@catalystic/json-to-yaml

中文文档
1.0.0发布于 2024/02/28ISCTypeScriptES Module零依赖近 30 天下载 7282

catalystic package for converting json to yaml

原始使用文档
文档目录3 节
  1. json-to-yaml
  2. Usage
  3. Motivation

json-to-yaml

@catalystic/json-to-yaml is a javascript npm package to convert JSON data in YAML.

It exports an convert function which intake JSON data and output YAML data.

You can pass standard JSON or any Javascript object (with primitives, null only and same apply to any nested array or object), check examples below.

Usage

Using Javascript Object

import { convert } from "@catalystic/json-to-yaml";

const json = {
  Type: "AWS::AppSync::Resolver",
  DependsOn: "GraphQLSchema",
  Properties: {
    ApiId: { "Fn::GetAtt": "GraphQLApi.ApiId" },
    DataSourceName: { "Fn::GetAtt": "UserServiceLambdaDataSource.Name" },
    TypeName: "Mutation",
    FieldName: "createUser",
    Kind: "UNIT",
    Runtime: {
      Name: "APPSYNC_JS",
      RuntimeVersion: "1.0.0",
    },
  },
};
const yaml = convert(json);

/* --- yaml ---
Type: "AWS::AppSync::Resolver"
DependsOn: "GraphQLSchema"
Properties:
  ApiId:
    Fn::GetAtt: "GraphQLApi.ApiId"
  DataSourceName:
    Fn::GetAtt: "UserServiceLambdaDataSource.Name"
  TypeName: "Mutation"
  FieldName: "createUser"
  Kind: "UNIT"
  Runtime:
    Name: "APPSYNC_JS"
    RuntimeVersion: "1.0.0"
*/

Using JSON data

import { readFileSync } from "node:fs";
import { convert } from "@catalystic/json-to-yaml";

const json = readFileSync("./file-name.json");
const yaml = convert(json);
console.log(yaml);

Motivation

On searching the npm registry for some package to convert json to yaml, i stumbled upon json-to-pretty-yaml which was last updated on 27th april 2018. And two of its dependencies were remedial and remove-trailing-whitespaces which were also last updated similarly. The remove-trailing-whitespaces is a one-liner package and remedial is a very small package and they could use modern javascript functions and can be merged into one single ESM package and thus begin the effort to do so and give birth to @catalystic/json-to-yaml.

版本与发布记录

@catalystic/json-to-yaml 共发布 1 个版本,首次发布于 2024/02/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2024/02/282 年前

关于 @catalystic/json-to-yaml 的常见问题

@catalystic/json-to-yaml 是什么?

catalystic package for converting json to yaml

如何安装 @catalystic/json-to-yaml?

在项目目录运行 npm install @catalystic/json-to-yaml,或使用 pnpm add / yarn add / bun add。

@catalystic/json-to-yaml 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@catalystic/json-to-yaml 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@catalystic/json-to-yaml 可以商用吗?

@catalystic/json-to-yaml 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@catalystic/json-to-yaml 的下载量有多少?

根据 npm 官方下载统计,@catalystic/json-to-yaml 在 2026/10/09 – 2026/11/07 这 30 天内被下载 7,282 次,日均约 243 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@catalystic/json-to-yaml 还在维护吗?

最新版本 1.0.0 发布于 2024/02/28(2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。