yaml.js icon indicating copy to clipboard operation
yaml.js copied to clipboard

Remove yaml.load() and make yaml.js platform/framework independant.

Open jeremyfa opened this issue 6 years ago • 1 comments

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 as yaml.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 use yaml.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.

jeremyfa avatar Dec 12 '17 12:12 jeremyfa

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');

simonbuchan avatar Feb 07 '18 03:02 simonbuchan