Skip to content

Commit

Permalink
Merge pull request #18 from squirrelchat/chore/cjs
Browse files Browse the repository at this point in the history
chore: build as cjs package
  • Loading branch information
cyyynthia committed May 15, 2024
2 parents 38fb814 + acfd65b commit 91006d3
Show file tree
Hide file tree
Showing 23 changed files with 875 additions and 723 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const toml = stringify(parsed)
console.log(toml)
```

Alternatively, if you prefer something similar to the JSON global, you can import the library as follows
```js
import TOML from 'smol-toml'

TOML.stringify({ ... })
```

A few notes on the `stringify` function:
- `undefined` and `null` values on objects are ignored (does not produce a key/value).
- `undefined` and `null` values in arrays are **rejected**.
Expand Down Expand Up @@ -91,10 +98,11 @@ const localTime = TomlDate.wrapAsLocalTime(jsDate)
## Performance
A note on these performance numbers: in some highly synthetic tests, other parsers such as `fast-toml` greatly
outperform other parsers, mostly due to their lack of compliance with the spec. For example, to parse a string,
`fast-toml` skips the entire string while `smol-toml` does validate the string, costing a fair chair of performance.
`fast-toml` skips the entire string while `smol-toml` does validate the string, costing a fair share of performance.

The ~5MB test file used for benchmark here is filled with random data which attempts to be close-ish to reality. The
idea is to have a file relatively close to a real-world application.
The ~5MB test file used for benchmark here is filled with random data which attempts to be close-ish to reality in
terms of structure. The idea is to have a file relatively close to a real-world application, with moderately sized
strings etc.

The large TOML generator can be found [here](https://gist.github.com/cyyynthia/e77c744cb6494dabe37d0182506526b9)

Expand Down Expand Up @@ -171,7 +179,7 @@ I initially reported this to the library author, but the author decided to
- b) [delete the issue](https://github.com/huan231/toml-nodejs/issues/12) when pointed out links to the NodeJS
documentation about the flag removal and standard resolution algorithm.

For the reference anyways, `toml-nodejs` (with proper imports) is ~8x slower on both parse benchmark with:
For the reference anyway, `toml-nodejs` (with proper imports) is ~8x slower on both parse benchmark with:
- spec example: 7,543.47 op/s
- 5mb mixed: 0.7006 op/s
</details>
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{
"name": "smol-toml",
"version": "1.1.4",
"version": "1.2.0",
"keywords": [
"toml",
"parser",
"serializer"
],
"description": "A small, fast, and correct TOML parser/serializer",
"repository": "git@github.com:squirrelchat/smol-toml.git",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/squirrelchat/smol-toml.git"
},
"author": "Cynthia <cyyynthia@borkenware.com>",
"license": "BSD-3-Clause",
"type": "module",
"engines": {
"node": ">= 18",
"pnpm": ">= 8"
"pnpm": ">= 9"
},
"scripts": {
"build": "tsc",
Expand All @@ -24,13 +26,13 @@
"devDependencies": {
"@iarna/toml": "3.0.0",
"@ltd/j-toml": "^1.38.0",
"@tsconfig/node-lts": "^20.1.1",
"@tsconfig/strictest": "^2.0.2",
"@types/node": "^20.11.5",
"@vitest/ui": "^1.2.1",
"@tsconfig/node-lts": "^20.1.3",
"@tsconfig/strictest": "^2.0.5",
"@types/node": "^20.12.11",
"@vitest/ui": "^1.6.0",
"fast-toml": "^0.5.4",
"typescript": "^5.3.3",
"vitest": "^1.2.1"
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"exports": {
".": {
Expand Down
Loading

0 comments on commit 91006d3

Please sign in to comment.