Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: build as cjs package #18

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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