Skip to content

Commit

Permalink
Docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Dec 3, 2020
1 parent 2fcfa81 commit d1692b9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 76 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Breaking: "unsafe" tags `!!js/function`, `!!js/regexp`, `!!js/undefined` are
moved to [js-yaml-js-types](https://github.com/nodeca/js-yaml-js-types) package.
- Breaking: removed `safe*` functions. Use `load`, `loadAll`, `dump`, `dumpAll`
- Breaking: removed `safe*` functions. Use `load`, `loadAll`, `dump`
instead which are all now safe by default.
- `yaml.DEFAULT_SAFE_SCHEMA` and `yaml.DEFAULT_FULL_SCHEMA` are removed, use
`yaml.DEFAULT_SCHEMA` instead.
Expand Down
41 changes: 6 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,12 @@ Optional arguments:
```


### Bundled YAML library for browsers

``` html
<!-- esprima required only for !!js/function -->
<script src="esprima.js"></script>
<script src="js-yaml.min.js"></script>
<script type="text/javascript">
var doc = jsyaml.load('greeting: hello\nname: world');
</script>
```

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.

Notes:

1. We have no resources to support browserified version. Don't expect it to be
well tested. Don't expect fast fixes if something goes wrong there.
2. `!!js/function` in browser bundle will not work by default. If you really need
it - load `esprima` parser first (via amd or directly).
3. `!!bin` in browser will return `Array`, because browsers do not support
node.js `Buffer` and adding Buffer shims is completely useless on practice.


API
---

Here we cover the most 'useful' methods. If you need advanced details (creating
your own tags), see [wiki](https://github.com/nodeca/js-yaml/wiki) and
[examples](https://github.com/nodeca/js-yaml/tree/master/examples) for more
info.
your own tags), see [examples](https://github.com/nodeca/js-yaml/tree/master/examples)
for more info.

``` javascript
const yaml = require('js-yaml');
Expand Down Expand Up @@ -112,8 +86,7 @@ options:
http://www.yaml.org/spec/1.2/spec.html#id2803231
- `CORE_SCHEMA` - same as `JSON_SCHEMA`:
http://www.yaml.org/spec/1.2/spec.html#id2804923
- `DEFAULT_SCHEMA` - all supported YAML types, without unsafe ones
(`!!js/undefined`, `!!js/regexp` and `!!js/function` are moved to [separate package](https://github.com/nodeca/js-yaml-js-types)).
- `DEFAULT_SCHEMA` - all supported YAML types.
- `json` _(default: false)_ - compatibility with JSON.parse behaviour. If true, then duplicate keys in a mapping will override values rather than throwing an error.

NOTE: This function **does not** understand multi-document sources, it throws
Expand Down Expand Up @@ -226,11 +199,9 @@ The list of standard YAML tags and corresponding JavaScript types. See also

**JavaScript-specific tags**

```
!!js/regexp /pattern/gim # RegExp
!!js/undefined '' # Undefined
!!js/function 'function () {...}' # Function
```
See [js-yaml-js-types](https://github.com/nodeca/js-yaml-js-types) for
extra types.


Caveats
-------
Expand Down
11 changes: 0 additions & 11 deletions benchmark/samples/document_nodeca_application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,3 @@ bind:

forum.index:
mount: /

# ACTION, WHEN REQUESTED HOST IS UNKNOWN
#
# _ is a special keyword that hold function called when hostname is not
# supposed to be served by server listener, by default 404 not found:
#
#_: !!js/function |
# function (req, res) {
# res.writeHead(404, { 'Content-Type': 'text/plain' });
# res.end('Invalid host ' + req.headers.host);
# }
2 changes: 1 addition & 1 deletion examples/custom_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var fs = require('fs');
var path = require('path');
var util = require('util');
var yaml = require('../lib/js-yaml');
var yaml = require('../');


// Let's define a couple of classes.
Expand Down
2 changes: 1 addition & 1 deletion examples/dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*eslint-disable no-console*/

var yaml = require('../lib/js-yaml');
var yaml = require('../');
var object = require('./dumper.json');


Expand Down
2 changes: 1 addition & 1 deletion examples/sample_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var fs = require('fs');
var path = require('path');
var util = require('util');
var yaml = require('../lib/js-yaml');
var yaml = require('../');


try {
Expand Down
31 changes: 5 additions & 26 deletions examples/sample_document.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,24 @@ merge:
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }

# All the following maps are equal:

- # Explicit keys
x: 1
y: 2
r: 10
label: nothing

- # Merge one map
<< : *CENTER
r: 10
label: center

- # Merge multiple maps
<< : [ *CENTER, *BIG ]
label: center/big

- # Override
<< : [ *BIG, *LEFT, *SMALL ]
x: 1
Expand Down Expand Up @@ -174,24 +174,3 @@ timestamp:
space separated: 2001-12-14 21:59:43.10 -5
no time zone (Z): 2001-12-15 2:59:43.10
date (00:00:00Z): 2002-12-14


# JavaScript Specific Types ####################################################
################################################################################

# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp

regexp:
simple: !!js/regexp foobar
modifiers: !!js/regexp /foobar/mi

# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined

undefined: !!js/undefined ~

# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function

function: !!js/function >
function foobar() {
return 'Wow! JS-YAML Rocks!';
}
3 changes: 3 additions & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ function State(input, options) {
this.filename = options['filename'] || null;
this.schema = options['schema'] || DEFAULT_SCHEMA;
this.onWarning = options['onWarning'] || null;
// (Hidden) Remove? makes the loader to expect YAML 1.1 documents
// if such documents have no explicit %YAML directive
this.legacy = options['legacy'] || false;

this.json = options['json'] || false;
this.listener = options['listener'] || null;

Expand Down

0 comments on commit d1692b9

Please sign in to comment.