Browse files

`require(filename)` now returns a single document

  • Loading branch information...
1 parent 062a245 commit b0e6ced9e183ff8f2d048858ec093feb2ad69b1d @ixti ixti committed Jul 1, 2012
Showing with 12 additions and 20 deletions.
  1. +2 −0 HISTORY.md
  2. +5 −14 README.md
  3. +1 −2 lib/js-yaml.js
  4. +1 −1 test/issues/issue-17.js
  5. +1 −1 test/issues/issue-19.js
  6. +1 −1 test/issues/issue-26.js
  7. +1 −1 test/issues/issue-8.js
View
2 HISTORY.md
@@ -3,6 +3,8 @@
* `y`, `yes`, `n`, `no`, `on`, `off` are not converted to Booleans anymore.
Fixes #42.
+* `require(filename)` now returns a single document and throws an Error if
+ file contains more than one document.
0.3.7 / 2012-02-28
View
19 README.md
@@ -16,6 +16,8 @@ Now you can use all modern YAML feature right in JavaScript. Originally snapshot
core developers: from now on we try to keep as minimal subset of rules as
possible to keep things obvious. Booleans are following YAML 1.2 core schema
now: http://www.yaml.org/spec/1.2/spec.html#id2804923
+- `require('file.yml')` now returns a single document (was array of documents)
+ and throws an error when file contains multiple documents.
## Installation
@@ -52,21 +54,10 @@ Just with one string!
``` javascript
require('js-yaml');
-// Get array of documents, or throw exception on error
-var docs = require('/home/ixti/examples.yml');
+// Get document, or throw exception on error
+var doc = require('/home/ixti/example.yml');
-console.log(docs);
-```
-
-If you are sure, that file has only one document, chained `shift()` will help to exclude array wrapper:
-
-``` javascript
-require('js-yaml');
-
-// Get array of documents, or throw exception on error
-var singleDoc = require('/home/ixti/examples.yml').shift();
-
-console.log(singleDoc);
+console.log(doc);
```
View
3 lib/js-yaml.js
@@ -72,8 +72,7 @@ jsyaml.addConstructor = function addConstructor(tag, constructor, Loader) {
var fd = fs.openSync(filename, 'r');
// fill in documents
- module.exports = [];
- jsyaml.loadAll(fd, function (doc) { module.exports.push(doc); });
+ module.exports = jsyaml.load(fd);
fs.closeSync(fd);
};
View
2 test/issues/issue-17.js
@@ -10,7 +10,7 @@ module.exports = require('../helper').issue({
title: "#17: Non-specific `!` tags should resolve to !!str",
fixed: true,
test: function () {
- var str = require(source).shift();
+ var str = require(source);
Assert.equal('string', typeof str);
}
});
View
2 test/issues/issue-19.js
@@ -10,7 +10,7 @@ module.exports = require('../helper').issue({
title: "#19: Timestamp parsing is one month off",
fixed: true,
test: function () {
- var doc = require(source).shift(), expected = new Date(2011, 11, 24);
+ var doc = require(source), expected = new Date(2011, 11, 24);
// JS month starts with 0 (0 => Jan, 1 => Feb, ...)
Assert.equal(doc.xmas.getTime(), expected.getTime());
View
2 test/issues/issue-26.js
@@ -10,7 +10,7 @@ module.exports = require('../helper').issue({
title: "#26: should convert new line into white space",
fixed: true,
test: function () {
- var doc = require(source).shift();
+ var doc = require(source);
Assert.equal(doc.test, 'a b c\n');
}
});
View
2 test/issues/issue-8.js
@@ -11,7 +11,7 @@ module.exports = require('../helper').issue({
fixed: true,
test: function () {
Assert.doesNotThrow(function () {
- require(source).shift();
+ require(source);
}, TypeError);
}
});

0 comments on commit b0e6ced

Please sign in to comment.