# @aitodotai/json-stringify-pretty-compact 中文文档

规范地址：https://npmcn.com/package/%40aitodotai/json-stringify-pretty-compact/

版本：1\.3\.0
npm 元数据更新时间：2022-04-04T12:25:33.817Z
中文译文更新时间：2026-11-05T18:44:01.197Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aitodotai/json-stringify-pretty-compact
原文对照：https://npmcn.com/package/%40aitodotai/json-stringify-pretty-compact/?lang=original
项目主页：https://github.com/AitoDotAI/json-stringify-pretty-compact#readme
源码仓库：https://github.com/AitoDotAI/json-stringify-pretty-compact

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：10.2 kB，6 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2019-01-30T09:38:34.908Z
- 最新版本发布：2019-01-30T09:38:35.210Z
- 近 30 天下载量：57959（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

两者中最好的 `JSON.stringify(obj)` 财务报告和审定财务报表 `JSON.stringify(obj, null, indent)`。 。 。 .

## 安装

```sh
npm install @aitodotai/json-stringify-pretty-compact
```

也可以使用：`pnpm add @aitodotai/json-stringify-pretty-compact`、`yarn add @aitodotai/json-stringify-pretty-compact`、`bun add @aitodotai/json-stringify-pretty-compact`

## README

**分叉信息:** 这是执行这些附加选项的维护分叉: `maxNesting`, (中文(简体) ), `arrayMargins`,以及 `objectMargins`。 。 。 .

# 概览 [![Build Status](https://travis-ci.org/AitoDotAI/json-stringify-pretty-compact.svg?branch=master)](https://travis-ci.org/AitoDotAI/json-stringify-pretty-compact) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

产出 `JSON.stringify` 有两种口味: _紧凑_ 财务报告和审定财务报表 _不错._ 这个 前者通常过于紧凑,人类无法阅读,而后者有时 太宽敞了。 本单元交易性能(和“替代”论点) 双方达成妥协 结果是 _美丽_ 紧凑字符串, 在 “漂亮”既指“类型”也指“好”.

```json
{
  "bool": true,
  "short array": [1, 2, 3],
  "long array": [
    {"x": 1, "y": 2},
    {"x": 2, "y": 1},
    {"x": 1, "y": 1},
    {"x": 2, "y": 2}
  ]
}
```

" 漂亮 " 模式 `JSON.stringify` 将每个阵列和 本模块将整个阵列或对象放在单个上 线条,除非行变为太长(默认最长为80个字符). 制作数组和对象多行是执行 最大行长; 如果这无济于事, 也无济于事.

# 安装

`npm install @aitodotai/json-stringify-pretty-compact`

```js
var stringify = require("json-stringify-pretty-compact")
```

# 使用量

## `stringify(obj, [options])`

这就像 `JSON.stringify(obj, null, options.indent)`,但对象和 数组在一条线上,如果适合的话(根据 `options.maxLength`) (中文(简体) ).

`options`数字 :

-   缩进:默认为 2. 工作原理与第三参数完全一样 `JSON.stringify`。 。 。 .
    
-   最大Length:默认为80. 将尝试在最大范围内保持行数 字符长.
    
-   最大监视: 默认为 `Infinity`。允许对象或阵列内嵌嵌入的最大数量
    
    默认情况下,输出可以包含任意数量的嵌入结构(只要 最大连通度没有超过),例如:
    
    ```json
    {"a": [{"b": ["test1", "test2"]}, {"c": true}]}}
    ```
    
    当最大监视设定为 `0`,输出不允许任何筑巢:
    
    ```json
    {
      "a": [
        {
          "b": [
            "test1",
            "test2"
          ]
        },
        {
          "c": true
        }
      ]
    }
    ```
    
-   边距: 默认值 `false`是否在括号后添加“边距” 和牙套:
    
    -   `false`数字 : `{"a": [1]}`
    -   `true`数字 : `{ "a": [ 1 ] }`
-   数组标记: 默认值为 `false`是否在括号中添加 " 边距 " :
    
    -   `false`数字 : `{"a": [1]}`
    -   `true`数字 : `{"a": [ 1 ]}`
-   数组标记: 默认值为 `true`是否在括号上添加“边距” :
    
    -   `false`数字 : `{"a": [1]}`
    -   `true`数字 : `{ "a": [1] }`

`stringify(obj, {maxLength: 0, indent: indent})` 给出的结果与 `JSON.stringify(obj, null, indent)`。 。 。 .

`stringify(obj, {maxLength: Infinity})` 给出的结果与 `JSON.stringify(obj)`,但结肠和逗号后面有空格.

## 释放

使用补丁更改发布新版本的示例 :

`npm run publish -- patch`

# 许可证

[麻省理工学院](https://npmcn.com/package/%40aitodotai/json-stringify-pretty-compact/LICENSE)。 。 。 .

## 常见问题

### @aitodotai/json-stringify-pretty-compact 是什么？

两者中最好的 JSON\.stringify\(obj\) 财务报告和审定财务报表 JSON\.stringify\(obj, null, indent\)。 。 。 \.

### 如何安装 @aitodotai/json-stringify-pretty-compact？

在项目目录运行 npm install @aitodotai/json-stringify-pretty-compact，或使用 pnpm add / yarn add / bun add。

### @aitodotai/json-stringify-pretty-compact 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/aitodotai\_\_json-stringify-pretty-compact 是否存在。

### @aitodotai/json-stringify-pretty-compact 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @aitodotai/json-stringify-pretty-compact 可以商用吗？

@aitodotai/json-stringify-pretty-compact 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @aitodotai/json-stringify-pretty-compact 的下载量有多少？

根据 npm 官方下载统计，@aitodotai/json-stringify-pretty-compact 在 2026/10/05 – 2026/11/03 这 30 天内被下载 57,959 次，日均约 1,932 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @aitodotai/json-stringify-pretty-compact 还在维护吗？

最新版本 1\.3\.0 发布于 2019/01/30（7 年前）；至今共发布 1 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/01/30。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

