1. object-property-extensions
Some utility methods for extending objects
object-property-extensions
Package: object-property-extensions
Created by: teeeemoji
Last modified: Thu, 12 May 2022 01:00:13 GMT
Version: 1.0.1
License: MIT
Downloads: 3
Repository: https://github.com/teeeemoji/object-property-extensions

Install

npm install object-property-extensions
yarn add object-property-extensions

object-property-extensions

Travis (.com)
Codecov
NPM
npm
npm
npm bundle size
GitHub last commit

Installation

 $ npm install object-property-extensions --save

Usage

 import {safeGet, safeSet, hasOwnProperty} from 'object-property-extensions'
const obj = {
  a: 1,
  b: [{
    c: 'd', 
    e: ['f']
  }]
}
hasOwnProperty(obj, 'b.0.c') // true
hasOwnProperty(obj, 'a.1.2') // false
safeGet(obj, 'b.0.c') // 'd'
safeGet(obj, 'a.1.2') // undefined
safeSet(obj, 'b.0.c', 1) // true
safeSet(obj, 'a.1.2', 1) // true

API

hasOwnProperty

src/index.js:16-28

Determines whether the ctx contains deeply nested property of the path description

Parameters

  • ctx {Object}
  • path {string|Array}

Returns boolean

safeGet

src/index.js:38-44

Safely retrieve the deep nested property of ctx that describe in the path

Parameters

  • ctx {Object}
  • path {string}

Returns any

safeSet

src/index.js:55-67

Safely set deeply nested property of ctx that describe in path

Parameters

  • ctx
  • path
  • value

Returns boolean

License

This project is licensed under the MIT license.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code