Skip to content

Methods for synchronously parsing various data formats to JS objects.

License

Notifications You must be signed in to change notification settings

dskrepps-legacy/parse-formats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parse-formats

Provides a list of various modules to parse data formats synchronously to JS objects.

Feel free to suggest more formats or more modules to parse them with via issue or pull request.

NPM

Formats

Ext format npm module
.cson cson cson-parser
.csv csv parser-csv
.hjson hjson hjson
.ini ini ini
.json json strip-json-comments or native
.json5 json5 json5
.xml xml xml2json
.yaml, .yml yaml js-yaml

Source

/* Common patterns */
function parse (parser, data, opts) {
	return parser.parse(data, opts);
}

function self (parser, data, opts) {
	return parser(data, opts);
}


/* { ext: { moduleName: function(module, data, opts) } } */
module.exports = {
	'.cson':  { 'cson-parser': parse },
	'.csv':   {
		'parser-csv': function (parser, data, opts) {
			return parser.parseSync(data, opts);
		},
	},
	'.hjson': { 'hjson': parse },
	'.ini':   { 'ini': parse },
	'.json':  {
		'strip-json-comments': function (stripComments, data) {
			return JSON.parse(stripComments(data));
		},
		'path': function (_, data) {
			return JSON.parse(data);
		},
	},
	'.json5': { 'json5': parse },
	'.xml': {
		'xml2json': function (xml2json, data, opts) {
			return JSON.parse(xml2json.toJson(data, opts));
		},
	},
	'.yaml': { 'js-yaml': jsYaml },
	'.yml':  { 'js-yaml': jsYaml },
};

function jsYaml (jsYaml, data, opts) {
	return jsYaml.load(data, opts);
}

About

Methods for synchronously parsing various data formats to JS objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published