An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![npm](https://img.shields.io/npm/v/key-value-transformer.svg)](https://www.npmjs.com/package/key-value-transformer)
[![License](https://img.shields.io/badge/License-0BSD-blue.svg)](https://spdx.org/licenses/0BSD.html)
[![Typed with TypeScript](https://flat.badgen.net/badge/icon/Typed?icon=typescript\&label\&labelColor=blue\&color=555555)](https://typescriptlang.org)
[![bundlejs](https://deno.bundlejs.com/?q=key-value-transformer\&badge=detailed)](https://bundlejs.com/?q=key-value-transformer)
[![downloads](http://img.shields.io/npm/dm/key-value-transformer.svg?style=flat-square)](https://npmjs.org/package/key-value-transformer)
[![GitHub Issues](https://img.shields.io/github/issues/arlac77/key-value-transformer.svg?style=flat-square)](https://github.com/arlac77/key-value-transformer/issues)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Farlac77%2Fkey-value-transformer%2Fbadge\&style=flat)](https://actions-badge.atrox.dev/arlac77/key-value-transformer/goto)
[![Styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Known Vulnerabilities](https://snyk.io/test/github/arlac77/key-value-transformer/badge.svg)](https://snyk.io/test/github/arlac77/key-value-transformer)
[![Coverage Status](https://coveralls.io/repos/arlac77/key-value-transformer/badge.svg)](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