1.0.0 • Published 6 years ago

extract-ts v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

extract-ts

This library is a type safe alternative to lodash's get.



The main advantage of this version is that it allows accessing many nested optional layers. This library expects you to be using typescript 2.8.0, or above.

Setup

Install via npm (or yarn)

npm i extract-ts --save

After that you may use it:

const resultWithDefault: string = extract(
    testObject,                  // object you want to extract a value of
    obj => obj.data.desiredData, // extract the value
    ''                           // default value, optional parameter
);

// if you omit the default value, extract may also return undefined
const resultWithoutDefault: string | undefined = extract(testObject, obj => obj.data.desiredData);

// per default the type of the default value equals the result type of the extractor
// but you can change that wen you specify the types:
const result: string | number = <SomeTypeYouWantToAccess, string, number>(
    testObject,
    obj => obj.data.desiredData,
    10
);

Local Development

After checking out the repository, you just need to run npm install. You will find many useful commands in the table below.

Useful commands

npm commanddescription
npm run buildproductive build of this library
npm run testruns all unit tests of this library
npm run test:coverageruns unit tests and evaluates the coverage
npm run verifychecks test coverage and runs the linter
npm run lintruns tslint

Contributing

Please follow the following steps if you want to contribute:

  • ( create an issue, introducing the change )
  • assign yourself to the issue you want to work on
  • open a pullrequest with your changes

Authors

Licence

MIT

1.0.0

6 years ago