jeremyfa / yaml.js

Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

jeremyfa opened this issue · 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.

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