This package has been deprecated

Author message:

"object-take" is deprecated. It was renamed and moved to "@bitty" scoped packages. Now it should be installed as "@bitty/get".

object-take
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

object-take

Build Status

A really small library, almost 150 bytes minified and gzipped, to take value from object using a string for path expression or returns a placeholder if value is undefined or unreachable.

It's approach is based on idx, from Facebook, and a insight from Vue.js meetup where @IgorHalfeld shows a way to get a property using eval. Yeah, eval.

Install

This module is published under NPM registry, so you can install from any package manager.

npm install --save object-take
 
# If you're using Yarn use the command below. 
yarn add object-take

Usage

Just import take function and take a value from object using a path expression.

import take from 'object-take';
 
// ...
 
const name = take(response, 'data.user.name', 'Unknown');

You can use brackets, even on first property.

const title = take(paragraphs, '["data"].children[0].textContent');

Also, expressions could be attached to path.

const id = take(response, 'data.keys[0].number.toString(16)');

License

Released under the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i object-take

Weekly Downloads

13

Version

0.1.3

License

MIT

Unpacked Size

7.28 kB

Total Files

7

Last publish

Collaborators

  • vitorluizc