All Projects β†’ VitorLuizC β†’ get

VitorLuizC / get

Licence: MIT License
🚚 A really small and type-safe (requires TypeScript >= 4.1.3) function, that gets a nested value from an object using a path string (like "a.b[0].d"). If value is 'undefined' or unreachable returns the placeholder instead.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to get

expand-hash
Recursively expands property keys with dot-notation into objects.
Stars: ✭ 25 (+92.31%)
Mutual labels:  object, nested-objects, dot-notation
glob-object
Filter an object using glob patterns and dot notation.
Stars: ✭ 25 (+92.31%)
Mutual labels:  object, nested, dot-notation
Deep Object Diff
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
Stars: ✭ 515 (+3861.54%)
Mutual labels:  object, deep
underscore.haz
πŸ” _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (+0%)
Mutual labels:  object, deep
obj-filter
JavaScript Object Filter. Deep filtering key/content recursively. Support wildcard, nested, and filter function in template.
Stars: ✭ 13 (+0%)
Mutual labels:  object, nested
Clone Deep
Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. Used by superstruct, merge-deep, and many others!
Stars: ✭ 229 (+1661.54%)
Mutual labels:  object, deep
Get Value
Use property paths (`a.b.c`) get a nested value from an object.
Stars: ✭ 194 (+1392.31%)
Mutual labels:  object, deep
stringify-keys
Build an array of key paths from an object.
Stars: ✭ 18 (+38.46%)
Mutual labels:  object, dot-notation
has-value
Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
Stars: ✭ 27 (+107.69%)
Mutual labels:  object, dot-notation
js-deep-sort-object
Simple module to sort objects recursively by its keys
Stars: ✭ 19 (+46.15%)
Mutual labels:  object, deep
CarND-VehicleDetection
vehicle detection with deep learning
Stars: ✭ 34 (+161.54%)
Mutual labels:  object, deep
readdir
Recursively read a directory, blazing fast. Use with picomatch or micromatch to match globs.
Stars: ✭ 37 (+184.62%)
Mutual labels:  nested
ember-deep-set
Deeply set values on an Ember Object or POJO
Stars: ✭ 30 (+130.77%)
Mutual labels:  nested-objects
forestTreesTagging
This project has the vision to assist the officials for Forest trees census and tagging each tree with proper location (latitude and longitude), tree type, and other arguments. and further had the plan to apply data analysis over-collected data.
Stars: ✭ 18 (+38.46%)
Mutual labels:  deep
EmbeddedScrollView
Embedded UIScrollView for iOS.
Stars: ✭ 55 (+323.08%)
Mutual labels:  nested
avoriaz-ava-example
Testing Vue components with AVA and avoriaz example
Stars: ✭ 17 (+30.77%)
Mutual labels:  ava
Inferno-Realtime-Fire-detection-using-CNNs
FPGA Deployable Fire Detection Model for Real-Time Video Surveillance Systems Using Convolutional Neural Networks
Stars: ✭ 24 (+84.62%)
Mutual labels:  deep
fly-ava
✈️ A plugin for Fly that run ava tests
Stars: ✭ 13 (+0%)
Mutual labels:  ava
pykorm
A python 🐍 kubernetes ☸️ ORM πŸš€. Very useful when writing operators for your CRDs with Kopf.
Stars: ✭ 56 (+330.77%)
Mutual labels:  object
kirby3-instagram
Kirby 3 Plugin to call Instagram (or any other) API Endpoints
Stars: ✭ 20 (+53.85%)
Mutual labels:  get

@bitty/get

A really small and type-safe (requires TypeScript >= 4.1.3) function, that gets a nested value from an object using a path string (like "a.b[0].d"). If value is undefined or unreachable returns the placeholder instead.

  • πŸ“¦ Distributions in ESM, CommonJS, UMD and UMD minified formats.

    • Supports both NodeJS used with ESM (import/export) and CommonJS (require/module.exports).
  • ⚑ Lightweight:

    • Weighs less than 150 bytes (when minified and gzipped).
    • Tree-shakeable.
    • Side-effects free.
  • πŸ”‹ Batteries included:

    • No dependencies.
    • Its not based on newer browser's APIs or es2015+ features.
  • 🏷 Safe:

    • JSDocs and type declarations for IDEs and editor's autocomplete/intellisense.
    • Made with TypeScript as strict as possible.
    • Unit tests with AVA (types was also tested).

It's approach is based on idx, from Facebook, and an insight from a Vue.js meetup where @IgorHalfeld showed a way to get nested values using eval.

Install

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install --save @bitty/get

# If you're using Yarn use the command below.
yarn add @bitty/get

Installation from CDN

This module has a UMD bundle available through JSDelivr and Unpkg CDNs.

<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/@bitty/get"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/@bitty/get"></script>

<script>
  // UMD module is exposed through the "get" global function.
  console.log(get);
  //=> "[Function: get]"

  var users = [{ name: 'Carlos Marcos' }];

  console.log(get(users, '[0].name', 'Unknown'));
  //=> "Carlos Marcos"
</script>

Usage

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

import get from '@bitty/get';

// ...

const name = get(response, 'data.user.name', 'Unknown');

You can use brackets, even on first property.

const title = get(paragraphs, '[0].children[0].textContent');

License

Released under MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].