forked from nodeca/js-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dervus Grim
committed
Feb 7, 2013
1 parent
bcf1568
commit 5879c09
Showing
5 changed files
with
157 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// JS-YAML 2.0.x | ||
|
||
var yaml = require('js-yaml'); | ||
|
||
var cookiesType = new yaml.Type('!cookies', { | ||
loader: { | ||
kind: 'array', | ||
resolver: function (array, explicit) { | ||
var index, length; | ||
|
||
for (index = 0, length = array.length; index < length; index += 1) { | ||
array[index] = 'A ' + array[index] + ' with some cookies!'; | ||
} | ||
|
||
return array; | ||
} | ||
} | ||
}); | ||
|
||
var COOKIES_SCHEMA = new yaml.Schema({ | ||
include: [ yaml.DEFAULT_SCHEMA ], | ||
explicit: [ cookiesType ] | ||
}); | ||
|
||
console.log(yaml.load(data, { schema: COOKIES_SCHEMA })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// JS-YAML version 1.x.x (deprecated) | ||
|
||
var yaml = require('js-yaml'); | ||
|
||
yaml.addConstructor('!cookies', function (node) { | ||
var array, index, length; | ||
|
||
array = this.constructSequence(node); | ||
|
||
for (index = 0, length = array.length; index < length; index += 1) { | ||
array[index] = 'A ' + array[index] + ' with some cookies!'; | ||
} | ||
|
||
return array; | ||
}); | ||
|
||
console.log(yaml.load(data)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
|
||
var yaml = require('js-yaml'); | ||
|
||
|
||
var object = { | ||
name: 'Wizzard', | ||
level: 17, | ||
sanity: null, | ||
inventory: [ | ||
{ | ||
name: 'Hat', | ||
features: [ 'magic', 'pointed' ], | ||
traits: {} | ||
}, | ||
{ | ||
name: 'Staff', | ||
features: [], | ||
traits: { damage: 10 } | ||
}, | ||
{ | ||
name: 'Cloak', | ||
features: [ 'old' ], | ||
traits: { defence: 0, comfort: 3 } | ||
} | ||
] | ||
}; | ||
|
||
|
||
console.log(yaml.dump(object, { | ||
flowLevel: 3, | ||
styles: { | ||
'!!int' : 'hexadecimal', | ||
'!!null' : 'camelcase' | ||
} | ||
})); | ||
|
||
|
||
// Output: | ||
//============================================================================== | ||
// "name": "Wizzard" | ||
// "level": 0x11 | ||
// "sanity": Null | ||
// "inventory": | ||
// - "name": "Hat" | ||
// "features": ["magic", "pointed"] | ||
// "traits": {} | ||
// - "name": "Staff" | ||
// "features": [] | ||
// "traits": {"damage": 0xA} | ||
// - "name": "Cloak" | ||
// "features": ["old"] | ||
// "traits": {"defence": 0x0, "comfort": 0x3} |
Oops, something went wrong.