
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@ltd/j-toml
Advanced tools
An implementation of TOML written by LongTengDao. Belong to "Plan J"./龙腾道为汤小明语写的实现。从属于“简计划”。
@ltd/j-toml
@ltd/j-toml
is an implementation of TOML ("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.)
npm install @ltd/j-toml
const TOML = require('@ltd/j-toml');
const source = `
I_am_normal = "..."
hasOwnProperty = "..."
constructor = "..."
__proto__ = "..."
`;
const rootTable = TOML.parse(source, '\n');
rootTable.I_am_normal // "..."
rootTable.hasOwnProperty // "..."
rootTable.constructor // "..."
rootTable.__proto__ // "..."
rootTable.valueOf // undefined
Object.keys(rootTable) // [ "I_am_normal", "hasOwnProperty", "constructor", "__proto__" ]
TOML.parse
TOML.parse(source, specificationVersion, multiLineStringJoiner, useBigInt = true, xOptions = null);
TOML.parse(source, multiLineStringJoiner, useBigInt = true, xOptions = null);
declare function parse (
source :Source,
specificationVersion :SpecificationVersion,
multiLineStringJoiner :string,
useBigInt? :boolean | number,
xOptions? :object,
) :Table;
declare function parse (
source :Source,
multiLineStringJoiner :string,
useBigInt? :boolean | number,
xOptions? :object,
) :Table;
type Source = string | Buffer | { readonly path :string, readonly data? :string | Buffer };
type SpecificationVersion = 1.0 | 0.5 | 0.4 | 0.3 | 0.2 | 0.1;
type Table = object;
arguments
source
string | Buffer | { readonly path :string, readonly data? :string | Buffer }
You can pass in string
or the original binary Buffer
(UTF-8) of the file as the source content.
One difference is that when passing in string
, parser will only check whether all characters are valid Unicode characters according to the specification (uncoupled UCS-4 character code is invalid);
When Buffer
is passed in, an additional check is made to see whether there is unknown code point (which has been automatically replaced by U+FFFD
in the string
state).
Another difference is that Buffer
can start with UTF BOM (U+FEFF
), which is used for validation of file encoding (but it must be UTF-8 encoding, which is not a technical limit, but a specification requirement), and skipped before real parsing;
But string
can't, because BOM belongs to UTF, not TOML.
If you want to be more console friendly when something of source content goes wrong, pass an object where the path
key is the path of that .toml
file, and the key data
is the source content (string
or Buffer
).
You can also omit the data
key and globalThis.require('fs').readFileSync(source.path)
will be called automatically.
specificationVersion
1.0 | 0.5 | 0.4 | 0.3 | 0.2 | 0.1
1.0
If there is no special reason (e.g. the downstream program could not deal with Infinity
、NaN
、fractional seconds and edge Datetime values, Local Date-Time / Local Date / Local Time types, empty string key name, mixed type array even array of tables / table under array of arrays structure yet), the latest version is recommended.
If you skip this argument, the rest arguments must be moved one position to the left.
multiLineStringJoiner
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 specification.
useBigInt
boolean | number
true
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
).
xOptions
The extensional features not in the specification.
Include keeping the key/value pairs order of tables, integers larger than signed long
, multi-line inline table with trailing comma even no comma, null
value, custom constructor, etc.
They are private experimental discouraged features.
See xOptions.
return
Table
Return the root table (tables parsed by this implementation are objects without any extended properties).
throw
Error
There will be an error thrown, when the arguments not meet the requirement or there is any error within the source.
TOML.parse[1.0]
TOML.parse[0.5]
TOML.parse[0.4]
TOML.parse[0.3]
TOML.parse[0.2]
TOML.parse[0.1]
TOML.parse[1.0](source, multiLineStringJoiner, useBigInt = true, xOptions = null);
TOML.parse[0.5](source, multiLineStringJoiner, useBigInt = true, xOptions = null);
TOML.parse[0.4](source, multiLineStringJoiner, useBigInt = true, xOptions = null);
TOML.parse[0.3](source, multiLineStringJoiner, useBigInt = true, xOptions = null);
TOML.parse[0.2](source, multiLineStringJoiner, useBigInt = true, xOptions = null);
TOML.parse[0.1](source, multiLineStringJoiner, useBigInt = true, xOptions = null);
declare const parse :{
readonly [SpecificationVersion in 1.0 | 0.5 | 0.4 | 0.3 | 0.2 | 0.1] :(
source :Source,
multiLineStringJoiner :string,
useBigInt? :boolean | number,
xOptions? :object,
) => Table
};
FAQs
An implementation of TOML written by LongTengDao. Belong to "Plan J"./龙腾道为汤小明语写的实现。从属于“简计划”。
The npm package @ltd/j-toml receives a total of 35,210 weekly downloads. As such, @ltd/j-toml popularity was classified as popular.
We found that @ltd/j-toml demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.