Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
/ multigrain Public archive

Single-step conversion between JSON, YAML, CSON, PLIST, & TOML.

License

Notifications You must be signed in to change notification settings

agorischek/multigrain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multigrain logo

Multigrain

Single-step conversion between JSON, YAML, CSON, PLIST, & TOML.

Build Status Dependencies Version License

npm install multigrain

Multigrain provides simple conversion between common serial formats, avoiding the need to manually chain processors with differing syntaxes when a variety of formats and conversions are necessary. This can be particularly useful when multiple consumers require the same information in different serialized formats, such as language grammars.

Use

The most basic use is to call the desired output format function and pass an input string or JavaScript object. Multigrain will return a string in the requested format. If a string is passed as input, Multigrain will use some simple heuristics to infer the input format.

multigrain.json(input);
multigrain.yaml(input);
multigrain.cson(input);
multigrain.plist(input);
multigrain.toml(input);

Alternatively, parse will return a native JavaScript object.

multigrain.parse(input);

You can pass the input format explicitly (json, yaml, cson, plist, or toml) as the second argument. Unless your input format can vary unpredictably, this is recommended.

multigrain.json(input, "toml");

Options supported by the underlying parser can be passed as an optional argument.

multigrain.yaml(input, "plist", parseOpts);

Supported build options can optionally be passed similarly.

multigrain.cson(input, "json", parseOpts, buildOpts);

Options

Default parse and build options can be specified, which will be used for all following parse and build calls that don't specify explicit options.

multigrain.options.yaml.parse({ merge: false });
multigrain.options.cson.build({ indent: "  " });

Options can also be reset to Multigrain defaults.

multigrain.options.reset();

Processors

Multigrain uses the following processors for parsing and building:

See their respective documentation for parse and build options.

About

Single-step conversion between JSON, YAML, CSON, PLIST, & TOML.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages