Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fisker/left-phalange-api
YAML, TOML, JSON, JSON5, INI, CSV, ES Module, CommonJS data loader, parser and stringifier
https://github.com/fisker/left-phalange-api
Last synced: 6 days ago
JSON representation
YAML, TOML, JSON, JSON5, INI, CSV, ES Module, CommonJS data loader, parser and stringifier
- Host: GitHub
- URL: https://github.com/fisker/left-phalange-api
- Owner: fisker
- License: mit
- Created: 2019-05-27T01:20:16.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-31T01:11:04.000Z (8 months ago)
- Last Synced: 2024-03-31T02:23:04.469Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 1000 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 46
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# left-phalange-api
> YAML, TOML, JSON, JSON5, INI, CSV, ES Module, CommonJS data loader, parser and stringifier
## Install
```sh
yarn add left-phalange-api
```## Usage
```js
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:
```js
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:
```js
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:
```js
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
- [left-phalange](https://github.com/fisker/left-phalange) - CLI for this module