Open jeremyfa opened 6 years ago
You could instead use the semi-standard package.json browser
field to only reference the correct code for the environment.
As a simple example:
// package.json
{ ...,
"main": "lib/node.js",
"browser": "lib/browser.js",
...
}
// node.js
exports.parse = require('./parse');
exports.stringify = require('./stringify');
exports.load = require('./load-node.js');
// browser.js
exports.parse = require('./parse');
exports.stringify = require('./stringify');
exports.load = require('./load-browser.js');
At first it seemed like a good idea to provide
yaml.load()
and internally use fs/XMLHttpRequest to read a yaml file content, but this is causing issue with packers, testing utilities etc...yaml.load()
is also a bit out of scope regarding parsing and dumping YAML content. It may be removed anyway asyaml.js
should focus on parsing and dumping files only.This would make
yaml.js
a pure javascript library without any dependency to node/browser API.Obviously this would break code that depend on
yaml.load()
but having users change existing code to make it useyaml.parse()
instead should be fairly quick in most cases.Users are the one who should decide how yaml content is fetched anyway, not
yaml.js
.