1.0.1 • Published 11 months ago

manic-yaml-matter v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

ManicYamlMatter

Yaml文件操作库

方法

  • parse,基本功能同yaml插件一致,追加了变量引入方法,类似于spring boot的yaml模式。
    用法:

    # spring-boot.yaml
    serve:
      port: 3000
      host: 127.0.0.1
      prefix: /api
    swagger:
      api: ${serve.prefix}/swagger
    import { readFileSync } from 'fs';
    import { parse } from 'manic-yaml-matter';
    const context = readFileSync('./spring-boot.yaml', 'utf-8');
    const source = parse(context);
    console.log(source);

    得到结果:

    {
      "serve": { "port": 3000, "host": "127.0.0.1", "prefix": "/api" },
      "swagger": { "api": "/api/swagger" }
    }

    注:

    1. 当引入变量不存在时,会抛出异常。
    2. 不支持转义符\,例:\${键}会被解析为\值
  • parsefparse方法,参数为yaml的路径。
    用法:

    import { parsef } from 'manic-yaml-matter';
    const source = parsef('./spring-boot.yaml');
1.0.1

11 months ago

1.0.0

11 months ago