YAML小结
1. Mapping
shorthand: !!map
Example 1. !!map Examples
1 # Unordered set of key: value pairs. 2 Block style: !!map 3 Clark : Evans 4 Brian : Ingerson 5 Oren : Ben-Kiki 6 Flow style: !!map { Clark: Evans, Brian: Ingerson, Oren: Ben-Kiki }
2. Ordered Mapping
shorthand: !!omap
Example 1. !!omap Examples
1 # Explicitly typed ordered map (dictionary). 2 Bestiary: !!omap 3 - aardvark: African pig-like ant eater. Ugly. 4 - anteater: South-American ant eater. Two species. 5 - anaconda: South-American constrictor snake. Scaly. 6 # Etc. 7 # Flow style 8 Numbers: !!omap [ one: 1, two: 2, three : 3 ]
3. Pairs
shorthand: !!pairs
Example 1. !!pairs Examples
1 # Explicitly typed pairs. 2 Block tasks: !!pairs 3 - meeting: with team. 4 - meeting: with boss. 5 - break: lunch. 6 - meeting: with client. 7 Flow tasks: !!pairs [ meeting: with team, meeting: with boss ]
4. Set
shorthand: !!set
Example 1. !!set Examples
1 # Explicitly typed set. 2 baseball players: !!set 3 ? Mark McGwire 4 ? Sammy Sosa 5 ? Ken Griffey 6 # Flow style 7 baseball teams: !!set { Boston Red Sox, Detroit Tigers, New York Yankees
5. Seq
shorthand: !!seq
Example 1. !!seq Examples
1 # Ordered sequence of nodes 2 Block style: !!seq 3 - Mercury # Rotates - no light/dark sides. 4 - Venus # Deadliest. Aptly named. 5 - Earth # Mostly dirt. 6 - Mars # Seems empty. 7 - Jupiter # The king. 8 - Saturn # Pretty. 9 - Uranus # Where the sun hardly shines. 10 - Neptune # Boring. No rings. 11 - Pluto # You call this a planet? 12 Flow style: !!seq [ Mercury, Venus, Earth, Mars, # Rocks 13 Jupiter, Saturn, Uranus, Neptune, # Gas 14 Pluto ] # Overrated
6. Bool
shorthand: !!bool
Example 1. !!bool Examples
1 canonical: y 2 answer: NO 3 logical: True 4 option: on
7. Float
shorthand: !!float
Example 1. !!float Examples
1 canonical: 6.8523015e+5 2 exponentioal: 685.230_15e+03 3 fixed: 685_230.15 4 sexagesimal: 190:20:30.15 5 negative infinity: -.inf 6 not a number: .NaN
8.常用类型列表
1 !!null '' # null 2 !!bool 'yes' # bool 3 !!int '3...' # number 4 !!float '3.14...' # number 5 !!binary '...base64...' # buffer 6 !!timestamp 'YYYY-...' # date 7 !!omap [ ... ] # array of key-value pairs 8 !!pairs [ ... ] # array or array pairs 9 !!set { ... } # array of objects with given keys and null values 10 !!str '...' # string 11 !!seq [ ... ] # array 12 !!map { ... } # object 13 14 !!js/regexp /pattern/gim # RegExp 15 !!js/undefined '' # Undefined 16 !!js/function 'function () {...}' # Function
9.一些特殊的写法
Note, that you use arrays or objects as key in JS-YAML. JS do not allows objects or array as keys, and stringifies (by calling .toString method) them at the moment of adding them.(有空再翻译 囧)
1 --- 2 ? [ foo, bar ] 3 : - baz 4 ? { foo: bar } 5 : - baz 6 - baz
1 { "foo,bar": ["baz"], "[object Object]": ["baz", "baz"] }
参考链接:http://nodeca.github.com/js-yaml/
YAML官网:http://www.yaml.org/

浙公网安备 33010602011771号