Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iarna/toml

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iarna/toml - npm Package Compare versions

Comparing version 2.2.5 to 3.0.0

21

CHANGELOG.md

@@ -1,7 +0,20 @@

# 2.2.5
# 3.0.0
* Docs: Updated benchmark results. Add fast-toml to result list. Improved benchmark layout.
* Update @sgarciac/bombadil and @ltd/j-toml in benchmarks and compliance tests.
* Dev: Some dev dep updates that shouldn't have any impact.
[TOML v1.0.0-rc.1](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v1.0.0-rc.1.md)
has been released! This update brings support for it! It's not a huge
update, an evening of tests and an evening of parser updates, but the
changes as a consumer of TOML are actually pretty impactful:
* Inline arrays can have mixed types now!!
* Inline tables MAY NOT have trailing commas. (Inline arrays are still allowed to have trailing commas.)
* Control chars are no longer allowed in comments. Only tabs may be used in comments.
* Multiline basic and literal strings can have quotes nestled up next to the closing triplet, that is:
`""""Hello," she said, "this is a thing.""""` is the equivalent of the JSON `"\"Hello,\" she said, \"this is a thing.\""`.
* Subtables may not extend tables created via dotted keys, that is, the following is invalid:```
[a]
x.y = 1
[a.x]
z = 2
```
# 2.2.4

@@ -8,0 +21,0 @@

3

index.d.ts
import { Transform } from "stream";
type JsonArray = boolean[] | number[] | string[] | JsonMap[] | Date[]
type JsonValue = boolean | number | string | JsonMap | JsonArray | Date
type JsonArray = JsonValue[]
type AnyJson = boolean | number | string | JsonMap | Date | JsonArray | JsonArray[]

@@ -5,0 +6,0 @@

@@ -323,3 +323,3 @@ 'use strict'

for (let kw of kv.key) {
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
if (hasKey(target, kw) && !isTable(target[kw])) {
throw this.error(new TomlError("Can't redefine existing key"))

@@ -332,2 +332,3 @@ }

}
target[_declared] = true
// unbox our numbers

@@ -390,2 +391,4 @@ if (isInteger(kv.value) || isFloat(kv.value)) {

return this.return()
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
throw this.errorControlCharIn('comments')
}

@@ -604,3 +607,3 @@ } while (this.nextChar())

} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
throw this.errorControlCharInString()
throw this.errorControlCharIn('strings')
} else {

@@ -634,3 +637,3 @@ this.consume()

} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M)) {
throw this.errorControlCharInString()
throw this.errorControlCharIn('strings')
} else {

@@ -651,3 +654,3 @@ this.consume()

if (this.char === CHAR_APOS) {
return this.return()
return this.next(this.parseLiteralMultiEnd3)
} else {

@@ -658,2 +661,18 @@ this.state.buf += "''"

}
parseLiteralMultiEnd3 () {
if (this.char === CHAR_APOS) {
this.state.buf += "'"
return this.next(this.parseLiteralMultiEnd4)
} else {
return this.returnNow()
}
}
parseLiteralMultiEnd4 () {
if (this.char === CHAR_APOS) {
this.state.buf += "'"
return this.return()
} else {
return this.returnNow()
}
}

@@ -677,3 +696,3 @@ /* STRINGS double quoted */

} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
throw this.errorControlCharInString()
throw this.errorControlCharIn('strings')
} else {

@@ -713,3 +732,3 @@ this.consume()

} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M)) {
throw this.errorControlCharInString()
throw this.errorControlCharIn('strings')
} else {

@@ -720,3 +739,3 @@ this.consume()

}
errorControlCharInString () {
errorControlCharIn (type) {
let displayCode = '\\u00'

@@ -728,3 +747,3 @@ if (this.char < 16) {

return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`))
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in ${type}, use ${displayCode} instead`))
}

@@ -745,3 +764,3 @@ recordMultiEscapeReplacement (replacement) {

if (this.char === CHAR_QUOT) {
return this.return()
return this.next(this.parseMultiEnd3)
} else {

@@ -752,2 +771,18 @@ this.state.buf += '""'

}
parseMultiEnd3 () {
if (this.char === CHAR_QUOT) {
this.state.buf += '"'
return this.next(this.parseMultiEnd4)
} else {
return this.returnNow()
}
}
parseMultiEnd4 () {
if (this.char === CHAR_QUOT) {
this.state.buf += '"'
return this.return()
} else {
return this.returnNow()
}
}
parseMultiEscape () {

@@ -1314,9 +1349,3 @@ if (this.char === CTRL_M || this.char === CTRL_J) {

recordInlineListValue (value) {
if (this.state.resultArr) {
const listType = this.state.resultArr[_contentType]
const valueType = tomlType(value)
if (listType !== valueType) {
throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`))
}
} else {
if (!this.state.resultArr) {
this.state.resultArr = InlineList(tomlType(value))

@@ -1384,3 +1413,3 @@ }

} else if (this.char === CHAR_COMMA) {
return this.next(this.parseInlineTable)
return this.next(this.parseInlineTablePostComma)
} else if (this.char === CHAR_RCUB) {

@@ -1392,4 +1421,17 @@ return this.goto(this.parseInlineTable)

}
parseInlineTablePostComma () {
if (this.char === CHAR_SP || this.char === CTRL_I) {
return null
} else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
throw this.error(new TomlError('Unterminated inline array'))
} else if (this.char === CHAR_COMMA) {
throw this.error(new TomlError('Empty elements in inline tables are not permitted'))
} else if (this.char === CHAR_RCUB) {
throw this.error(new TomlError('Trailing commas in inline tables are not permitted'))
} else {
return this.goto(this.parseInlineTable)
}
}
}
return TOMLParser
}
{
"name": "@iarna/toml",
"version": "2.2.5",
"version": "3.0.0",
"main": "toml.js",

@@ -15,3 +15,3 @@ "scripts": {

"setup-burntsushi-toml-suite": "[ -d test/burntsushi-toml-test ] || (git clone https://github.com/BurntSushi/toml-test test/burntsushi-toml-test; rimraf test/burntsushi-toml-test/.git/hooks/*); cd test/burntsushi-toml-test; git pull",
"setup-iarna-toml-suite": "[ -d test/spec-test ] || (git clone https://github.com/iarna/toml-spec-tests -b 0.5.0 test/spec-test; rimraf test/spec-test/.git/hooks/*); cd test/spec-test; git pull",
"setup-iarna-toml-suite": "[ -d test/spec-test ] || (git clone https://github.com/iarna/toml-spec-tests -b 1.0.0-rc.1 test/spec-test; rimraf test/spec-test/.git/hooks/*); cd test/spec-test; git pull",
"prepare": "npm run setup-burntsushi-toml-suite && npm run setup-iarna-toml-suite"

@@ -38,3 +38,3 @@ },

"@ltd/j-toml": "^0.5.107",
"@perl/qx": "^1.1.0",
"@perl/qx": "^1.0.2",
"@sgarciac/bombadil": "^2.3.0",

@@ -45,6 +45,6 @@ "ansi": "^0.3.1",

"fast-toml": "^0.5.4",
"funstream": "^4.2.0",
"glob": "^7.1.6",
"funstream": "^3.0.0",
"glob": "^7.1.2",
"js-yaml": "^3.13.1",
"rimraf": "^3.0.2",
"rimraf": "^2.6.2",
"tap": "^12.0.1",

@@ -51,0 +51,0 @@ "toml": "^3.0.0",

@@ -7,8 +7,16 @@ # @iarna/toml

# ** TOML 0.5.0 **
# ** TOML 1.0.0-rc.1 **
### TOML Spec Support
The most recent version as of 2018-07-26: [v0.5.0](https://github.com/mojombo/toml/blob/master/versions/en/toml-v0.5.0.md)
The most recent version as of 2019-04-21: [1.0.0-rc.1](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v1.0.0-rc.1.md)
### Other Versions
1.0.0-rc.1 parsers can load almost any TOML 0.4 and TOML 0.5 document, but
TOML 1.0.0-rc.1 docs are not always compatible with TOML 0.4 and TOML 0.5
parsers. If you're using this to generate TOML documents and you want an
older parser to be able to read them you may want to use the
[latest TOML 0.5 version of this module](https://www.npmjs.com/package/@iarna/toml/v/toml-0.5).
### Example

@@ -37,16 +45,10 @@

* See [TOML-SPEC-SUPPORT](https://shared.by.re-becca.org/misc/TOML-SPEC-SUPPORT.html)
for a comparison of which TOML features are supported by the various
Node.js TOML parsers.
* Support for TOML 1.0.0-rc.1!
* Highly correct! Careful adherence to spec.
* See [TOML-SPEC-SUPPORT](https://shared.by.re-becca.org/misc/TOML-SPEC-SUPPORT-v1.html) for a comparison of which TOML features
are supported by the various Node.js TOML parsers.
* Speedy! See benchmarks at end.
* BigInt support on Node 10!
* 100% test coverage.
* Fast parsing. It's as much as 100 times
faster than `toml` and 3 times faster than `toml-j0.4`. However a recent
newcomer [`@ltd/j-toml`](https://www.npmjs.com/package/@ltd/j-toml) has
appeared with 0.5 support and astoundingly fast parsing speeds for large
text blocks. All I can say is you'll have to test your specific work loads
if you want to know which of @iarna/toml and @ltd/j-toml is faster for
you, as we currently excell in different areas.
* Careful adherence to spec. Tests go beyond simple coverage.
* Smallest parser bundle (if you use `@iarna/toml/parse-string`).
* Small parser bundle (if you use `@iarna/toml/parse-string`).
* No deps.

@@ -159,7 +161,4 @@ * Detailed and easy to read error messages‼

Version 2 of this module supports TOML 0.5.0. Other modules currently
published to the npm registry support 0.4.0. 0.5.0 is mostly backwards
compatible with 0.4.0, but if you have need, you can install @iarna/toml@1
to get a version of this module that supports 0.4.0. Please see the
[CHANGELOG](CHANGELOG.md#2.0.0) for details on exactly whats changed.
Version 3 of this module supports TOML 1.0.0-rc.1. Please see the
[CHANGELOG](CHANGELOG.md#3.0.0) for details on exactly whats changed.

@@ -181,3 +180,3 @@ ## TOML we can't do

they are (with `isFloating`, `isDate`, `isTime` properties) and that
their ISO representation (via `toISOString`) is representative of their
their ISO representation (via `toISOString`) are representative of their
TOML value. They will correctly round trip if you pass them to

@@ -205,6 +204,7 @@ `TOML.stringify`.

The results below are from my desktop using Node 13.13.0. The library
versions tested were `@iarna/toml@2.2.4`, `toml-j0.4@1.1.1`, `toml@3.0.0`,
`@sgarciac/bombadil@2.3.0`, `@ltd/j-toml@0.5.107`, and `fast-toml@0.5.4`. The speed value is
megabytes-per-second that the parser can process of that document type.
Bigger is better. The percentage after average results is the margin of error.
versions tested were `@iarna/toml@3.0.0`, `toml-j0.4@1.1.1`, `toml@3.0.0`,
`@sgarciac/bombadil@2.3.0`, `@ltd/j-toml@0.5.107`, and `fast-toml@0.5.4`.
The speed value is megabytes-per-second that the parser can process of that
document type. Bigger is better. The percentage after average results is
the margin of error.

@@ -224,27 +224,28 @@ New here is fast-toml. fast-toml is very fast, for some datatypes, but it

| - | :---------: | :-------: | :--: | :----------------: | :---------: | :-------: |
| **Overall** | 28MB/sec<br><small>0.35%</small> | 6.5MB/sec<br><small>0.25%</small> | 0.2MB/sec<br><small>0.70%</small> | - | 35MB/sec<br><small>0.23%</small> | - |
| **Spec Example: v0.4.0** | 26MB/sec<br><small>0.37%</small> | 10MB/sec<br><small>0.27%</small> | 1MB/sec<br><small>0.42%</small> | 1.2MB/sec<br><small>0.95%</small> | 28MB/sec<br><small>0.31%</small> | - |
| **Spec Example: Hard Unicode** | 64MB/sec<br><small>0.59%</small> | 18MB/sec<br><small>0.12%</small> | 2MB/sec<br><small>0.20%</small> | 0.6MB/sec<br><small>0.53%</small> | 68MB/sec<br><small>0.31%</small> | 78MB/sec<br><small>0.28%</small> |
| **Types: Array, Inline** | 7.3MB/sec<br><small>0.60%</small> | 4MB/sec<br><small>0.16%</small> | 0.1MB/sec<br><small>0.91%</small> | 1.3MB/sec<br><small>0.81%</small> | 10MB/sec<br><small>0.35%</small> | 9MB/sec<br><small>0.16%</small> |
| **Types: Array** | 6.8MB/sec<br><small>0.19%</small> | 6.7MB/sec<br><small>0.15%</small> | 0.2MB/sec<br><small>0.79%</small> | 1.2MB/sec<br><small>0.93%</small> | 8.8MB/sec<br><small>0.47%</small> | 27MB/sec<br><small>0.21%</small> |
| **Types: Boolean,** | 21MB/sec<br><small>0.20%</small> | 9.4MB/sec<br><small>0.17%</small> | 0.2MB/sec<br><small>0.96%</small> | 1.8MB/sec<br><small>0.70%</small> | 16MB/sec<br><small>0.20%</small> | 8.4MB/sec<br><small>0.22%</small> |
| **Types: Datetime** | 18MB/sec<br><small>0.14%</small> | 11MB/sec<br><small>0.15%</small> | 0.3MB/sec<br><small>0.85%</small> | 1.6MB/sec<br><small>0.45%</small> | 9.8MB/sec<br><small>0.48%</small> | 6.5MB/sec<br><small>0.23%</small> |
| **Types: Float** | 8.8MB/sec<br><small>0.09%</small> | 5.9MB/sec<br><small>0.14%</small> | 0.2MB/sec<br><small>0.51%</small> | 2.1MB/sec<br><small>0.82%</small> | 14MB/sec<br><small>0.15%</small> | 7.9MB/sec<br><small>0.14%</small> |
| **Types: Int** | 5.9MB/sec<br><small>0.11%</small> | 4.5MB/sec<br><small>0.28%</small> | 0.1MB/sec<br><small>0.78%</small> | 1.5MB/sec<br><small>0.64%</small> | 10MB/sec<br><small>0.14%</small> | 8MB/sec<br><small>0.17%</small> |
| **Types: Literal String, 7 char** | 26MB/sec<br><small>0.29%</small> | 8.5MB/sec<br><small>0.32%</small> | 0.3MB/sec<br><small>0.84%</small> | 2.3MB/sec<br><small>1.02%</small> | 23MB/sec<br><small>0.15%</small> | 13MB/sec<br><small>0.15%</small> |
| **Types: Literal String, 92 char** | 46MB/sec<br><small>0.19%</small> | 11MB/sec<br><small>0.20%</small> | 0.3MB/sec<br><small>0.56%</small> | 12MB/sec<br><small>0.92%</small> | 101MB/sec<br><small>0.17%</small> | 75MB/sec<br><small>0.29%</small> |
| **Types: Literal String, Multiline, 1079 char** | 22MB/sec<br><small>0.42%</small> | 6.7MB/sec<br><small>0.55%</small> | 0.9MB/sec<br><small>0.78%</small> | 44MB/sec<br><small>1.00%</small> | 350MB/sec<br><small>0.16%</small> | 636MB/sec<br><small>0.16%</small> |
| **Types: Basic String, 7 char** | 25MB/sec<br><small>0.15%</small> | 7.3MB/sec<br><small>0.18%</small> | 0.2MB/sec<br><small>0.96%</small> | 2.2MB/sec<br><small>1.09%</small> | 14MB/sec<br><small>0.16%</small> | 12MB/sec<br><small>0.22%</small> |
| **Types: Basic String, 92 char** | 43MB/sec<br><small>0.30%</small> | 7.2MB/sec<br><small>0.16%</small> | 0.1MB/sec<br><small>4.04%</small> | 12MB/sec<br><small>1.33%</small> | 71MB/sec<br><small>0.19%</small> | 70MB/sec<br><small>0.23%</small> |
| **Types: Basic String, 1079 char** | 24MB/sec<br><small>0.45%</small> | 5.8MB/sec<br><small>0.17%</small> | 0.1MB/sec<br><small>3.64%</small> | 44MB/sec<br><small>1.05%</small> | 93MB/sec<br><small>0.29%</small> | 635MB/sec<br><small>0.28%</small> |
| **Types: Table, Inline** | 9.7MB/sec<br><small>0.10%</small> | 5.5MB/sec<br><small>0.22%</small> | 0.1MB/sec<br><small>0.87%</small> | 1.4MB/sec<br><small>1.18%</small> | 8.7MB/sec<br><small>0.60%</small> | 8.7MB/sec<br><small>0.22%</small> |
| **Types: Table** | 7.1MB/sec<br><small>0.14%</small> | 5.6MB/sec<br><small>0.42%</small> | 0.1MB/sec<br><small>0.65%</small> | 1.4MB/sec<br><small>1.11%</small> | 7.4MB/sec<br><small>0.70%</small> | 18MB/sec<br><small>0.20%</small> |
| **Scaling: Array, Inline, 1000 elements** | 40MB/sec<br><small>0.21%</small> | 2.4MB/sec<br><small>0.19%</small> | 0.1MB/sec<br><small>0.35%</small> | 1.6MB/sec<br><small>1.02%</small> | 17MB/sec<br><small>0.15%</small> | 32MB/sec<br><small>0.16%</small> |
| **Scaling: Array, Nested, 1000 deep** | 2MB/sec<br><small>0.15%</small> | 1.7MB/sec<br><small>0.26%</small> | 0.3MB/sec<br><small>0.58%</small> | - | 1.8MB/sec<br><small>0.74%</small> | 13MB/sec<br><small>0.20%</small> |
| **Scaling: Literal String, 40kb** | 61MB/sec<br><small>0.18%</small> | 10MB/sec<br><small>0.15%</small> | 3MB/sec<br><small>0.84%</small> | 12MB/sec<br><small>0.51%</small> | 551MB/sec<br><small>0.44%</small> | 19kMB/sec<br><small>0.19%</small> |
| **Scaling: Literal String, Multiline, 40kb** | 62MB/sec<br><small>0.16%</small> | 5MB/sec<br><small>0.45%</small> | 0.2MB/sec<br><small>1.70%</small> | 11MB/sec<br><small>0.74%</small> | 291MB/sec<br><small>0.24%</small> | 21kMB/sec<br><small>0.22%</small> |
| **Scaling: Basic String, Multiline, 40kb** | 62MB/sec<br><small>0.18%</small> | 5.8MB/sec<br><small>0.38%</small> | 2.9MB/sec<br><small>0.86%</small> | 11MB/sec<br><small>0.41%</small> | 949MB/sec<br><small>0.44%</small> | 26kMB/sec<br><small>0.16%</small> |
| **Scaling: Basic String, 40kb** | 59MB/sec<br><small>0.20%</small> | 6.3MB/sec<br><small>0.17%</small> | 0.2MB/sec<br><small>1.95%</small> | 12MB/sec<br><small>0.44%</small> | 508MB/sec<br><small>0.35%</small> | 18kMB/sec<br><small>0.15%</small> |
| **Scaling: Table, Inline, 1000 elements** | 28MB/sec<br><small>0.12%</small> | 8.2MB/sec<br><small>0.19%</small> | 0.3MB/sec<br><small>0.89%</small> | 2.3MB/sec<br><small>1.14%</small> | 5.3MB/sec<br><small>0.24%</small> | 13MB/sec<br><small>0.20%</small> |
| **Scaling: Table, Inline, Nested, 1000 deep** | 7.8MB/sec<br><small>0.28%</small> | 5MB/sec<br><small>0.20%</small> | 0.1MB/sec<br><small>0.84%</small> | - | 3.2MB/sec<br><small>0.52%</small> | 10MB/sec<br><small>0.23%</small> |
| **Overall** | 28MB/sec<br><small>0.55%</small> | - | - | - | - | - |
| **01-small-doc-mixed-type-inline-array** | 5.3MB/sec<br><small>0.48%</small> | - | - | - | - | 12MB/sec<br><small>0.13%</small> |
| **Spec Example: v0.4.0** | 25MB/sec<br><small>0.40%</small> | 9.9MB/sec<br><small>0.15%</small> | 0.9MB/sec<br><small>0.37%</small> | 1.3MB/sec<br><small>1.02%</small> | 28MB/sec<br><small>0.33%</small> | - |
| **Spec Example: Hard Unicode** | 63MB/sec<br><small>0.47%</small> | 17MB/sec<br><small>0.21%</small> | 2MB/sec<br><small>0.25%</small> | 0.6MB/sec<br><small>0.47%</small> | 65MB/sec<br><small>0.27%</small> | 79MB/sec<br><small>0.09%</small> |
| **Types: Array, Inline** | 7.2MB/sec<br><small>0.53%</small> | 4.1MB/sec<br><small>0.09%</small> | 0.1MB/sec<br><small>0.69%</small> | 1.4MB/sec<br><small>0.86%</small> | 10MB/sec<br><small>0.33%</small> | 9MB/sec<br><small>0.16%</small> |
| **Types: Array** | 6.8MB/sec<br><small>0.09%</small> | 6.8MB/sec<br><small>0.20%</small> | 0.2MB/sec<br><small>0.81%</small> | 1.3MB/sec<br><small>0.82%</small> | 8.9MB/sec<br><small>0.36%</small> | 29MB/sec<br><small>0.16%</small> |
| **Types: Boolean,** | 20MB/sec<br><small>0.22%</small> | 9.3MB/sec<br><small>0.29%</small> | 0.2MB/sec<br><small>0.91%</small> | 1.9MB/sec<br><small>0.85%</small> | 16MB/sec<br><small>0.29%</small> | 8.6MB/sec<br><small>0.22%</small> |
| **Types: Datetime** | 17MB/sec<br><small>0.09%</small> | 11MB/sec<br><small>0.17%</small> | 0.3MB/sec<br><small>0.75%</small> | 1.6MB/sec<br><small>0.42%</small> | 9.8MB/sec<br><small>0.40%</small> | 6.5MB/sec<br><small>0.11%</small> |
| **Types: Float** | 8.5MB/sec<br><small>0.29%</small> | 5.8MB/sec<br><small>0.33%</small> | 0.2MB/sec<br><small>0.91%</small> | 2.2MB/sec<br><small>0.91%</small> | 14MB/sec<br><small>0.25%</small> | 7.9MB/sec<br><small>0.33%</small> |
| **Types: Int** | 5.8MB/sec<br><small>0.13%</small> | 4.5MB/sec<br><small>0.14%</small> | 0.1MB/sec<br><small>0.63%</small> | 1.5MB/sec<br><small>0.73%</small> | 9.8MB/sec<br><small>0.14%</small> | 8.1MB/sec<br><small>0.16%</small> |
| **Types: Literal String, 7 char** | 25MB/sec<br><small>0.15%</small> | 8.3MB/sec<br><small>0.38%</small> | 0.2MB/sec<br><small>0.71%</small> | 2.3MB/sec<br><small>1.04%</small> | 23MB/sec<br><small>0.28%</small> | 14MB/sec<br><small>0.21%</small> |
| **Types: Literal String, 92 char** | 44MB/sec<br><small>0.23%</small> | 12MB/sec<br><small>0.14%</small> | 0.3MB/sec<br><small>0.63%</small> | 13MB/sec<br><small>1.12%</small> | 100MB/sec<br><small>0.14%</small> | 77MB/sec<br><small>0.15%</small> |
| **Types: Literal String, Multiline, 1079 char** | 23MB/sec<br><small>0.35%</small> | 7.2MB/sec<br><small>0.34%</small> | 0.9MB/sec<br><small>0.86%</small> | 47MB/sec<br><small>1.07%</small> | 380MB/sec<br><small>0.13%</small> | 641MB/sec<br><small>0.14%</small> |
| **Types: Basic String, 7 char** | 25MB/sec<br><small>0.09%</small> | 7MB/sec<br><small>0.08%</small> | 0.2MB/sec<br><small>0.82%</small> | 2.3MB/sec<br><small>1.02%</small> | 15MB/sec<br><small>0.12%</small> | 13MB/sec<br><small>0.14%</small> |
| **Types: Basic String, 92 char** | 44MB/sec<br><small>0.15%</small> | 8MB/sec<br><small>0.39%</small> | 0.1MB/sec<br><small>1.52%</small> | 12MB/sec<br><small>1.53%</small> | 70MB/sec<br><small>0.17%</small> | 71MB/sec<br><small>0.16%</small> |
| **Types: Basic String, 1079 char** | 24MB/sec<br><small>0.36%</small> | 5.7MB/sec<br><small>0.12%</small> | 0.1MB/sec<br><small>3.65%</small> | 42MB/sec<br><small>1.67%</small> | 93MB/sec<br><small>0.13%</small> | 617MB/sec<br><small>0.14%</small> |
| **Types: Table, Inline** | 9.4MB/sec<br><small>0.21%</small> | 5.2MB/sec<br><small>0.23%</small> | 0.1MB/sec<br><small>1.18%</small> | 1.4MB/sec<br><small>1.20%</small> | 8.5MB/sec<br><small>0.68%</small> | 8.7MB/sec<br><small>0.30%</small> |
| **Types: Table** | 6.8MB/sec<br><small>0.13%</small> | 5.5MB/sec<br><small>0.22%</small> | 0.1MB/sec<br><small>1.10%</small> | 1.5MB/sec<br><small>1.05%</small> | 7.3MB/sec<br><small>0.54%</small> | 19MB/sec<br><small>0.21%</small> |
| **Scaling: Array, Inline, 1000 elements** | 40MB/sec<br><small>0.27%</small> | 2.4MB/sec<br><small>0.20%</small> | 0.1MB/sec<br><small>1.90%</small> | 1.6MB/sec<br><small>1.14%</small> | 18MB/sec<br><small>0.16%</small> | 32MB/sec<br><small>0.12%</small> |
| **Scaling: Array, Nested, 1000 deep** | 2MB/sec<br><small>0.17%</small> | 1.6MB/sec<br><small>0.09%</small> | 0.3MB/sec<br><small>0.62%</small> | - | 1.8MB/sec<br><small>0.80%</small> | 13MB/sec<br><small>0.19%</small> |
| **Scaling: Literal String, 40kb** | 59MB/sec<br><small>0.26%</small> | 10MB/sec<br><small>0.14%</small> | 3MB/sec<br><small>0.91%</small> | 13MB/sec<br><small>0.40%</small> | 479MB/sec<br><small>0.25%</small> | 19kMB/sec<br><small>0.20%</small> |
| **Scaling: Literal String, Multiline, 40kb** | 61MB/sec<br><small>0.23%</small> | 5.3MB/sec<br><small>0.30%</small> | 0.2MB/sec<br><small>1.78%</small> | 12MB/sec<br><small>0.55%</small> | 276MB/sec<br><small>0.16%</small> | 21kMB/sec<br><small>0.10%</small> |
| **Scaling: Basic String, Multiline, 40kb** | 61MB/sec<br><small>0.21%</small> | 6MB/sec<br><small>0.40%</small> | 2.8MB/sec<br><small>0.75%</small> | 12MB/sec<br><small>0.60%</small> | 1kMB/sec<br><small>0.13%</small> | 27kMB/sec<br><small>0.14%</small> |
| **Scaling: Basic String, 40kb** | 60MB/sec<br><small>0.13%</small> | 6.6MB/sec<br><small>0.13%</small> | 0.2MB/sec<br><small>1.67%</small> | 13MB/sec<br><small>0.30%</small> | 504MB/sec<br><small>0.26%</small> | 19kMB/sec<br><small>0.22%</small> |
| **Scaling: Table, Inline, 1000 elements** | 26MB/sec<br><small>0.17%</small> | 7.3MB/sec<br><small>0.83%</small> | 0.3MB/sec<br><small>0.95%</small> | 2.5MB/sec<br><small>1.24%</small> | 5.4MB/sec<br><small>0.22%</small> | 13MB/sec<br><small>0.22%</small> |
| **Scaling: Table, Inline, Nested, 1000 deep** | 8MB/sec<br><small>0.10%</small> | 5.2MB/sec<br><small>0.25%</small> | 0.1MB/sec<br><small>0.45%</small> | - | 3.1MB/sec<br><small>0.58%</small> | 10MB/sec<br><small>0.19%</small> |

@@ -258,6 +259,3 @@ ## Tests

and YAML files. You can find those files here:
[spec-test](https://github.com/iarna/iarna-toml/blob/latest/test/spec-test/).
A number of examples of invalid Unicode were also written, but are difficult
to make use of in Node.js where Unicode errors are silently hidden. You can
find those here: [spec-test-disabled](https://github.com/iarna/iarna-toml/blob/latest/test/spec-test-disabled/).
[spec-test](https://github.com/iarna/toml-spec-test/).

@@ -291,3 +289,3 @@ Further tests were written to increase coverage to 100%, these may be more

Tests for the parsers debugging mode live in [test/devel.js](https://github.com/iarna/iarna-toml/blob/latest/test/devel.js).
Tests for the parser's debugging mode live in [test/devel.js](https://github.com/iarna/iarna-toml/blob/latest/test/devel.js).

@@ -294,0 +292,0 @@ And finally, many more stringification tests were borrowed from [@othiym23](https://github.com/othiym23)'s

@@ -21,6 +21,2 @@ 'use strict'

function arrayOneTypeError () {
return new Error("Array values can't have mixed types")
}
function getInlineKeys (obj) {

@@ -47,8 +43,8 @@ return Object.keys(obj).filter(key => isInline(obj[key]))

obj = toJSON(obj)
var inlineKeys
var complexKeys
let inlineKeys
let complexKeys
inlineKeys = getInlineKeys(obj)
complexKeys = getComplexKeys(obj)
var result = []
var inlineIndent = indent || ''
const result = []
const inlineIndent = indent || ''
inlineKeys.forEach(key => {

@@ -61,3 +57,3 @@ var type = tomlType(obj[key])

if (result.length > 0) result.push('')
var complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
const complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
complexKeys.forEach(key => {

@@ -114,3 +110,3 @@ result.push(stringifyComplex(prefix, complexIndent, key, obj[key]))

function stringifyKey (key) {
var keyStr = String(key)
const keyStr = String(key)
if (/^[-A-Za-z0-9_]+$/.test(keyStr)) {

@@ -211,5 +207,3 @@ return keyStr

}
var chunks = String(value).split('.')
var int = chunks[0]
var dec = chunks[1] || 0
const [int, dec] = String(value).split('.')
return stringifyInteger(int) + '.' + dec

@@ -226,25 +220,6 @@ }

function isNumber (type) {
return type === 'float' || type === 'integer'
}
function arrayType (values) {
var contentType = tomlType(values[0])
if (values.every(_ => tomlType(_) === contentType)) return contentType
// mixed integer/float, emit as floats
if (values.every(_ => isNumber(tomlType(_)))) return 'float'
return 'mixed'
}
function validateArray (values) {
const type = arrayType(values)
if (type === 'mixed') {
throw arrayOneTypeError()
}
return type
}
function stringifyInlineArray (values) {
values = toJSON(values)
const type = validateArray(values)
var result = '['
var stringified = values.map(_ => stringifyInline(_, type))
let result = '['
const stringified = values.map(_ => stringifyInline(_))
if (stringified.join(', ').length > 60 || /\n/.test(stringified)) {

@@ -260,3 +235,3 @@ result += '\n ' + stringified.join(',\n ') + '\n'

value = toJSON(value)
var result = []
const result = []
Object.keys(value).forEach(key => {

@@ -269,3 +244,3 @@ result.push(stringifyKey(key) + ' = ' + stringifyAnyInline(value[key], false))

function stringifyComplex (prefix, indent, key, value) {
var valueType = tomlType(value)
const valueType = tomlType(value)
/* istanbul ignore else */

@@ -283,8 +258,7 @@ if (valueType === 'array') {

values = toJSON(values)
validateArray(values)
var firstValueType = tomlType(values[0])
const firstValueType = tomlType(values[0])
/* istanbul ignore if */
if (firstValueType !== 'table') throw typeError(firstValueType)
var fullKey = prefix + stringifyKey(key)
var result = ''
const fullKey = prefix + stringifyKey(key)
let result = ''
values.forEach(table => {

@@ -299,4 +273,4 @@ if (result.length > 0) result += '\n'

function stringifyComplexTable (prefix, indent, key, value) {
var fullKey = prefix + stringifyKey(key)
var result = ''
const fullKey = prefix + stringifyKey(key)
let result = ''
if (getInlineKeys(value).length > 0) {

@@ -303,0 +277,0 @@ result += indent + '[' + fullKey + ']\n'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc