YAML : YAML parser and encoder
This module provides a lightweight YAML 1.2 Parser & Encoder.
User can use the following code to import the YAML module.
var YAML = require('yaml');
Support
The following shows YAML module APIs available for each permissions.
| User Mode | Privilege Mode | |
|---|---|---|
| YAML.parse | ● | ● |
| YAML.stringify | ● | ● |
YAML Module
YAML.parse(input[, exceptionOnInvalidType[, objectDecoder]])
input{String} Yaml string.exceptionOnInvalidType{Boolean}trueif an exception must be thrown on invalid types,falseotherwise. default:false.objectDecoder{Function} A function to deserialize custom objects, default:null.key{Any} The key associated with the value.value{Any} The value produced by parsing.- Returns: {Any} Custom value.
- Returns: {Object} YAML converted to a JavaScript object.
Example
YAML.parse("- apple\n- banana\n- carrot");
// ['apple', 'banana', 'carrot']
YAML.stringify(input[, inline[, indent[, exceptionOnInvalidType[, objectEncoder]]]])
input{Object} JavaScript object.inline{Integer} The level where you switch to inline YAML. default: 2.indent{Integer} The amount of spaces to use for indentation of nested nodes. default: 4.exceptionOnInvalidType{Boolean}trueif an exception must be thrown on invalid types (a JavaScript resource or object),falseotherwise. default:false.objectEncoder{Function} A function to serialize custom objects. default:null.key{Any} The key associated with the value.value{Any} The value produced by parsing.- Returns: {Any} Custom value.
- Returns: {String} A YAML string representing the original JavaScript object.
Example
YAML.stringify({ a: 10, b: 20, c: [1, 2, 3] });
/*
a: 10
b: 20
c:
- 1
- 2
- 3
*/




陕公网安备61019002002605号