npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markty-toml

v0.1.1

Published

Nano TOML parser for Javascript.

Downloads

2,639

Readme

npm npm bundle size

:microscope: Nano implementation of TOML using Markty. 10x faster, 10x smaller :)

Demo

:eyes: Try the live converter here :eyes:

Quick start

For Node

npm install markty-toml

var toml = require('markty-toml')
// or using ES6:
import toml from 'markty-toml'

const someTOML = `
key = "value"

[deeply.nested.key]
secret = "Shhhhh"
`

console.log( toml(someTOML) )

// > prints:
// {
//     "key" : "value",
//     "deeply": {
//         "nested": {
//             "key": {
//                 "secret" : "Shhhhh"
//             }
//         }
//     }
// }

In-Browser

Find latest version here.

To get the umd version:

  1. Observe the URL here and see the latest version used after @ like @0.1.1.
  2. Just modify the URL to get something like this: https://unpkg.com/[email protected]/dist/martytoml.umd.js

Then just import it normally :

<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/martytoml.umd.js"></script>

Then the exported name is marktytoml(), so you can just:

<script>
var someTOML = 'key = "value"\n[deeply.nested.key]\nsecret = "Shhhhh"';
console.log( marktytoml(someTOML) )
</script>

// > prints:
// {
//     "key" : "value",
//     "deeply": {
//         "nested": {
//             "key": {
//                 "secret" : "Shhhhh"
//             }
//         }
//     }
// }

FEATURES

  • :microscope: Ridiculously SMALL:: 100 LOC, 1kb gzipped

  • :zap: Blazing fast :zap: see benchmarks

  • Use any of colon or equal sign: key : value works the same as key = value

  • Single-line comments: # this = comment

  • Single-line text withOUT double-quotes: key = single line without double-quotes allowed

  • String literals: winpath = '''C:\\Users\\nodejs\\templates'''

  • Multi-line text with double-quotes: key = "Multilined paragraphs with line breaks like this \n\n\n should be enclosed with double-quotes"

  • Basic native data types (should not be enclosed by double-quotes):

    • [x] strings like hello world
    • [x] integers like 1, 2, 3...
    • [x] float like 3.14
    • [x] boolean like true, false
    • [x] signed numbers like +27, -23
    • [x] infinity like +inf, inf, -inf
    • [x] hexadecimals like 0xDEADBEEF
    • [x] octals like 0o01234567, 0o755
    • [x] binaries like 0b11010110
    • [x] dates like 1979-05-27T00:32:00-07:00, 1979-05-27
  • Complex objects objects as value:

    • [x] array of values like stuff = ["one", "two", "three"]
    • [x] array of arrays like stuff = [[1,2], ["a","b"]]
    • [x] inline tables like stuff = {"key" : "value"}
  • Tables:

    [sub.sub]
    key = value
  • Array of tables:

    [[sub.sub]]
    key = value1
    
    [[sub.sub]]
    key = value2
  • Spaced keys when surrounded by double quotes like "spaced key here" = value

Example

string = hello I do NOT need double quotes

array = ["I", "still", "need", "double-quotes", "except for", 1, true, 3.14, ":)"]

other : hey look ! I can have a colon instead of an equal sign

sentence = "this is a long sentence
with line breaks
one here
and another here
so I need double quotes"

This will correctly parse to :

{
    "string" : "hello I do NOT need double quotes",
    "array" : ["I", "still", "need", "double-quotes", "except for", 1, true, 3.14, ":)"],
    "other" : "hey look ! I can have a colon instead of an equal sign",
    "sentence": "this is a long sentence\nwith line breaks\none here\nand another here\nso I need double quotes"
}

When should you use marktyTOML over other libs (or when you should NOT)

  • :baby: Even though a lot of tests have been implemented, I will be slow to patch issues if any... so check if your use case match the tests before anything.
  • Not TOML v0.5 compliant and not meant to be. For instance, here are UNsupported specs:
    • There is no errors mechanism to print from.
    • Handling colons : as key/value separator is not allowed in TOML v0.5 (only = supported)
    • Handling strings without " is not allowed in TOML v0.5 (strings must be enclosed by ")
  • markty-TOML considers any TOML source like a database log:
    • when two identical nodes are set, the last one REPLACES the first: TOML sources are treated like a list of updates which AFTER PARSING returns a final state. This clearly goes against official TOML specs which aims to parse a given source as a final database state: thus two identical nodes would throw an error for the whole source.

Benchmarks

| Test | Observations | markty-TOML | node-toml | |:-----|:-------------|-------------:|---------------:| | gzipped size | | 1.086 b | 9.000 b | | v0.5 compliant ? | | :heavy_multiplication_x: | :heavy_check_mark: | | Parsing tests: | | simple_kv | link to bench | 148,008 ops/s | 15,991 ops/s | | simple_block | link to bench | 140.563 ops/s | 13.311 ops/s | | classic_config | link to bench | 19.358 ops/s | 395 ops/s |