npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prop-ops

v1.1.6

Published

Assists in performing CRUD operations on javascript objects and arrays

Downloads

4

Readme

prop

npm install prop-ops

prop-ops assists in performing CRUD operations on javascript objects and arrays. By default, prop-ops does not mutate objects, but offers the option of doing so.

Authors: Matthew Meyers, Sunyoung Kim
License: MIT

prop.get(obj, propString, [fallBack]) ⇒ Any

Safely access deeply nested properties of unstructured objects

Kind: static method of prop

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | Object | Array | | the object or array to traverse | | propString | String | | the path to the desired property | | [fallBack] | Any | | a fall back value to return if the property is not found |

Example

import * as prop from 'prop-ops'

const objA = { a: { b: 'c' } }
prop.get(objA, 'a.b')
// > 'c'

// Specify a value to return if a property is not found
prop.get(objA, 'a.nope')
// > null
prop.get(objA, 'a.nope', 24)
// > 24

// Traverse an array
const objB = { a: [{ b: 'c' }] }
prop.get(objB, 'a.[0].b')
// > 'c'

prop.set(obj, propString, value, [loose]) ⇒ Object | Array

Sets deeply nested object properties.

Kind: static method of prop
Returns: Object | Array - an updated version of obj

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | Object | Array | | the object or array to traverse | | propString | String | | the path to the desired property | | value | Any | | the value to set | | [loose] | Boolean | false | create new objects / arrays along the path if undefined is encountered |

Example

import * as prop from 'prop-ops'

const objA = { a: { b: 'c' } }
const updatedA = prop.set(objA, 'a.c', 'd')
// > objA     == { a: { b: 'c' } }
// > updatedA == { a: { b: 'c', c: 'd' } }

const constructedObj = prop.set({}, 'a.[0].b.c', 12, true)
// > constructedObj == { a: [{ b: { c: 12 } }] }

set.mutate(obj, propString, value, [loose])

Like set, but will modify the original object

Kind: static method of set

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | Object | Array | | the object or array to traverse | | propString | String | | the path to the desired property | | value | Any | | the value to set | | [loose] | Boolean | false | create new objects / arrays along the path if undefined is encountered |

Example

import * as prop from 'prop-ops'

const objA = { a: { b: 'c' } }
prop.set.mutate(objA, 'a.c', 'd')
// > objA == { a: { b: 'c', c: 'd' } }

const emptyObj = {}
prop.set.mutate(emptyObj, 'a.[0].b.c', 12, true)
// > emptyObj == { a: [{ b: { c: 12 } }] }

prop.merge(obj, propString, value, [loose]) ⇒ Object | Array

Merge deeply nested objects or arrays.

Kind: static method of prop
Returns: Object | Array - an updated version of obj

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | Object | Array | | the object or array to traverse | | propString | String | | the path to the desired property | | value | Object | Array | | the object to merge | | [loose] | Boolean | false | create new objects / arrays along the path if undefined is encountered |

Example

import * as prop from 'prop-ops'

const objA = { a: { b: 'c' } }
const updatedA = prop.merge(objA, 'a', { d: 'e', f: 'g' })
// > objA     == { a: { b: 'c' } }
// > updatedA == { a: { b: 'c', d: 'e', f: 'g' } }

const objB = { a: [0, 1, 2] }
const updatedB = prop.merge(objB, 'a', [, , 3, 4])
// > objB     == { a: [0, 1, 2] }
// > updatedB == { a: [0, 1, 3, 4] }

merge.mutate(obj, propString, value, [loose])

Like merge, but will modify the original object

Kind: static method of merge

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | Object | Array | | the object or array to traverse | | propString | String | | the path to the desired property | | value | Object | Array | | the object to merge | | [loose] | Boolean | false | create new objects / arrays along the path if undefined is encountered |

Example

import * as prop from 'prop-ops'

const objA = { a: { b: 'c' } }
prop.merge.mutate(objA, 'a', { d: 'e', f: 'g' })
// > objA == { a: { b: 'c', d: 'e', f: 'g' } }

const objB = { a: [0, 1, 2] }
prop.merge.mutate(objB, 'a', [, , 3, 4])
// > objB == { a: [0, 1, 3, 4] }

prop.has(obj, propString) ⇒ Boolean

Check if an object or array has a property

Kind: static method of prop

| Param | Type | Description | | --- | --- | --- | | obj | Object | object to traverse | | propString | String | the path to the desired property |

Example

import * as prop from 'prop-ops'

const objA = { a: [{ b: { c: 'd' } }] }
prop.has(objA, 'a.b')
// > false
prop.has(objA, 'a.[0].b.c')
// > true

prop.del(obj, propString) ⇒ Object | Array

Deletes deeply nested object properties

Kind: static method of prop

| Param | Type | Description | | --- | --- | --- | | obj | Object | Array | object to traverse | | propString | String | the path to the desired property |

Example

import * as prop from 'prop-ops'

const objA = { a: { b: { c: 'd' } } }
const updatedA = prop.del(objA, 'a.b')
// > objA     == { a: { b: { c: 'd' } } }
// > updatedA == { a: {} }

del.mutate(obj, propString)

Like del, but will modify the original object

Kind: static method of del

| Param | Type | Description | | --- | --- | --- | | obj | Object | Array | object to traverse | | propString | String | the path to the desired property |

Example

import * as prop from 'prop-ops'

const objA = { a: [{ b: { c: 'd' } }] }
prop.del.mutate(objA, 'a.b')
// noop
prop.del.mutate(objA, 'a.[0].b')
// objA == { a: [{}] }