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

TOML vs YAML: Configuration File Format Parsers

Both packages help developers read and write configuration files in different formats. TOML and YAML are popular formats for storing settings and configuration data, similar to JSON but with different syntax styles. These packages allow you to convert these configuration files into JavaScript objects that your code can use, making it easier to manage application settings.

Configuration Parsersconfigurationparserfile formatsettingsdata

Unable to load comparison data. Please try again later.

Similar Packages

js-yaml

100%

A very popular JavaScript package that lets you read and write YAML files. It's fast, easy to use, and supports all major YAML features like nested objects and arrays.

This is the most widely used YAML parser in the JavaScript ecosystem. It's battle-tested, well-documented, and used by major frameworks like Vue and Next.js

Data Format Parser

@iarna/toml

100%

A complete TOML parser and writer that fully supports the TOML spec. It makes working with TOML files as simple as working with JSON.

This is considered the best TOML parser for JavaScript. It's actively maintained and has excellent TypeScript support

Data Format Parser

yaml-loader

80%

A webpack loader that helps you import YAML files directly into your JavaScript code. Perfect for when you're working with webpack-based projects.

Great for projects that use webpack and need to work with YAML files, especially in React or Vue applications

Build Tool Integration

json5

70%

A package that adds useful features to JSON like comments, trailing commas, and single quotes. It's like JSON but more friendly for humans to write.

While not YAML or TOML, it's a great alternative when you want something simpler than YAML but more flexible than JSON

Data Format Parser

parse-json

60%

A simple package that makes parsing JSON safer and provides better error messages. It's like JSON.parse but with better error handling.

While it's for JSON, it's often used alongside YAML and TOML parsers when working with different config file formats

Data Format Parser

TOML Parser for Node.js

Build Status

NPM

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 version 0.4.0 the TOML spec as specified by mojombo/toml@v0.4.0

Installation

toml-node is available via npm.

npm install toml

toml-node also works with browser module bundlers like Browserify and webpack.

Usage

Standalone

Say you have some awesome TOML in a variable called someTomlString. Maybe it came from the web; maybe it came from a file; wherever it came from, it came asynchronously! Let's turn that sucker into a JavaScript object.

var toml = require('toml'); var data = toml.parse(someTomlString); console.dir(data);

toml.parse throws an exception in the case of a parsing error; such exceptions have a line and column property on them to help identify the offending text.

try { toml.parse(someCrazyKnuckleHeadedTrblToml); } catch (e) { console.error("Parsing error on line " + e.line + ", column " + e.column + ": " + e.message); }

Streaming

As of toml-node version 1.0, the streaming interface has been removed. Instead, use a module like concat-stream:

var toml = require('toml'); var concat = require('concat-stream'); var fs = require('fs'); fs.createReadStream('tomlFile.toml', 'utf8').pipe(concat(function(data) { var parsed = toml.parse(data); }));

Thanks @ForbesLindesay for the suggestion.

Requiring with Node.js

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

Live Demo

You can experiment with TOML online at http://binarymuse.github.io/toml-node/, which uses the latest version of this library.

Building & Testing

toml-node uses the PEG.js parser generator.

npm install
npm run build
npm test

Any changes to src/toml.peg requires a regeneration of the parser with npm run build.

toml-node is tested on Travis CI and is tested against:

  • Node 0.10
  • Node 0.12
  • Latest stable io.js

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

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.

The development and maintenance of this library is sponsored by:

<p align="center" width="100%"> <a href="https://www.scipress.io/" ><img width="150" align="top" src="https://eemeli.org/yaml/images/scipress.svg" alt="Scipress" /></a> &nbsp; &nbsp; <a href="https://manifest.build/" ><img width="150" align="top" src="https://eemeli.org/yaml/images/manifest.svg" alt="Manifest" /></a> </p>

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

jshint*
nodeunit~0.9.0
pegjs~0.8.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^5.0.2
@rollup/plugin-typescript^12.1.1
@types/jest^29.2.4
@types/node^20.11.20
babel-jest^29.0.1
cross-env^7.0.3
eslint^9.9.1
eslint-config-prettier^9.0.0
fast-check^2.12.0
jest^29.0.1
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
310223.0.02 years ago12 years agoinstall size 6.0 KB
Y
yaml
1,475202.8.0a month ago14 years agoinstall size 30.8 KB

Who's Using These Packages

toml

metalsmith
metalsmith

An extremely simple, pluggable static site generator for Node.js

CYFS
CYFS

CYFS is the next-generation technology to build real Web3 by upgrading the basic protocol of Web (TCP/IP+DNS+HTTP),is short for CYberFileSystem. https://www.cyfs.com/, cyfs://cyfs/index_en.html.

eslint-online-playground
eslint-online-playground

ESLint Online Playground

common-shared
common-shared

Includes common files used across different types of common file repositories (e.g. Go, Python, TypeScript, Go, more..)

mtx
mtx

mtx

yaml

hound
hound

Automated code review for GitHub pull requests.

fabrica-dev-kit
fabrica-dev-kit

A toolkit for faster, smoother WordPress 5 development

rails-templates
rails-templates

Our optimized Rails templates used in our projects

pola-web
pola-web

Pola pomoże Ci odnaleźć polskie wyroby. Zabierając Polę na zakupy odnajdujesz produkty “z duszą” i wspierasz polską gospodarkę.

sonarqube-webapp
sonarqube-webapp

SonarQube Community Build Web App