yaml-js

Pure Javascript YAML loader and dumper, ported from PyYAML

WTFPL 21 个版本
安装
npm install yaml-js
yarn add yaml-js
pnpm add yaml-js
bun add yaml-js
README

⚠️Abandoned

This project is now abandoned and the repository archived. The license should allow you to fork and do whatever you want, in case you cannot migrate to a different YAML library.

Fun history fact: when I made the port there wasn't another pure JS YAML parser - the initial commit for this repo was just a couple of days before the initial release of js-yaml!

yaml-js

yaml-js is a YAML loader and dumper, ported pretty much line-for-line from PyYAML. The goal for the project is to maintain a reliable and specification-complete YAML processor in pure Javascript, with CoffeeScript source code. You can try it out here.

Loading is stable and well-used, and passes the yaml-spec test suite, which fairly thoroughly covers the YAML 'core' schema.

Dumping is present but very lightly tested (auto-tests only, no significant usage). The output should therefore be correct YAML, however formatting is currently entirely untested.

How Do I Get It?

npm install yaml-js

How Do I Use It?

// Server (e.g. node.js)
var yaml = require('yaml-js');

// Browser
// <script src='yaml.min.js'></script>

// Loading
console.log(yaml.load(
  '---\n' +
  'phrase1:\n' +
  '  - hello\n' +
  '  - &world world\n' +
  'phrase2:\n' +
  '  - goodbye\n' +
  '  - *world\n' +
  'phrase3: >\n' +
  '  What is up\n' +
  '  in this place.'
));
// { phrase1: [ 'hello', 'world' ],
//   phrase2: [ 'goodbye', 'world' ],
//   phrase3: 'What is up in this place.' }

// Dumping
console.log(yaml.dump({
  phrase1: [ 'hello',   'world' ],
  phrase2: [ 'goodbye', 'world' ],
  phrase3: 'What is up in this place.'
}));
// phrase1: [hello, world]
// phrase2: [goodbye, world]
// phrase3: What is up in this place.

API summary

Method Description
load Parse the first YAML document in a stream and produce the corresponding Javascript object.
dump Serialize a Javascript object into a YAML stream.
load_all Parse all YAML documents in a stream and produce the corresponing Javascript objects.
dump_all Serialize a sequence of Javascript objects into a YAML stream.
scan Scan a YAML stream and produce tokens.
parse Parse a YAML stream and produce events.
compose Parse the first YAML document in a stream and produce the corresponding representation tree.
compose_all Parse all YAML documents in a stream and produce corresponding representation trees.
emit Emit YAML parsing events into a stream.
serialize Serialize a representation tree into a YAML stream.
serialize_all Serialize a sequence of representation trees into a YAML stream.

License

WTFPL

版本列表
0.3.1-0 2021-09-19
0.3.1 2021-09-19
0.3.0 2017-12-18
0.2.3 2018-01-09
0.2.2 2017-12-18
0.2.1 2017-12-18
0.2.0 2017-06-22
0.1.5 2017-04-25
0.1.4 2016-09-07
0.1.3 2015-09-20
0.1.2 2015-09-20
0.1.1 2015-05-08
0.1.0 2014-08-24
0.0.8 2013-08-15
0.0.7 2013-04-14
0.0.6 2013-04-14
0.0.5 2012-08-25
0.0.4 2012-06-04
0.0.3 2012-06-03
0.0.2 2012-01-05
0.0.1 2012-01-04