1.1.4 • Published 5 years ago

fields-transformer v1.1.4

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

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

Installation

Use the package manager npm to install field-transformer.

npm install field-transformer

Usage

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

make

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

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

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

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

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.

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

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1-alpha.0

5 years ago

1.0.0

5 years ago