CommonJS, ESModule, INI, JSON, JSON5, TOML, YAML data loader, parser and stringifier

CommonJS, ESModule, INI, JSON, JSON5, TOML, YAML data loader, parser and stringifier

Demo

demo-screenshot.jpg

Source in ./ui

Platforms

Node, Web, Deno

Install

npm i @grossacasacs/left-phalange

Usage

// Node
import {parse, load, loadAsync, stringify, supportedExtensions} from '@grossacasacs/left-phalange'
// Web
import {parse, stringify} from '@grossacasacs/left-phalange' // should resolve to /dist/browser.es.js
// Deno
import {parse, stringify, load, loadAsync} from 'https://unpkg.com/@grossacasacs/left-phalange/dist/deno.es.js'

load(file[, options])

Loading from a file

  • file
    • Data file path to load
  • options
    • Optional
    • Type Object | String
    • Default {}
  • options(String)
    • options.type
  • options.type
    • Data type of file
    • Should be one of cjs, esm, ini, js, json, json5, toml, yaml

examples:

load('path/to/data')

load('path/to/data.json')

load('path/to/data', 'yaml')

load('path/to/data', {type: 'toml'})

loadAsync(file[, options])

Promise version of load

parse(string[, options])

Parsing from a string

  • string
    • type: String
    • string to parse
  • options
    • Optional
    • Type Object | String
    • Default {}
  • options(String)
    • options.type
  • options.type
    • Data type of string
    • Default yaml
    • Should be one of ini, json, json5, toml, yaml

examples:

parse('{"left": "phalange"}')

parse('{"left": "phalange"}', 'json')

parse('left = "phalange"', {type: 'toml'})

stringify(data[, options])

Creating a string from an object

  • data
    • Data to stringify
  • options
    • Optional
    • Type Object | String | Boolean
    • Default {}
  • options(String)
    • options.type
  • options(Boolean)
    • options.pretty
  • options.type
    • Data type of string
    • Default json
    • Should be one of cjs, esm, ini, json, json5
  • options.pretty
    • Pretty output
    • Default false

examples:

stringify({left: 'phalange'})
// {"left": "phalange"}

stringify({left: 'phalange'}, 'toml')
// left = "phalange"

stringify({left: 'phalange'}, true)
// {
//   "left": "phalange"
// }

stringify({left: 'phalange'}, {type: 'json5', pretty: true})
// {
//   left: 'phalange',
// }

Changelog

Changelog

Related

License

MIT ©

Author: admin

16 thoughts on “CommonJS, ESModule, INI, JSON, JSON5, TOML, YAML data loader, parser and stringifier

  1. If you want to use the photo it would also be good to check with the artist beforehand in case it is subject to copyright. Best wishes. Aaren Reggis Sela

  2. If you want to use the photo it would also be good to check with the artist beforehand in case it is subject to copyright. Best wishes. Aaren Reggis Sela

  3. If some one desires expert view on the topic of running a blog afterward i recommend him/her to pay a visit this webpage, Keep up the nice work. Pam Tammy Micki

  4. You made some nice points there. I looked on the internet for the subject matter and found most individuals will agree with your site.

  5. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  6. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  7. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  8. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  9. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  10. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

Leave a Reply

Your email address will not be published.