# parse-pairs

> Parse key-value pairs (like environment variables)

Latest version **2.0.0** (published 2022-11-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install parse-pairs
pnpm add parse-pairs
yarn add parse-pairs
bun add parse-pairs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-11-26 |
| First published | 2016-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Julien Fontanet |
| Maintainers | julien-f, marsaud, pdonias |
| Keywords | env, environ, environment, key, pair, pairs, parse, parser, value, var, variable, variables |

## Links

- npm: https://www.npmjs.com/package/parse-pairs
- Repository: https://github.com/JsCommunity/parse-pairs
- Issues: https://github.com/JsCommunity/parse-pairs/issues
- npm.io page: https://npm.io/package/parse-pairs

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-11-26
- 1.1.0 — 2020-12-30
- 1.0.0 — 2019-11-29
- 0.2.2 — 2016-12-14
- 0.2.1 — 2016-12-14
- 0.2.0 — 2016-12-14
- 0.1.0 — 2016-11-28
- 0.0.0 — 2016-11-28

## README

# parse-pairs

[![Package Version](https://badgen.net/npm/v/parse-pairs)](https://npmjs.org/package/parse-pairs) ![License](https://badgen.net/npm/license/parse-pairs) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/parse-pairs)](https://bundlephobia.com/result?p=parse-pairs) [![Node compatibility](https://badgen.net/npm/node/parse-pairs)](https://npmjs.org/package/parse-pairs)

> Parse key-value pairs

## Install

Installation of the [npm package](https://npmjs.org/package/parse-pairs):

```
> npm install --save parse-pairs
```

## Usage

```js
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](https://github.com/JsCommunity/parse-pairs/issues/) or [PR](https://github.com/JsCommunity/parse-pairs/pulls) if necessary
- single line comments starting with `#` are ignored

### Custom parser

> For advanced needs, you can create a custom parser.

```js
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'
}
```

## Contributions

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

You may:

- report any [issue](https://github.com/JsCommunity/parse-pairs/issues)
  you've encountered;
- fork and create a pull request.

## License

ISC © [Julien Fontanet](https://github.com/julien-f)

---
_Source: https://npm.io/package/parse-pairs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
