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

deep-props.set

v0.1.2

Published

Sets values within nested objects; creates structure if not found. Supports setting within Objects, Arrays, Maps, Sets, WeakMaps, and WeakSets; supports creation of Objects, Arrays, and Maps.

Downloads

8

Readme

deep-props.set

NPM

Sets values within nested objects; creates structure if not found. Supports setting within Objects, Arrays, Maps, Sets, WeakMaps, and WeakSets; supports creation of Objects, Arrays, and Maps.

Uses the deep-props.get module for dataset exploration. As such, allows for setting within all types supported by the deep-props.get module (with the exception of strings).

In terms of new structure creation, keys are analyzed in the following manner in order to determine what kind of structure to construct:

  • Number keys (or string numbers) construct arrays.
  • String keys construct Objects.
  • Object keys construct Maps.

The next key along the path is used during this structure determination.

Behavior can be customized by using either the forceConstructor or the setCustomizer settings in the module options.

See the usage examples for an overview of different types of data structures.

Getting Started

The following installation, testing, and deployment instructions assume that deep-props.set will be installed as a standalone module. For instructions on how to install and test all deep-props modules, please refer to the main README. Functionality of the module remains the same in both cases.

Prerequisites

Node.JS version 8.7.0 or above.

Installing

npm install deep-props.set

Testing

The following command will test the package for errors. It prints a selection of examples to the console; scroll through its output if you want to learn more about the utility.

npm test --prefix /path/to/node_modules/deep-props.set

Deployment

const set = require('deep-props.set')

Usage

Note: For string paths using standard settings, '.' is considered the same as '[' and ']'. See Options for instructions for customizing this behavior.

Setting within existing Object structure

const nest = { foo: { bar: { baz: 'beh' } } }

// Both return: { foo: { bar: { baz: 'qux' } } }
set(nest, 'foo.bar.baz', 'qux')
nest

Setting within existing Array structure

const nest = [[['foo']]]

// Both return: [[['bar']]]
set(nest, '0.0.0', 'bar')
nest

Setting within existing Map structure

const nest = new Map().set(
  'foo', new Map().set(
    'bar', new Map().set(
      'baz', 'beh'
    )
  )
)

// Both return: Map { 'foo' => Map { 'bar' => Map { 'baz' => 'qux' } } }
set(nest, 'foo.bar.baz', 'qux')
nest

Setting within existing Set structure

const nest = new Set([
  new Set([
    new Set([
      'foo'
    ])
  ])
])

// Both return: Set { Set { Set { 'bar' } } }
set(nest, '0.0.0', 'bar')
nest

// Both return: Set { Set { Set { 'bar', 'baz' } } }
set(nest, '0.0.1', 'baz')
nest

Creation of new Object structure

const nest = {}

// Both return: { foo: { bar: { baz: 'qux' } } }
set(nest, 'foo.bar.baz', 'qux')
nest

Creation of new Array structure

const nest = []

// Both return: [[['foo']]]
set(nest, '0.0.0', 'foo')
nest

Creation of new Map structure

const nest = new Map()

// Both return: Map { ['foo'] => Map { ['bar'] => Map { ['baz'] => 'beh' } } }
set(nest, [['foo'], ['bar'], ['baz']], 'beh')
nest

Documentation

See:

Module: set

Sets values within nested objects; creates structure if not found. Supports setting within Objects, Arrays, Maps, Sets, WeakMaps, and WeakSets; supports creation of Objects, Arrays, and Maps.

Parameters:

| Name | Type | Attributes | Default | Description | | --- | --- | --- | --- | --- | | host | deep-props.set~Host | | | Container to search within. | | path | deep-props.set~Path | | | Path to desired property. | | data | * | | | Data to set at endpoint of path. | | opt | deep-props.set~Options | <optional> | {} | Execution settings. |

Source:

Returns:

True if successful, false if not. If opt.gen === true, returns a generator that yields each search step.

Type

boolean | deep-props.set~ResultGenerator

Versioning

Versioned using SemVer. For available versions, see the Changelog.

Contribution

Please raise an issue if you find any. Pull requests are welcome!

Author

  • Justin Collier - jpcx

License

This project is licensed under the MIT License - see the LICENSE file for details