项目作者: eemeli

项目描述 :
JavaScript parser and stringifier for YAML
高级语言: TypeScript
项目地址: git://github.com/eemeli/yaml.git
创建时间: 2018-01-29T20:45:06Z
项目社区:https://github.com/eemeli/yaml

开源协议:ISC License

下载


YAML

yaml is a definitive library for YAML, the human friendly data serialization standard.
This library:

  • Supports both YAML 1.1 and YAML 1.2 and all common data schemas,
  • Passes all of the yaml-test-suite tests,
  • Can accept any string as input without throwing, parsing as much YAML out of it as it can, and
  • Supports parsing, modifying, and writing YAML comments and blank lines.

The library is released under the ISC open source license, and the code is available on GitHub.
It has no external dependencies and runs on Node.js as well as modern browsers.

For the purposes of versioning, any changes that break any of the documented endpoints or APIs will be considered semver-major breaking changes.
Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed).

The minimum supported TypeScript version of the included typings is 3.9;
for use in earlier versions you may need to set skipLibCheck: true in your config.
This requirement may be updated between minor versions of the library.

For more information, see the project’s documentation site: eemeli.org/yaml

To install:

  1. npm install yaml
  2. # or
  3. deno add jsr:@eemeli/yaml

Note: These docs are for yaml@2. For v1, see the v1.10.0 tag for the source and eemeli.org/yaml/v1 for the documentation.

The development and maintenance of this library is sponsored by:


Scipress

Manifest

API Overview

The API provided by yaml has three layers, depending on how deep you need to go: Parse & Stringify, Documents, and the underlying Lexer/Parser/Composer.
The first has the simplest API and “just works”, the second gets you all the bells and whistles supported by the library along with a decent AST, and the third lets you get progressively closer to YAML source, if that’s your thing.

A command-line tool is also included.

Parse & Stringify

  1. import { parse, stringify } from 'yaml'

Documents

  1. import {
  2. Document,
  3. isDocument,
  4. parseAllDocuments,
  5. parseDocument
  6. } from 'yaml'

Content Nodes

  1. import {
  2. isAlias, isCollection, isMap, isNode,
  3. isPair, isScalar, isSeq, Scalar,
  4. visit, visitAsync, YAMLMap, YAMLSeq
  5. } from 'yaml'

Parsing YAML

  1. import { Composer, Lexer, Parser } from 'yaml'

YAML.parse

  1. # file.yml
  2. YAML:
  3. - A human-readable data serialization language
  4. - https://en.wikipedia.org/wiki/YAML
  5. yaml:
  6. - A complete JavaScript implementation
  7. - https://www.npmjs.com/package/yaml
  1. import fs from 'fs'
  2. import YAML from 'yaml'
  3. YAML.parse('3.14159')
  4. // 3.14159
  5. YAML.parse('[ true, false, maybe, null ]\n')
  6. // [ true, false, 'maybe', null ]
  7. const file = fs.readFileSync('./file.yml', 'utf8')
  8. YAML.parse(file)
  9. // { YAML:
  10. // [ 'A human-readable data serialization language',
  11. // 'https://en.wikipedia.org/wiki/YAML' ],
  12. // yaml:
  13. // [ 'A complete JavaScript implementation',
  14. // 'https://www.npmjs.com/package/yaml' ] }

YAML.stringify

  1. import YAML from 'yaml'
  2. YAML.stringify(3.14159)
  3. // '3.14159\n'
  4. YAML.stringify([true, false, 'maybe', null])
  5. // `- true
  6. // - false
  7. // - maybe
  8. // - null
  9. // `
  10. YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
  11. // `number: 3
  12. // plain: string
  13. // block: |
  14. // two
  15. // lines
  16. // `

Browser testing provided by:


BrowserStack