您好,登錄后才能下訂單哦!
安裝 js-yaml
npm install js-yaml
index.js
let fs = require("fs"); let content = fs.readFileSync("text.yaml",{encoding:"utf8"}); let yaml = require("js-yaml"); let result = yaml.load(content); console.log(JSON.stringify(result, null, 2)); console.log(result.fn(1,3)); console.log(result.reg.test("test")); console.log(result.undef);
text.yaml
#對象鍵值對 name: xxx hash: { name: Steve, foo: bar } #數組 array: - Cat - Dog - Goldfish array2: [Cat, Dog] array3: - - a - b #符合結構 languages: - ruby - [{name: perl,code: 2}] - name: js code: 3 #純量 parent: ~ isSet: true number: 12.30 date: 1976-07-31 #類型轉換 string: !!str 1 int: !!int "2" bool: !!bool "true" fn: !!js/function function(a,b){return a+b;} reg: !!js/regexp /test/ undef: !!js/undefined '' #引用 defaults: &defaults adapter: postgres host: localhost newDefault: *defaults development: database: myapp_development <<: *defaults
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。