Neighbourhood Party Manager
Miss any of our Open RFC calls?Watch the recordings here! »

parse-pairs

1.0.0 • Public • Published

parse-pairs

Package Version Build Status PackagePhobia Latest Commit

Parse key-value pairs

Install

Installation of the npm package:

> npm install --save parse-pairs

Usage

import parsePairs from "parse-pairs";
 
parsePairs('Batman="Bruce Wayne" "Wonder Woman"="Diana Prince" # comment');
// {
//   Batman: 'Bruce Wayne',
//   'Wonder Woman': 'Diana Prince'
// }
  • both keys and values can be quoted
  • single and double quotes are supported
  • white spaces around pairs are ignored
  • no escape sequences, feel free to open an issue or PR if necessary
  • single line comments starting with # are ignored

Custom parser

For advanced needs, you can create a custom parser.

import { createParser } from 'parse-pairs'
 
const parse = createParser({
  keyTransform: lodash.cameCase,
  valueTransform: (value, key) => lodash.startCase(value.toLowerCase())
})
 
parse('BATMAN="BRUCE WAYNE" "WONDER WOMAN"="DIANA PRINCE"')
{
  batman: 'Bruce Wayne',
  wonderWoman: 'Diana Prince'
}

Development

# Install dependencies
> npm install

# Run the tests
> npm test

# Continuously compile
> npm run dev

# Continuously run the tests
> npm run dev-test

# Build for production (automatically called by npm install)
> npm run build

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet

Install

npm i parse-pairs

DownloadsWeekly Downloads

397

Version

1.0.0

License

ISC

Unpacked Size

15.5 kB

Total Files

6

Last publish

Collaborators

  • avatar
  • avatar
  • avatar