Skip to content

Commit

Permalink
Merge branch 'master' into no-eval
Browse files Browse the repository at this point in the history
* master: (58 commits)
  Check for leading newlines when determining if block indentation indicator is needed (nodeca#404)
  Add property based tests to assess load reverses dump (nodeca#398)
  3.11.0 released
  Browser files rebuild
  Dumper: fix negative integers in bin/octal/hex formats, close nodeca#399
  support es6 arrow functions, fixes nodeca#389 (nodeca#393)
  Fix typo in README.md (nodeca#373)
  3.10.0 released
  Browser files rebuild
  Add test for astrals dump
  Combine surrogate pairs into one escape sequence when encoding. (nodeca#369)
  Fix condenseFlow for objects (nodeca#371)
  correct spelling mistake (nodeca#367)
  More meaningful error for loader (nodeca#361)
  Fix typo and format code. (nodeca#365)
  3.9.1 released
  Browser files rebuild
  Ensure stack is present for custom errors (fixes nodeca#351) (nodeca#360)
  3.9.0 released
  Browser files rebuild
  ...
  • Loading branch information
minj committed Apr 28, 2018
2 parents b34e032 + bab69b5 commit 7a41c3b
Show file tree
Hide file tree
Showing 43 changed files with 754 additions and 158 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
env:
node: true
browser: true
es6: false

rules:
accessor-pairs: 2
Expand Down Expand Up @@ -42,7 +43,7 @@ rules:
no-cond-assign: 2
no-console: 1
no-constant-condition: 2
no-control-regex: 2
# no-control-regex: 2
no-debugger: 1
no-delete-var: 2
no-div-regex: 2
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sudo: false
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
- '5'
- '6'
- '8'
74 changes: 74 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
3.11.0 / 2018-03-05
-------------------

- Fix dump in bin/octal/hex formats for negative integers, #399.
- Add arrow functions suport for `!!js/function`.


3.10.0 / 2017-09-10
-------------------

- Fix `condenseFlow` output (quote keys for sure, instead of spaces), #371, #370.
- Dump astrals as codepoints instead of surrogate pair, #368.


3.9.1 / 2017-07-08
------------------

- Ensure stack is present for custom errors in node 7.+, #351.


3.9.0 / 2017-07-08
------------------

- Add `condenseFlow` option (to create pretty URL query params), #346.
- Support array return from safeLoadAll/loadAll, #350.


3.8.4 / 2017-05-08
------------------

- Dumper: prevent space after dash for arrays that wrap, #343.


3.8.3 / 2017-04-05
------------------

- Should not allow numbers to begin and end with underscore, #335.


3.8.2 / 2017-03-02
------------------

- Fix `!!float 123` (integers) parse, #333.
- Don't allow leading zeros in floats (except 0, 0.xxx).
- Allow positive exponent without sign in floats.


3.8.1 / 2017-02-07
------------------

- Maintenance: update browserified build.


3.8.0 / 2017-02-07
------------------

- Fix reported position for `duplicated mapping key` errors.
Now points to block start instead of block end.
(#243, thanks to @shockey).


3.7.0 / 2016-11-12
------------------

- Fix parsing of quotes followed by newlines (#304, thanks to @dplepage).
- Support polymorphism for tags (#300, thanks to @monken).


3.6.1 / 2016-05-11
------------------

- Fix output cut on a pipe, #286.


3.6.0 / 2016-04-16
------------------

Expand Down
74 changes: 46 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JS-YAML - YAML 1.2 parser / writer for JavaScript
__[Online Demo](http://nodeca.github.com/js-yaml/)__


This is an implementation of [YAML](http://yaml.org/), a human friendly data
This is an implementation of [YAML](http://yaml.org/), a human-friendly data
serialization language. Started as [PyYAML](http://pyyaml.org/) port, it was
completely rewritten from scratch. Now it's very fast, and supports 1.2 spec.

Expand Down Expand Up @@ -57,7 +57,7 @@ var doc = jsyaml.load('greeting: hello\nname: world');
</script>
```

Browser support was done mostly for online demo. If you find any errors - feel
Browser support was done mostly for the online demo. If you find any errors - feel
free to send pull requests with fixes. Also note, that IE and other old browsers
needs [es5-shims](https://github.com/kriskowal/es5-shim) to operate.

Expand Down Expand Up @@ -122,17 +122,17 @@ NOTE: This function **does not** understand multi-document sources, it throws
exception on those.

NOTE: JS-YAML **does not** support schema-specific tag resolution restrictions.
So, JSON schema is not as strict as defined in the YAML specification.
So, the JSON schema is not as strictly defined in the YAML specification.
It allows numbers in any notation, use `Null` and `NULL` as `null`, etc.
Core schema also has no such restrictions. It allows binary notation for integers.
The core schema also has no such restrictions. It allows binary notation for integers.


### load (string [ , options ])

**Use with care with untrusted sources**. The same as `safeLoad()` but uses
`DEFAULT_FULL_SCHEMA` by default - adds some JavaScript-specific types:
`!!js/function`, `!!js/regexp` and `!!js/undefined`. For untrusted sources you
must additionally validate object structure, to avoid injections:
`!!js/function`, `!!js/regexp` and `!!js/undefined`. For untrusted sources, you
must additionally validate object structure to avoid injections:

``` javascript
var untrusted_code = '"toString": !<tag:yaml.org,2002:js/function> "function (){very_evil_thing();}"';
Expand All @@ -142,10 +142,10 @@ require('js-yaml').load(untrusted_code) + ''
```


### safeLoadAll (string, iterator [ , options ])
### safeLoadAll (string [, iterator] [, options ])

Same as `safeLoad()`, but understands multi-document sources and apply
`iterator` to each document.
Same as `safeLoad()`, but understands multi-document sources. Applies
`iterator` to each document if specified, or returns array of documents.

``` javascript
var yaml = require('js-yaml');
Expand All @@ -156,16 +156,16 @@ yaml.safeLoadAll(data, function (doc) {
```


### loadAll (string, iterator [ , options ])
### loadAll (string [, iterator] [ , options ])

Same as `safeLoadAll()` but uses `DEFAULT_FULL_SCHEMA` by default.


### safeDump (object [ , options ])

Serializes `object` as YAML document. Uses `DEFAULT_SAFE_SCHEMA`, so it will
throw exception if you try to dump regexps or functions. However, you can
disable exceptions by `skipInvalid` option.
Serializes `object` as a YAML document. Uses `DEFAULT_SAFE_SCHEMA`, so it will
throw an exception if you try to dump regexps or functions. However, you can
disable exceptions by setting the `skipInvalid` option to `true`.

options:

Expand All @@ -182,28 +182,46 @@ options:
- `noRefs` _(default: `false`)_ - if `true`, don't convert duplicate objects into references
- `noCompatMode` _(default: `false`)_ - if `true` don't try to be compatible with older
yaml versions. Currently: don't quote "yes", "no" and so on, as required for YAML 1.1
- `condenseFlow` _(default: `false`)_ - if `true` flow sequences will be condensed, omitting the space between `a, b`. Eg. `'[a,b]'`, and omitting the space between `key: value` and quoting the key. Eg. `'{"a":b}'` Can be useful when using yaml for pretty URL query params as spaces are %-encoded.

styles:
The following table show availlable styles (e.g. "canonical",
"binary"...) available for each tag (.e.g. !!null, !!int ...). Yaml
output is shown on the right side after `=>` (default setting) or `->`:

``` none
!!null
"canonical" => "~"
"canonical" -> "~"
"lowercase" => "null"
"uppercase" -> "NULL"
"camelcase" -> "Null"
!!int
"binary" => "0b1", "0b101010", "0b1110001111010"
"octal" => "01", "052", "016172"
"binary" -> "0b1", "0b101010", "0b1110001111010"
"octal" -> "01", "052", "016172"
"decimal" => "1", "42", "7290"
"hexadecimal" => "0x1", "0x2A", "0x1C7A"
"hexadecimal" -> "0x1", "0x2A", "0x1C7A"
!!null, !!bool, !!float
"lowercase" => "null", "true", "false", ".nan", '.inf'
"uppercase" => "NULL", "TRUE", "FALSE", ".NAN", '.INF'
"camelcase" => "Null", "True", "False", ".NaN", '.Inf'
```
!!bool
"lowercase" => "true", "false"
"uppercase" -> "TRUE", "FALSE"
"camelcase" -> "True", "False"
By default, !!int uses `decimal`, and !!null, !!bool, !!float use `lowercase`.
!!float
"lowercase" => ".nan", '.inf'
"uppercase" -> ".NAN", '.INF'
"camelcase" -> ".NaN", '.Inf'
```

Example:

``` javascript
safeDump (object, {
'styles': {
'!!null': 'canonical' // dump null as ~
},
'sortKeys': true // sort object keys
});
```

### dump (object [ , options ])

Expand Down Expand Up @@ -244,7 +262,7 @@ Caveats
-------

Note, that you use arrays or objects as key in JS-YAML. JS does not allow objects
or array as keys, and stringifies (by calling .toString method) them at the
or arrays as keys, and stringifies (by calling `toString()` method) them at the
moment of adding them.

``` yaml
Expand Down Expand Up @@ -276,14 +294,14 @@ Breaking changes in 2.x.x -> 3.x.x
----------------------------------

If you have not used __custom__ tags or loader classes and not loaded yaml
files via `require()` - no changes needed. Just upgrade library.
files via `require()`, no changes are needed. Just upgrade the library.

Otherwise, you should:

1. Replace all occurences of `require('xxxx.yml')` by `fs.readFileSync()` +
1. Replace all occurrences of `require('xxxx.yml')` by `fs.readFileSync()` +
`yaml.safeLoad()`.
2. rewrite your custom tags constructors and custom loader
classes, to conform new API. See
classes, to conform the new API. See
[examples](https://github.com/nodeca/js-yaml/tree/master/examples) and
[wiki](https://github.com/nodeca/js-yaml/wiki) for details.

Expand Down
2 changes: 0 additions & 2 deletions bin/js-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,4 @@ readFile(options.file, 'utf8', function (error, input) {

if (isYaml) console.log(JSON.stringify(output, null, ' '));
else console.log(yaml.dump(output));

process.exit(0);
});
Loading

0 comments on commit 7a41c3b

Please sign in to comment.