npm package: @ryniaubenpm2/unde-accusantium-nobis
Description: `@ryniaubenpm2/unde-accusantium-nobis` is a definitive library for [YAML](https://@ryniaubenpm2/unde-accusantium-nobis.org/), the human friendly data serialization standard. This library:
Author: ryniaube
Latest version: 1.0.0

# YAML <a href="https://www.npmjs.com/package/@ryniaubenpm2/unde-accusantium-nobis"><img align="right" src="https://badge.fury.io/js/@ryniaubenpm2/unde-accusantium-nobis.svg" title="npm package" /></a>

`@ryniaubenpm2/unde-accusantium-nobis` is a definitive library for [YAML](https://@ryniaubenpm2/unde-accusantium-nobis.org/), 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 [@ryniaubenpm2/unde-accusantium-nobis-test-suite](https://github.com/@ryniaubenpm2/unde-accusantium-nobis/@ryniaubenpm2/unde-accusantium-nobis-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](https://github.com/ryniaubenpm2/unde-accusantium-nobis/).
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/@ryniaubenpm2/unde-accusantium-nobis**](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/)

To install:

```sh
npm install @ryniaubenpm2/unde-accusantium-nobis
```

**Note:** These docs are for `@ryniaubenpm2/unde-accusantium-nobis@2`. For v1, see the [v1.10.0 tag](https://github.com/ryniaubenpm2/unde-accusantium-nobis/tree/v1.10.0) for the source and [eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/v1](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/v1/) for the documentation.

The development and maintenance of this library is [sponsored](https://github.com/sponsors/eemeli) by:

<a href="https://www.scipress.io/">
<img width=150 src="https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/images/scipress.svg" alt="Scipress" />
</a>

## API Overview

The API provided by `@ryniaubenpm2/unde-accusantium-nobis` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#parse-amp-stringify), [Documents](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#documents), and the underlying [Lexer/Parser/Composer](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#parsing-@ryniaubenpm2/unde-accusantium-nobis).
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](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#content-nodes), and the third lets you get progressively closer to YAML source, if that's your thing.

A [command-line tool](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#command-line-tool) is also included.

```js
import { parse, stringify } from '@ryniaubenpm2/unde-accusantium-nobis'
// or
import YAML from '@ryniaubenpm2/unde-accusantium-nobis'
// or
const YAML = require('@ryniaubenpm2/unde-accusantium-nobis')
```

### Parse & Stringify

- [`parse(str, reviver?, options?): value`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#@ryniaubenpm2/unde-accusantium-nobis-parse)
- [`stringify(value, replacer?, options?): string`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#@ryniaubenpm2/unde-accusantium-nobis-stringify)

### Documents

- [`Document`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#documents)
  - [`constructor(value, replacer?, options?)`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#creating-documents)
  - [`#anchors`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#working-with-anchors)
  - [`#contents`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#content-nodes)
  - [`#directives`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#stream-directives)
  - [`#errors`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#errors)
  - [`#warnings`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#errors)
- [`isDocument(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`parseAllDocuments(str, options?): Document[]`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#parsing-documents)
- [`parseDocument(str, options?): Document`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#parsing-documents)

### Content Nodes

- [`isAlias(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`isCollection(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`isMap(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`isNode(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`isPair(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`isScalar(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`isSeq(foo): boolean`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#identifying-node-types)
- [`new Scalar(value)`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#scalar-values)
- [`new YAMLMap()`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#collections)
- [`new YAMLSeq()`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#collections)
- [`doc.createAlias(node, name?): Alias`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#working-with-anchors)
- [`doc.createNode(value, options?): Node`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#creating-nodes)
- [`doc.createPair(key, value): Pair`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#creating-nodes)
- [`visit(node, visitor)`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#finding-and-modifying-nodes)

### Parsing YAML

- [`new Lexer().lex(src)`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#lexer)
- [`new Parser(onNewLine?).parse(src)`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#parser)
- [`new Composer(options?).compose(tokens)`](https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/#composer)

## YAML.parse

```@ryniaubenpm2/unde-accusantium-nobis
# file.yml
YAML:
  - A human-readable data serialization language
  - https://en.wikipedia.org/wiki/YAML
@ryniaubenpm2/unde-accusantium-nobis:
  - A complete JavaScript implementation
  - https://www.npmjs.com/package/@ryniaubenpm2/unde-accusantium-nobis
```

```js
import fs from 'fs'
import YAML from '@ryniaubenpm2/unde-accusantium-nobis'

YAML.parse('3.14159')
// 3.14159

YAML.parse('[ true, false, maybe, null ]\n')
// [ true, false, 'maybe', null ]

const file = fs.readFileSync('./file.yml', 'utf8')
YAML.parse(file)
// { YAML:
//   [ 'A human-readable data serialization language',
//     'https://en.wikipedia.org/wiki/YAML' ],
//   @ryniaubenpm2/unde-accusantium-nobis:
//   [ 'A complete JavaScript implementation',
//     'https://www.npmjs.com/package/@ryniaubenpm2/unde-accusantium-nobis' ] }
```

## YAML.stringify

```js
import YAML from '@ryniaubenpm2/unde-accusantium-nobis'

YAML.stringify(3.14159)
// '3.14159\n'

YAML.stringify([true, false, 'maybe', null])
// `- true
// - false
// - maybe
// - null
// `

YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
// `number: 3
// plain: string
// block: |
//   two
//   lines
// `
```

---

Browser testing provided by:

<a href="https://www.browserstack.com/open-source">
<img width=200 src="https://eemeli.org/@ryniaubenpm2/unde-accusantium-nobis/images/browserstack.svg" alt="BrowserStack" />
</a>