Hướng dẫn nodejs yaml parser - trình phân tích cú pháp nodejs yaml

2.1.3 & nbsp; • & nbsp; public & nbsp; • & nbsp; xuất bản một tháng trướcPublic • Published a month ago

  • Readme
  • Khám phá BetaBETA
  • 0 phụ thuộc
  • 3,805 người phụ thuộc
  • 68 phiên bản

Yaml
Hướng dẫn nodejs yaml parser - trình phân tích cú pháp nodejs yaml

yaml là một thư viện dứt khoát cho YAML, tiêu chuẩn tuần tự hóa dữ liệu thân thiện của con người. Thư viện này:

  • Hỗ trợ cả YAML 1.1 và YAML 1.2 và tất cả các lược đồ dữ liệu phổ biến,
  • Vượt qua tất cả các bài kiểm tra Yaml-Test-suite,
  • Có thể chấp nhận bất kỳ chuỗi nào làm đầu vào mà không cần ném, phân tích càng nhiều yaml ra khỏi nó càng tốt, và
  • Hỗ trợ phân tích cú pháp, sửa đổi và viết bình luận YAML và các dòng trống.

Thư viện được phát hành theo giấy phép nguồn mở của ISC và mã có sẵn trên GitHub. Nó không có phụ thuộc bên ngoài và chạy trên Node.js cũng như trình duyệt hiện đại.

Đối với các mục đích của phiên bản, bất kỳ thay đổi nào phá vỡ bất kỳ điểm cuối hoặc API được ghi nhận nào sẽ được coi là thay đổi phá vỡ Semver-Major. Nội bộ thư viện không có giấy tờ có thể thay đổi giữa các phiên bản nhỏ và các API trước đó có thể bị phản đối (nhưng không bị xóa).

Để biết thêm thông tin, hãy xem trang web tài liệu của dự án: eemeli.org/yamleemeli.org/yaml

Để cài đặt:

Lưu ý: Những tài liệu này dành cho yaml@2. Đối với V1, xem thẻ v1.10.0 cho nguồn và eemeli.org/yaml/v1 để biết tài liệu. These docs are for yaml@2. For v1, see the v1.10.0 tag for the source and eemeli.org/yaml/v1 for the documentation.

Tổng quan API

API được cung cấp bởi yaml có ba lớp, tùy thuộc vào mức độ bạn cần đi: Parse & Stringify, tài liệu và trình phân tích/trình phân tích cú pháp/trình soạn thảo cơ bản. Đầu tiên có API đơn giản nhất và "công việc chỉ hoạt động", lần thứ hai giúp bạn có tất cả các chuông và còi được thư viện hỗ trợ cùng với AST tốt, và lần thứ ba cho phép bạn tiến gần hơn đến nguồn YAML, nếu đó là điều của bạn.

import { parse, stringify } from 'yaml'
// or
import YAML from 'yaml'
// or
const YAML = require('yaml')

Parse & Stringify

  • parse(str, reviver?, options?): value
  • stringify(value, replacer?, options?): string

Các tài liệu

  • Document
    • # file.yml
      YAML:
        - A human-readable data serialization language
        - https://en.wikipedia.org/wiki/YAML
      yaml:
        - A complete JavaScript implementation
        - https://www.npmjs.com/package/yaml
      0
    • # file.yml
      YAML:
        - A human-readable data serialization language
        - https://en.wikipedia.org/wiki/YAML
      yaml:
        - A complete JavaScript implementation
        - https://www.npmjs.com/package/yaml
      1
    • # file.yml
      YAML:
        - A human-readable data serialization language
        - https://en.wikipedia.org/wiki/YAML
      yaml:
        - A complete JavaScript implementation
        - https://www.npmjs.com/package/yaml
      2
    • # file.yml
      YAML:
        - A human-readable data serialization language
        - https://en.wikipedia.org/wiki/YAML
      yaml:
        - A complete JavaScript implementation
        - https://www.npmjs.com/package/yaml
      3
    • # file.yml
      YAML:
        - A human-readable data serialization language
        - https://en.wikipedia.org/wiki/YAML
      yaml:
        - A complete JavaScript implementation
        - https://www.npmjs.com/package/yaml
      4
    • # file.yml
      YAML:
        - A human-readable data serialization language
        - https://en.wikipedia.org/wiki/YAML
      yaml:
        - A complete JavaScript implementation
        - https://www.npmjs.com/package/yaml
      5
  • # file.yml
    YAML:
      - A human-readable data serialization language
      - https://en.wikipedia.org/wiki/YAML
    yaml:
      - A complete JavaScript implementation
      - https://www.npmjs.com/package/yaml
    6
  • # file.yml
    YAML:
      - A human-readable data serialization language
      - https://en.wikipedia.org/wiki/YAML
    yaml:
      - A complete JavaScript implementation
      - https://www.npmjs.com/package/yaml
    7
  • # file.yml
    YAML:
      - A human-readable data serialization language
      - https://en.wikipedia.org/wiki/YAML
    yaml:
      - A complete JavaScript implementation
      - https://www.npmjs.com/package/yaml
    8

Nội dung nút

  • # file.yml
    YAML:
      - A human-readable data serialization language
      - https://en.wikipedia.org/wiki/YAML
    yaml:
      - A complete JavaScript implementation
      - https://www.npmjs.com/package/yaml
    9
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    0
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    1
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    2
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    3
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    4
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    5
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    6
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    7
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    8
  • import fs from 'fs'
    import YAML from 'yaml'
    
    YAML.parse('3.14159')
    // 3.14159
    
    YAML.parse('[ true, false, maybe, null ]\n')
    // [ true, false, 'maybe', null ]
    
    const file = fs.readFileSync('./file.yml', 'utf8')
    YAML.parse(file)
    // { YAML:
    //   [ 'A human-readable data serialization language',
    //     'https://en.wikipedia.org/wiki/YAML' ],
    //   yaml:
    //   [ 'A complete JavaScript implementation',
    //     'https://www.npmjs.com/package/yaml' ] }
    9
  • import YAML from 'yaml'
    
    YAML.stringify(3.14159)
    // '3.14159\n'
    
    YAML.stringify([true, false, 'maybe', null])
    // `- true
    // - false
    // - maybe
    // - null
    // `
    
    YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
    // `number: 3
    // plain: string
    // block: |
    //   two
    //   lines
    // `
    0
  • import YAML from 'yaml'
    
    YAML.stringify(3.14159)
    // '3.14159\n'
    
    YAML.stringify([true, false, 'maybe', null])
    // `- true
    // - false
    // - maybe
    // - null
    // `
    
    YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
    // `number: 3
    // plain: string
    // block: |
    //   two
    //   lines
    // `
    1
  • import YAML from 'yaml'
    
    YAML.stringify(3.14159)
    // '3.14159\n'
    
    YAML.stringify([true, false, 'maybe', null])
    // `- true
    // - false
    // - maybe
    // - null
    // `
    
    YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
    // `number: 3
    // plain: string
    // block: |
    //   two
    //   lines
    // `
    2

Phân tích cú pháp yaml

  • import YAML from 'yaml'
    
    YAML.stringify(3.14159)
    // '3.14159\n'
    
    YAML.stringify([true, false, 'maybe', null])
    // `- true
    // - false
    // - maybe
    // - null
    // `
    
    YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
    // `number: 3
    // plain: string
    // block: |
    //   two
    //   lines
    // `
    3
  • import YAML from 'yaml'
    
    YAML.stringify(3.14159)
    // '3.14159\n'
    
    YAML.stringify([true, false, 'maybe', null])
    // `- true
    // - false
    // - maybe
    // - null
    // `
    
    YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
    // `number: 3
    // plain: string
    // block: |
    //   two
    //   lines
    // `
    4
  • import YAML from 'yaml'
    
    YAML.stringify(3.14159)
    // '3.14159\n'
    
    YAML.stringify([true, false, 'maybe', null])
    // `- true
    // - false
    // - maybe
    // - null
    // `
    
    YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
    // `number: 3
    // plain: string
    // block: |
    //   two
    //   lines
    // `
    5

YAML.parse

# file.yml
YAML:
  - A human-readable data serialization language
  - https://en.wikipedia.org/wiki/YAML
yaml:
  - A complete JavaScript implementation
  - https://www.npmjs.com/package/yaml

import fs from 'fs'
import YAML from 'yaml'

YAML.parse('3.14159')
// 3.14159

YAML.parse('[ true, false, maybe, null ]\n')
// [ true, false, 'maybe', null ]

const file = fs.readFileSync('./file.yml', 'utf8')
YAML.parse(file)
// { YAML:
//   [ 'A human-readable data serialization language',
//     'https://en.wikipedia.org/wiki/YAML' ],
//   yaml:
//   [ 'A complete JavaScript implementation',
//     'https://www.npmjs.com/package/yaml' ] }

YAML.stringify

import YAML from 'yaml'

YAML.stringify(3.14159)
// '3.14159\n'

YAML.stringify([true, false, 'maybe', null])
// `- true
// - false
// - maybe
// - null
// `

YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
// `number: 3
// plain: string
// block: |
//   two
//   lines
// `


Kiểm tra trình duyệt được cung cấp bởi: