source: node_modules/yaml/README.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[d24f17c]1# YAML <a href="https://www.npmjs.com/package/yaml"><img align="right" src="https://badge.fury.io/js/yaml.svg" title="npm package" /></a>
2
3`yaml` is a definitive library for [YAML](https://yaml.org/), the human friendly data serialization standard.
4This library:
5
6- Supports both YAML 1.1 and YAML 1.2 and all common data schemas,
7- Passes all of the [yaml-test-suite](https://github.com/yaml/yaml-test-suite) tests,
8- Can accept any string as input without throwing, parsing as much YAML out of it as it can, and
9- Supports parsing, modifying, and writing YAML comments and blank lines.
10
11The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/).
12It has no external dependencies and runs on Node.js as well as modern browsers.
13
14For the purposes of versioning, any changes that break any of the documented endpoints or APIs will be considered semver-major breaking changes.
15Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed).
16
17The minimum supported TypeScript version of the included typings is 3.9;
18for use in earlier versions you may need to set `skipLibCheck: true` in your config.
19This requirement may be updated between minor versions of the library.
20
21For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)
22
23To install:
24
25```sh
26npm install yaml
27```
28
29**Note:** These docs are for `yaml@2`. For v1, see the [v1.10.0 tag](https://github.com/eemeli/yaml/tree/v1.10.0) for the source and [eemeli.org/yaml/v1](https://eemeli.org/yaml/v1/) for the documentation.
30
31## API Overview
32
33The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the underlying [Lexer/Parser/Composer](https://eemeli.org/yaml/#parsing-yaml).
34The 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](https://eemeli.org/yaml/#content-nodes), and the third lets you get progressively closer to YAML source, if that's your thing.
35
36```js
37import { parse, stringify } from 'yaml'
38// or
39import YAML from 'yaml'
40// or
41const YAML = require('yaml')
42```
43
44### Parse & Stringify
45
46- [`parse(str, reviver?, options?): value`](https://eemeli.org/yaml/#yaml-parse)
47- [`stringify(value, replacer?, options?): string`](https://eemeli.org/yaml/#yaml-stringify)
48
49### Documents
50
51- [`Document`](https://eemeli.org/yaml/#documents)
52 - [`constructor(value, replacer?, options?)`](https://eemeli.org/yaml/#creating-documents)
53 - [`#anchors`](https://eemeli.org/yaml/#working-with-anchors)
54 - [`#contents`](https://eemeli.org/yaml/#content-nodes)
55 - [`#directives`](https://eemeli.org/yaml/#stream-directives)
56 - [`#errors`](https://eemeli.org/yaml/#errors)
57 - [`#warnings`](https://eemeli.org/yaml/#errors)
58- [`isDocument(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
59- [`parseAllDocuments(str, options?): Document[]`](https://eemeli.org/yaml/#parsing-documents)
60- [`parseDocument(str, options?): Document`](https://eemeli.org/yaml/#parsing-documents)
61
62### Content Nodes
63
64- [`isAlias(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
65- [`isCollection(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
66- [`isMap(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
67- [`isNode(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
68- [`isPair(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
69- [`isScalar(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
70- [`isSeq(foo): boolean`](https://eemeli.org/yaml/#identifying-nodes)
71- [`new Scalar(value)`](https://eemeli.org/yaml/#scalar-values)
72- [`new YAMLMap()`](https://eemeli.org/yaml/#collections)
73- [`new YAMLSeq()`](https://eemeli.org/yaml/#collections)
74- [`doc.createAlias(node, name?): Alias`](https://eemeli.org/yaml/#working-with-anchors)
75- [`doc.createNode(value, options?): Node`](https://eemeli.org/yaml/#creating-nodes)
76- [`doc.createPair(key, value): Pair`](https://eemeli.org/yaml/#creating-nodes)
77- [`visit(node, visitor)`](https://eemeli.org/yaml/#modifying-nodes)
78
79### Parsing YAML
80
81- [`new Lexer().lex(src)`](https://eemeli.org/yaml/#lexer)
82- [`new Parser(onNewLine?).parse(src)`](https://eemeli.org/yaml/#parser)
83- [`new Composer(options?).compose(tokens)`](https://eemeli.org/yaml/#composer)
84
85## YAML.parse
86
87```yaml
88# file.yml
89YAML:
90 - A human-readable data serialization language
91 - https://en.wikipedia.org/wiki/YAML
92yaml:
93 - A complete JavaScript implementation
94 - https://www.npmjs.com/package/yaml
95```
96
97```js
98import fs from 'fs'
99import YAML from 'yaml'
100
101YAML.parse('3.14159')
102// 3.14159
103
104YAML.parse('[ true, false, maybe, null ]\n')
105// [ true, false, 'maybe', null ]
106
107const file = fs.readFileSync('./file.yml', 'utf8')
108YAML.parse(file)
109// { YAML:
110// [ 'A human-readable data serialization language',
111// 'https://en.wikipedia.org/wiki/YAML' ],
112// yaml:
113// [ 'A complete JavaScript implementation',
114// 'https://www.npmjs.com/package/yaml' ] }
115```
116
117## YAML.stringify
118
119```js
120import YAML from 'yaml'
121
122YAML.stringify(3.14159)
123// '3.14159\n'
124
125YAML.stringify([true, false, 'maybe', null])
126// `- true
127// - false
128// - maybe
129// - null
130// `
131
132YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
133// `number: 3
134// plain: string
135// block: |
136// two
137// lines
138// `
139```
140
141---
142
143Browser testing provided by:
144
145<a href="https://www.browserstack.com/open-source">
146<img width=200 src="https://eemeli.org/yaml/images/browserstack.svg" />
147</a>
Note: See TracBrowser for help on using the repository browser.