
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
The yaml-js npm package is a JavaScript library for parsing and stringifying YAML (YAML Ain't Markup Language) data. It allows developers to easily convert YAML data to JavaScript objects and vice versa, making it useful for configuration files, data serialization, and more.
Parsing YAML to JavaScript Object
This feature allows you to parse a YAML string and convert it into a JavaScript object. The `load` method is used to achieve this.
const yaml = require('yaml-js');
const yamlString = 'name: John Doe\nage: 30';
const jsObject = yaml.load(yamlString);
console.log(jsObject);
Stringifying JavaScript Object to YAML
This feature allows you to convert a JavaScript object into a YAML string. The `dump` method is used to achieve this.
const yaml = require('yaml-js');
const jsObject = { name: 'John Doe', age: 30 };
const yamlString = yaml.dump(jsObject);
console.log(yamlString);
js-yaml is a popular YAML parser and dumper for JavaScript. It is widely used and has a more active community compared to yaml-js. js-yaml provides similar functionalities for parsing and stringifying YAML data, but it also includes additional features like schema support and custom types.
yaml is another YAML parser and stringifier for JavaScript. It is known for its performance and compliance with the YAML 1.2 specification. The yaml package offers a more modern API and better error handling compared to yaml-js.
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 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.
npm install yaml-js
// 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.
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. |
FAQs
Pure Javascript YAML loader and dumper, ported from PyYAML
The npm package yaml-js receives a total of 182,077 weekly downloads. As such, yaml-js popularity was classified as popular.
We found that yaml-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.