https://github.com/arlac77/key-value-transformer
Replaces key value pairs in a stream of lines
https://github.com/arlac77/key-value-transformer
Last synced: about 1 year ago
JSON representation
Replaces key value pairs in a stream of lines
- Host: GitHub
- URL: https://github.com/arlac77/key-value-transformer
- Owner: arlac77
- License: 0bsd
- Created: 2021-12-08T09:34:52.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-04-06T00:05:57.000Z (about 1 year ago)
- Last Synced: 2025-04-06T00:24:20.293Z (about 1 year ago)
- Language: JavaScript
- Size: 1.39 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/key-value-transformer)
[](https://spdx.org/licenses/0BSD.html)
[](https://typescriptlang.org)
[](https://bundlejs.com/?q=key-value-transformer)
[](https://npmjs.org/package/key-value-transformer)
[](https://github.com/arlac77/key-value-transformer/issues)
[](https://actions-badge.atrox.dev/arlac77/key-value-transformer/goto)
[](https://github.com/prettier/prettier)
[](http://commitizen.github.io/cz-cli/)
[](https://snyk.io/test/github/arlac77/key-value-transformer)
[](https://coveralls.io/github/arlac77/key-value-transformer)
# key-value-transformer
Scans and replaces key value pairs in a stream of lines
```js
import { keyValueTransformer } from "key-value-transformer";
const input = getTextStream();
const output = keyValueTransformer(input, async * (key,value) => { yield [key, "newValue" ];})
```
# API
### Table of Contents
* [KeyValueUpdates](#keyvalueupdates)
* [Parameters](#parameters)
* [Lines](#lines)
* [KeyValueTransformOptions](#keyvaluetransformoptions)
* [Properties](#properties)
* [colonSeparatedKeyValuePairOptions](#colonseparatedkeyvaluepairoptions)
* [equalSeparatedKeyValuePairOptions](#equalseparatedkeyvaluepairoptions)
* [colonSeparatedKeyValuePairOptionsDoublingKeys](#colonseparatedkeyvaluepairoptionsdoublingkeys)
* [keyValueTransformer](#keyvaluetransformer)
* [Parameters](#parameters-1)
## KeyValueUpdates
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
### Parameters
* `key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** current key
* `value` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** current value
* `presentKeys` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** the already seen keys
Returns **AsyncIterable<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>>** updated key and value pairs
## Lines
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
Returns **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
## KeyValueTransformOptions
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
### Properties
* `extractKeyValue` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** 1st. line with key and value
* `extractValueContinuation` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** additional lines holding only values
* `lineEnding` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** used to separate lines
* `keyValueSeparator` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** chars to separate key from value like '=' or ':'
* `keyValueLines` **[Lines](#lines)** to generate line(s) for a key value(s) pair
* `trailingLines` **[Lines](#lines)?** lines coming after all key values have been written
* `headLines` **[Lines](#lines)?** lines before all key values have been written
## colonSeparatedKeyValuePairOptions
Type: [KeyValueTransformOptions](#keyvaluetransformoptions)
## equalSeparatedKeyValuePairOptions
Type: [KeyValueTransformOptions](#keyvaluetransformoptions)
## colonSeparatedKeyValuePairOptionsDoublingKeys
Type: [KeyValueTransformOptions](#keyvaluetransformoptions)
## keyValueTransformer
Replaces key value pairs in a stream of lines.
### Parameters
* `source` **AsyncIterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** input lines
* `updates` **[KeyValueUpdates](#keyvalueupdates)**
* `options` **[KeyValueTransformOptions](#keyvaluetransformoptions)** (optional, default `colonSeparatedKeyValuePairOptions`)
Returns **AsyncIterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** lines with replaces key value pairs
# install
With [npm](http://npmjs.org) do:
```shell
npm install key-value-transformer
```
# license
BSD-2-Clause