3.0.0 • Published 3 years ago

left-phalange-api v3.0.0

Weekly downloads
250
License
MIT
Repository
github
Last release
3 years ago

left-phalange-api

YAML, TOML, JSON, JSON5, INI, CSV, ES Module, CommonJS data loader, parser and stringifier

Install

yarn add left-phalange-api

Usage

import {parse, load, stringify} from 'left-phalange-api'

load(file, options)

  • 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, csv

examples:

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

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

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

parse(string, options)

  • 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, csv
  • options.filename
    • Filename displayed in the error message.

examples:

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

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

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

await parse('left = phalange', {filename: 'path/to/data.yml'})

stringify(data, options)

  • 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, csv
  • options.pretty
    • Pretty output
    • Default false

examples:

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

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

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

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

Related

3.0.0

3 years ago

2.0.0

3 years ago

1.3.3

3 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago