Skip to content

Commit 1ea8370

Browse files
committed
Fix examples
1 parent 73ef02c commit 1ea8370

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

examples/.eslintrc.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
env:
2+
es6: true
3+
4+
parserOptions:
5+
ecmaVersion: 2017

examples/handle_unknown_types.js

+12-24
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
/*eslint-disable no-console*/
44

5-
var fs = require('fs');
6-
var path = require('path');
7-
var util = require('util');
8-
var yaml = require('../');
5+
const util = require('util');
6+
const yaml = require('../');
97

108

11-
var tags = [ 'scalar', 'sequence', 'mapping' ].map(function (kind) {
9+
const tags = [ 'scalar', 'sequence', 'mapping' ].map(function (kind) {
1210
// first argument here is a prefix, so this type will handle anything starting with !
1311
return new yaml.Type('!', {
1412
kind: kind,
@@ -19,24 +17,14 @@ var tags = [ 'scalar', 'sequence', 'mapping' ].map(function (kind) {
1917
});
2018
});
2119

22-
var SCHEMA = yaml.DEFAULT_SCHEMA.extend(tags);
20+
const SCHEMA = yaml.DEFAULT_SCHEMA.extend(tags);
2321

24-
// do not execute the following if file is required (http://stackoverflow.com/a/6398335)
25-
if (require.main === module) {
22+
const data = `
23+
subject: Handling unknown types in JS-YAML
24+
scalar: !unknown_scalar_tag 123
25+
sequence: !unknown_sequence_tag [ 1, 2, 3 ]
26+
mapping: !unknown_mapping_tag { foo: 1, bar: 2 }
27+
`;
2628

27-
// And read a document using that schema.
28-
fs.readFile(path.join(__dirname, 'handle_unknown_types.yml'), 'utf8', function (error, data) {
29-
var loaded;
30-
31-
if (!error) {
32-
loaded = yaml.load(data, { schema: SCHEMA });
33-
console.log(util.inspect(loaded, false, 20, true));
34-
} else {
35-
console.error(error.stack || error.message || String(error));
36-
}
37-
});
38-
}
39-
40-
// There are some exports to play with this example interactively.
41-
module.exports.tags = tags;
42-
module.exports.SCHEMA = SCHEMA;
29+
const loaded = yaml.load(data, { schema: SCHEMA });
30+
console.log(util.inspect(loaded, false, 20, true));

examples/handle_unknown_types.yml

-4
This file was deleted.

0 commit comments

Comments
 (0)