NPM Star
Collections
  1. Home
  2. Compare
  3. toml vs yaml
NPM Compare

Compare NPM packages statistics, trends, and features

CollectionsVS Code extensionChrome extensionTermsPrivacyLinkTreeIndiehackersBig Frontendqiuyumi

Unable to load comparison data. Please try again later.

TOML Parser for Node.js

CI

If you haven't heard of TOML, well you're just missing out. Go check it out now. Back? Good.

TOML Spec Support

toml-node supports TOML v1.1.0, scoring 673/680 (99.0%) on the official toml-test compliance suite:

| | Pass | Total | Rate | |---|---|---|---| | Valid tests | 213 | 214 | 99.5% | | Invalid tests | 460 | 466 | 98.7% | | Total | 673 | 680 | 99.0% |

The 7 remaining failures are inherent JavaScript platform limitations shared by all JS TOML parsers:

  • 1 valid test: 64-bit integer precision (Number can't represent values beyond Number.MAX_SAFE_INTEGER)
  • 6 invalid tests: UTF-8 encoding validation (Node.js handles UTF-8 decoding at the engine level before the parser sees the data)

Feature Support

  • Strings: basic, literal, multiline, all escape sequences (\uXXXX, \UXXXXXXXX, \xHH, \e)
  • Integers: decimal, hexadecimal (0xDEADBEEF), octal (0o755), binary (0b11010110)
  • Floats: decimal, scientific notation, inf, -inf, nan
  • Booleans: true, false
  • Dates/Times: offset date-time, local date-time, local date, local time; seconds optional
  • Arrays: mixed types allowed
  • Tables: standard, inline (with dotted/quoted keys, newlines, trailing commas), array of tables
  • Keys: bare, quoted, dotted (fruit.apple.color = "red")
  • Comments: # line comments

Installation

npm install toml

Requires Node.js 20 or later. Zero runtime dependencies.

Usage

const toml = require('toml'); const data = toml.parse(someTomlString);

toml.parse throws an exception on parse errors with line and column properties:

try { toml.parse(someBadToml); } catch (e) { console.error(`Parsing error on line ${e.line}, column ${e.column}: ${e.message}`); }

Date/Time Values

Offset date-times are returned as JavaScript Date objects. Local date-times, local dates, and local times are returned as strings since they have no timezone information and can't be losslessly represented as Date:

const data = toml.parse(` odt = 1979-05-27T07:32:00Z # Date object ldt = 1979-05-27T07:32:00 # string: "1979-05-27T07:32:00" ld = 1979-05-27 # string: "1979-05-27" lt = 07:32:00 # string: "07:32:00" `); data.odt instanceof Date // true typeof data.ldt // "string" typeof data.ld // "string" typeof data.lt // "string"

Special Float Values

inf and nan are returned as JavaScript Infinity and NaN:

const data = toml.parse(` pos_inf = inf neg_inf = -inf not_a_number = nan `); data.pos_inf === Infinity // true data.neg_inf === -Infinity // true Number.isNaN(data.not_a_number) // true

Requiring .toml Files

You can use the toml-require package to require() your .toml files with Node.js.

Building & Testing

toml-node uses the Peggy parser generator (successor to PEG.js).

npm install
npm run build
npm test
npm run test:spec           # run toml-test compliance suite
npm run test:spec:failures  # show failure details

Changes to src/toml.pegjs require a rebuild with npm run build.

License

toml-node is licensed under the MIT license agreement. See the LICENSE file for more information.

YAML <a href="https://www.npmjs.com/package/yaml"><img align="right" src="https://badge.fury.io/js/yaml.svg" title="npm package" /></a>

yaml is a definitive library for YAML, the human friendly data serialization standard. This library:

  • Supports both YAML 1.1 and YAML 1.2 and all common data schemas,
  • Passes all of the yaml-test-suite tests,
  • Can accept any string as input without throwing, parsing as much YAML out of it as it can, and
  • Supports parsing, modifying, and writing YAML comments and blank lines.

The library is released under the ISC open source license, and the code is available on GitHub. It has no external dependencies and runs on Node.js as well as modern browsers.

For the purposes of versioning, any changes that break any of the documented endpoints or APIs will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed).

The minimum supported TypeScript version of the included typings is 3.9; for use in earlier versions you may need to set skipLibCheck: true in your config. This requirement may be updated between minor versions of the library.

For more information, see the project's documentation site: eemeli.org/yaml

For build instructions and contribution guidelines, see docs/CONTRIBUTING.md.

To install:

npm install yaml # or deno add jsr:@eemeli/yaml

Note: These docs are for yaml@2. For v1, see the v1.10.0 tag for the source and eemeli.org/yaml/v1 for the documentation.

API Overview

The API provided by yaml has three layers, depending on how deep you need to go: Parse & Stringify, Documents, and the underlying Lexer/Parser/Composer. The first has the simplest API and "just works", the second gets you all the bells and whistles supported by the library along with a decent AST, and the third lets you get progressively closer to YAML source, if that's your thing.

A command-line tool is also included.

Parse & Stringify

import { parse, stringify } from 'yaml'
  • parse(str, reviver?, options?): value
  • stringify(value, replacer?, options?): string

Documents

<!-- prettier-ignore -->
import { Document, isDocument, parseAllDocuments, parseDocument } from 'yaml'
  • Document
    • constructor(value, replacer?, options?)
    • #contents
    • #directives
    • #errors
    • #warnings
  • isDocument(foo): boolean
  • parseAllDocuments(str, options?): Document[]
  • parseDocument(str, options?): Document

Content Nodes

<!-- prettier-ignore -->
import { isAlias, isCollection, isMap, isNode, isPair, isScalar, isSeq, Scalar, visit, visitAsync, YAMLMap, YAMLSeq } from 'yaml'
  • isAlias(foo): boolean
  • isCollection(foo): boolean
  • isMap(foo): boolean
  • isNode(foo): boolean
  • isPair(foo): boolean
  • isScalar(foo): boolean
  • isSeq(foo): boolean
  • new Scalar(value)
  • new YAMLMap()
  • new YAMLSeq()
  • doc.createAlias(node, name?): Alias
  • doc.createNode(value, options?): Node
  • doc.createPair(key, value): Pair
  • visit(node, visitor)
  • visitAsync(node, visitor)

Parsing YAML

import { Composer, Lexer, Parser } from 'yaml'
  • new Lexer().lex(src)
  • new Parser(onNewLine?).parse(src)
  • new Composer(options?).compose(tokens)

YAML.parse

# file.yml YAML: - A human-readable data serialization language - https://en.wikipedia.org/wiki/YAML yaml: - A complete JavaScript implementation - https://www.npmjs.com/package/yaml
import fs from 'fs' import YAML from 'yaml' YAML.parse('3.14159') // 3.14159 YAML.parse('[ true, false, maybe, null ]\n') // [ true, false, 'maybe', null ] const file = fs.readFileSync('./file.yml', 'utf8') YAML.parse(file) // { YAML: // [ 'A human-readable data serialization language', // 'https://en.wikipedia.org/wiki/YAML' ], // yaml: // [ 'A complete JavaScript implementation', // 'https://www.npmjs.com/package/yaml' ] }

YAML.stringify

import YAML from 'yaml' YAML.stringify(3.14159) // '3.14159\n' YAML.stringify([true, false, 'maybe', null]) // `- true // - false // - maybe // - null // ` YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' }) // `number: 3 // plain: string // block: | // two // lines // `

Browser testing provided by:

<a href="https://www.browserstack.com/open-source"> <img width=200 src="https://eemeli.org/yaml/images/browserstack.svg" alt="BrowserStack" /> </a>

Dependencies Comparison

toml

Dependencies

Dev Dependencies

peggy^5.1.0

Peer Dependencies

yaml

Dependencies

Dev Dependencies

@babel/core^7.12.10
@babel/plugin-transform-typescript^7.12.17
@babel/preset-env^7.12.11
@eslint/js^9.9.1
@rollup/plugin-babel^6.0.3
@rollup/plugin-replace^6.0.3
@rollup/plugin-typescript^12.1.1
@types/jest^29.2.4
@types/node^20.11.20
babel-jest^29.0.1
eslint^9.9.1
eslint-config-prettier^10.1.8
fast-check^2.12.0
jest^29.0.1
jest-resolve^29.7.0
jest-ts-webcompat-resolver^1.0.0
prettier^3.0.2
rollup^4.12.0
tslib^2.8.1
typescript^5.7.2
typescript-eslint^8.4.0

Peer Dependencies

StarsIssuesVersionUpdatedⓘLast publish dateCreatedⓘPackage creation dateSizeⓘMinified + Gzipped size
T
toml
323174.1.12 months ago13 years agoinstall size 7.4 KB
Y
yaml
1,672352.9.0a month ago15 years agoinstall size 30.5 KB

Who's Using These Packages

toml

doesitarm
doesitarm

🦾 A list of reported app support for Apple Silicon as well as Apple M4 and M3 Ultra Macs

Cnblogs-Theme-SimpleMemory
Cnblogs-Theme-SimpleMemory

🍭 Cnblogs theme _ Basic theme : SimpleMemory

ogs
ogs

DO NOT USE THIS REPO! Migrated to https://gitlab.opengeosys.org/ogs/ogs!

Dependency
Dependency
eslint-online-playground
eslint-online-playground

ESLint Online Playground

yaml

artillery
artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.

obsidian-tasks
obsidian-tasks

Task management for the Obsidian knowledge base.

dumb-password-rules
dumb-password-rules

A compilation of sites with dumb password rules.

fabrica-dev-kit
fabrica-dev-kit

A toolkit for faster, smoother WordPress 5 development

tryhackme-ctf
tryhackme-ctf

TryHackMe CTFs writeups, notes, drafts, scrabbles, files and solutions.