# fields-transformer

> transforms fields

Latest version **1.1.4** (published 2019-09-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install fields-transformer
pnpm add fields-transformer
yarn add fields-transformer
bun add fields-transformer
```

## 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 | 1.1.4 |
| Published | 2019-09-09 |
| First published | 2019-04-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Israel Oluwole O. |
| Maintainers | whizyrel |
| Keywords | transforms, objects, fields |

## Links

- npm: https://www.npmjs.com/package/fields-transformer
- Repository: https://github.com/whizyrel/transformer
- Homepage: https://github.com/whizyrel/transformer#readme
- Issues: https://github.com/whizyrel/transformer/issues
- npm.io page: https://npm.io/package/fields-transformer

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2019-09-09
- 1.1.3 — 2019-09-09
- 1.1.2 — 2019-09-09
- 1.1.1 — 2019-09-09
- 1.1.0 — 2019-05-14
- 1.0.1-alpha.0 — 2019-04-12
- 1.0.0 — 2019-04-05

## README

# transformer
Typically transforms key value pairs into some other key value pairs. It is intended to work with the results from multipart handlers like formidable or multer. Not the transformer from the `transformer` movie.
See documentation below.

## Requirement

- [Node](https://nodejs.org/en/download/)
- [NPM](https://www.npmjs.com/)

## Installation

Use the package manager [npm](https://www.npmjs.com/package/field-transformer) to install field-transformer.

```bash
npm install field-transformer
```

## Usage

```js
const transformer = require('jwt-linker');
```

#### make

Use the `make` method for transforming an `object` with keys with values of type `array of objects`

```js
transformer.make({
  bread: [{path: 'a'}, {path: 'b'}, {path: '...n'}],
  butter: [{path: 'a'}, {path: 'b'}, {path: '...n'}],
  ginger: [{path: 'a'}, {path: 'b'}, {path: '...n'}]
});

// Typically, used with transformer.attach
```

#### makeSingle

Use to transform an `array` of `paths` into an array of `filePaths` like so

```js
const {filePaths} = transformer.makeSingle({
  files: [{path: 'a'}, {path: 'b'}, {path: '...n'}]}
);
console.log(filePaths); // ['a', 'b', '..n']
```

#### objFieldTransformer

Use to transform keys of values of type `object` with `path` as values into an array of `filePaths` like so

```js
const {filePaths} = transformer.objFieldTransformer({
  bread: {path: 'a'},
  butter: {path: 'a'},
  ginger: {path: 'a'},
});
console.log(filePaths); // ['a', 'a', 'a']
```

#### objArrayTransformer

Use to transform keys of values of the type `array` into an array of `filePaths` like so

```js

const someObject = {
  bread: [{path: 'a'}, {path: 'b'}, {path: '...n'}],
  butter: [{path: 'a'}, {path: 'b'}, {path: '...n'}],
  ginger: [{path: 'a'}, {path: 'b'}, {path: '...n'}]
};

const {filePaths} = transformer.objArrayTransformer(someObject);
console.log(filePaths); // ['a', 'b', '..n', 'a', 'b', '..n', ...]
```

#### attach

Use to attach elements of the filePaths to the doc. Receives two arguments `doc` and `fields`.
`Fields` is either an array of strings or just a string. Attach picks the values from the `filePaths` in `transformer.make` returns a promise, deal as suites you.

```js
const docModified = await transformer.attach({}, ['storyImages', 'otherImages']);
or const docModified = await transformer.attach({}, 'profileImage');

console.log({docModified}); // {docModified: {storyImages: '...', otherImages: '...'}}
or console.log({docModified}); // {docModified: {profileImage: '...'}}
```

## Additions

- method objArrayTransformer
- An explainable readme

# Support, Issues

Please visit the Github repo. Submissions, issues... are welcome

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