JSPM

  • Created
  • Published
  • Downloads 388485
  • Score
    100M100P100Q206902F
  • License LGPL-3.0

An implementation of TOML v0.5 written by LongTengDao./龙腾道为汤小明语 v0.5 写的实现。

Package Exports

  • @ltd/j-toml

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ltd/j-toml) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

English | 简体中文 ___ @ltd/j-toml v0.5

@ltd/j-toml v0.5 is an implementation of TOML v0.5 ("Tom's Obvious, Minimal Language") written by LongTengDao,
which is the best config format he had ever seen.
(Obviously for exhausted people who tried to design that.)

Node.js

npm install @ltd/j-toml
const TOML = require('@ltd/j-toml');

const sourceContent  = `
      I_am_normal    = "..."
      hasOwnProperty = "..."
      constructor    = "..."
      __proto__      = "..."
`;

const rootTable = TOML.parse(sourceContent, 0.5, '\n');

rootTable.I_am_normal    // "..."
rootTable.hasOwnProperty // "..."
rootTable.constructor    // "..."
rootTable.__proto__      // "..."

TOML.parse

TOML.parse(sourceContent, specificationVersion, multiLineJoiner[, useBigInt=true[, xOptions]]);
function parse (
         sourceContent        :string | Buffer,
         specificationVersion :0.5,
         multiLineJoiner      :string,
         useBigInt?           :boolean | number = true,
         xOptions?            :object
) :Table;

arguments

  1. sourceContent

    • required
    • type: string / Buffer(utf8)

    If the string starts with UTF BOM, that's ok.
    You can also pass in a Buffer. But it must be UTF 8 encoding, that's not a technology problem, but a requirement in the specification.

  2. specificationVersion

    • required
    • type: 0.5

    You must specify it explicitly (though it can't be other value for the time being).

  3. multiLineJoiner

    • required
    • type: string

    For the multi-line strings, use what to join the lines for result.
    Note that TOML always use "\n" or "\r\n" split the source lines while parsing, which defined in TOML spec.

  4. useBigInt

    • default: true
    • type: boolean / number

    Specify whether you want or not to use BigInt for integer type value. A number type argument allows you to control it by a max limit, like Number.MAX_SAFE_INTEGER (and the min limit from -useBigInt, if useBigInt>=0; otherwise as the min limit, and the max limit is -useBigInt-1).

  5. xOptions

    • type: object

    The extensional features not in the spec.
    Include keeping the key/value pairs order of tables, integers larger than long, comment information, null value, mixed-type array, multi-line inline table with trailing comma even no comma, interpolation string, custom constructor, etc.
    They are private experimental discouraged features.
    See xOptions.

return

  • type: Table

Return the root table (tables parsed by this implementation are objects without any extended properties).

throw

  • type: Error

If the arguments not meet the requirement, there will be an error; if there is any error with the source, the error object will has two number properties lineIndex and lineNumber to help locating that.