1.0.4 • Published 3 years ago

@gdurastanti/js-extract v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

js-extract

Fancy extractor for js objects that is like destructuring but safer.

Install

npm install --save @gdurastanti/js-extract

Use

import extract from @gdurastanti/'js-extract'

OR

var extract = require('@gdurastanti/js-extract').default

Example

const data = {
  one: {
    num: 1,
    str: 'one',
    foo: {
      bar: 'baz',
    },
  },
  two: {
    num: 2,
    str: 'two',
    foo: {
      bar: 'baz',
    },
  }
};

const selector = `
  one: {
    str
  },
  two: {
    num,
    foo
  }
`

extract(selector).from(data);

Result:

{
  one: {
    str: 'one'
  },
  two: {
    num: 2,
    foo: {
      bar: 'baz'
    }
  }
}