Skip to content

Commit

Permalink
update custom types example
Browse files Browse the repository at this point in the history
do not execute console.log when module is required
and exports are used
  • Loading branch information
rockitbaby committed Apr 29, 2015
1 parent 9cc570a commit 0b9042f
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions examples/custom_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ var SpaceYamlType = new yaml.Type('!space', {

var SPACE_SCHEMA = yaml.Schema.create([ SpaceYamlType, PointYamlType ]);


// And read a document using that schema.

fs.readFile(path.join(__dirname, 'custom_types.yml'), 'utf8', function (error, data) {
var loaded;

if (!error) {
loaded = yaml.load(data, { schema: SPACE_SCHEMA });
console.log(util.inspect(loaded, false, 20, true));
} else {
console.error(error.stack || error.message || String(error));
}
});

// do not execute the following if file is required (http://stackoverflow.com/a/6398335)
if (require.main === module) {

// And read a document using that schema.
fs.readFile(path.join(__dirname, 'custom_types.yml'), 'utf8', function (error, data) {
var loaded;

if (!error) {
loaded = yaml.load(data, { schema: SPACE_SCHEMA });
console.log(util.inspect(loaded, false, 20, true));
} else {
console.error(error.stack || error.message || String(error));
}
});
}

// There are some exports to play with this example interactively.

module.exports.Point = Point;
module.exports.Space = Space;
module.exports.PointYamlType = PointYamlType;
Expand Down

0 comments on commit 0b9042f

Please sign in to comment.