PHPackages                             avtomon/yaml.js - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. avtomon/yaml.js

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

avtomon/yaml.js
===============

YAML parse &amp; save

01JavaScript

Since Jun 15Pushed 5y agoCompare

[ Source](https://github.com/avtomon/yaml.js)[ Packagist](https://packagist.org/packages/avtomon/yaml.js)[ RSS](/packages/avtomon-yamljs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

YAML [![](https://camo.githubusercontent.com/af17b529a8d9915c54e24dbc54f6889e90af6530d4d264078a6a0040e8575d8c/68747470733a2f2f62616467652e667572792e696f2f6a732f79616d6c2e737667 "npm package")](https://www.npmjs.com/package/yaml)[![](https://camo.githubusercontent.com/6164c38d277ec8929499fc1112d3766a2e22474b2e85daf1b2d8440533d92555/68747470733a2f2f7472617669732d63692e6f72672f65656d656c692f79616d6c2e7376673f6272616e63683d6d6173746572 "Build status")](https://travis-ci.org/eemeli/yaml)
=======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#yaml-)

`yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents.

The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards.

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

For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)

To install:

```
npm install yaml
```

Note: `yaml` 0.x and 1.x are rather different implementations. For the earlier `yaml`, see [tj/js-yaml](https://github.com/tj/js-yaml).

API Overview
------------

[](#api-overview)

The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse &amp; Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the [CST Parser](https://eemeli.org/yaml/#cst-parser). 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/yaml/#content-nodes), and the third is the closest to YAML source, making it fast, raw, and crude.

```
import YAML from 'yaml'
// or
const YAML = require('yaml')
```

### Parse &amp; Stringify

[](#parse--stringify)

- [`YAML.parse(str, options): value`](https://eemeli.org/yaml/#yaml-parse)
- [`YAML.stringify(value, options): string`](https://eemeli.org/yaml/#yaml-stringify)

### YAML Documents

[](#yaml-documents)

- [`YAML.createNode(value, wrapScalars, tag): Node`](https://eemeli.org/yaml/#creating-nodes)
- [`YAML.defaultOptions`](https://eemeli.org/yaml/#options)
- [`YAML.Document`](https://eemeli.org/yaml/#yaml-documents)
    - [`constructor(options)`](https://eemeli.org/yaml/#creating-documents)
    - [`defaults`](https://eemeli.org/yaml/#options)
    - [`#anchors`](https://eemeli.org/yaml/#working-with-anchors)
    - [`#contents`](https://eemeli.org/yaml/#content-nodes)
    - [`#errors`](https://eemeli.org/yaml/#errors)
- [`YAML.parseAllDocuments(str, options): YAML.Document[]`](https://eemeli.org/yaml/#parsing-documents)
- [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/#parsing-documents)

```
import { Pair, YAMLMap, YAMLSeq } from 'yaml/types'
```

- [`new Pair(key, value)`](https://eemeli.org/yaml/#creating-nodes)
- [`new YAMLMap()`](https://eemeli.org/yaml/#creating-nodes)
- [`new YAMLSeq()`](https://eemeli.org/yaml/#creating-nodes)

### CST Parser

[](#cst-parser)

```
import parseCST from 'yaml/parse-cst'
```

- [`parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
- [`YAML.parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)

YAML.parse
----------

[](#yamlparse)

```
# 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
--------------

[](#yamlstringify)

```
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:

[![](https://camo.githubusercontent.com/c934c1e1e01e8437c9608a7ec7e72a7b3fa36960144d3de9826353304d3fcd1a/68747470733a2f2f65656d656c692e6f72672f79616d6c2f696d616765732f62726f77736572737461636b2e737667)](https://www.browserstack.com/open-source)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/92ce6727f8411ccb2b1fbd51fc91b3d20a07ca6880b22e2ecf759fe1fe1238d3?d=identicon)[avtomon](/maintainers/avtomon)

---

Top Contributors

[![eemeli](https://avatars.githubusercontent.com/u/617000?v=4)](https://github.com/eemeli "eemeli (822 commits)")[![ikatyang](https://avatars.githubusercontent.com/u/8341033?v=4)](https://github.com/ikatyang "ikatyang (15 commits)")[![MikeRalphson](https://avatars.githubusercontent.com/u/21603?v=4)](https://github.com/MikeRalphson "MikeRalphson (3 commits)")[![shirk3y](https://avatars.githubusercontent.com/u/1696055?v=4)](https://github.com/shirk3y "shirk3y (2 commits)")[![avtomon](https://avatars.githubusercontent.com/u/10077243?v=4)](https://github.com/avtomon "avtomon (1 commits)")[![Whoaa512](https://avatars.githubusercontent.com/u/1581943?v=4)](https://github.com/Whoaa512 "Whoaa512 (1 commits)")[![dubzzz](https://avatars.githubusercontent.com/u/5300235?v=4)](https://github.com/dubzzz "dubzzz (1 commits)")[![isaacs](https://avatars.githubusercontent.com/u/9287?v=4)](https://github.com/isaacs "isaacs (1 commits)")[![tripodsan](https://avatars.githubusercontent.com/u/917628?v=4)](https://github.com/tripodsan "tripodsan (1 commits)")

### Embed Badge

![Health badge](/badges/avtomon-yamljs/health.svg)

```
[![Health](https://phpackages.com/badges/avtomon-yamljs/health.svg)](https://phpackages.com/packages/avtomon-yamljs)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
