• Stars
    star
    1,142
  • Rank 39,350 (Top 0.8 %)
  • Language
    TypeScript
  • License
    ISC License
  • Created over 6 years ago
  • Updated 15 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

YAML parser and stringifier for JavaScript

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:

npm install 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.

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.

import { parse, stringify } from 'yaml'
// or
import YAML from 'yaml'
// or
const YAML = require('yaml')

Parse & Stringify

Documents

Content Nodes

Parsing YAML

YAML.parse

# file.yml
YAML:
  - A human-readable data serialization language
  - https://en.wikipedia.org/wiki/YAML
yaml:
  - A complete JavaScript implementation
  - https://www.npmjs.com/package/yaml
import fs from 'fs'
import YAML from 'yaml'

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' ],
//   yaml:
//   [ 'A complete JavaScript implementation',
//     'https://www.npmjs.com/package/yaml' ] }

YAML.stringify

import YAML from 'yaml'

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:

More Repositories

1

yaml-loader

YAML loader for webpack
JavaScript
149
star
2

make-plural

Translates Unicode CLDR pluralization rules to executable JavaScript
JavaScript
59
star
3

intl-pluralrules

Polyfill for Intl.PluralRules
JavaScript
39
star
4

konopas

Mobile-friendly guides for conventions, with all sorts of spiffy features
JavaScript
26
star
5

dot-properties

Parse & stringify .properties files in JavaScript
JavaScript
21
star
6

kill-sticky

Browser extension to remove all elements with fixed or sticky positions
JavaScript
19
star
7

prettier-plugin-properties

Prettier plugin for .properties files
JavaScript
19
star
8

fluent-compiler

JavaScript transpiler for Fluent messages
JavaScript
14
star
9

dev-console.macro

A Babel macro that removes console prints in production
JavaScript
12
star
10

yaml-convert

Convert between YAML and JSON, optionally wrapping output as a JS module
JavaScript
7
star
11

pdf-form-fill

PDF form fill with UTF-8 support, using pdftk
JavaScript
5
star
12

yaml-playground

YAML Playground
JavaScript
5
star
13

message-resource-wg

Developing a standard for Unicode MessageFormat 2 resources
4
star
14

proposal-intl-loadlocales

Lazy-loading of Intl locales
4
star
15

yaml-types

Useful JavaScript types for YAML
TypeScript
3
star
16

safe-identifier

Sanitize strings for use as JavaScript identifiers & property names
JavaScript
3
star
17

react-message-context

Renamed & moved, now published as @messageformat/react
JavaScript
2
star
18

raw-yaml

Read anything as YAML (including #comments)
2
star
19

json-estree-ast

ESTree-compatible JSON AST parser
JavaScript
2
star
20

mocha-selenium-bridge

Run tests in the browser, report results in Node
JavaScript
2
star
21

yaml.macro

A Babel macro for loading YAML files
JavaScript
2
star
22

pdf-form-fill-server

A containerisable server wrapper around pdf-form-fill
JavaScript
2
star
23

fluent-loader

Webpack loader for Fluent -> MOVED:
JavaScript
2
star
24

talks

Talks and presentations by Eemeli Aro
HTML
1
star
25

messages

Text message generation
JavaScript
1
star
26

codemirror-bidi-demo

JavaScript
1
star
27

ibid

Tools to automate your releases and changelogs, esp. for monorepos
TypeScript
1
star