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

dot-prop-opt

v1.0.5

Published

Modify nested object properties using a dot path. Package is runtime optimized.

Downloads

18

Readme

dot-prop-opt Build Status codecov huntr

Modify nested object properties using a dot path. Package is runtime optimized.

I have test this version with dot-prop package. The optimized version is significant faster on get and delete, but also bit faster on has and set methods.

opt.get x 300,660 ops/sec ±0.69% (89 runs sampled)
opt.set x 301,490 ops/sec ±0.63% (88 runs sampled)
opt.delete x 677,365 ops/sec ±1.10% (89 runs sampled)
opt.has x 397,895 ops/sec ±1.09% (86 runs sampled)
dot-props.get x 183,423 ops/sec ±1.19% (88 runs sampled)
dot-props.set x 216,006 ops/sec ±1.03% (87 runs sampled)
dot-props.delete x 485,108 ops/sec ±0.98% (87 runs sampled)
dot-props.has x 357,707 ops/sec ±1.61% (81 runs sampled)

Install

$ npm install dot-prop-opt

Usage

const sdp = require('dot-prop-opt');

// get
sdp.get({name: {first: 'julia'}}, 'name.first');
//=> 'julia'

sdp.get({name: {first: 'a'}}, 'name.notDefined.deep');
//=> undefined

sdp.get({name: {first: 'a'}}, 'name.notDefined.deep', 'default value');
//=> 'default value'

// set
const obj = {foo: {bar: 'a'}};
sdp.set(obj, 'name.first', 'julia');
console.log(obj);
//=> {name: {first: 'julia'}}

const person = sdp.set({}, 'name.first', 'julia');
console.log(person);
//=> {name: {first: 'name.first'}}

sdp.set(obj, 'name.middle', 'marie');
console.log(obj);
//=> {name: {first: 'julia', middle: 'marie'}}

// has
sdp.has({name: {first: 'julia'}}, 'name.first');
//=> true

// delete
const obj = {name: {first: 'julia'}};
sdp.delete(obj, 'name.first');
console.log(obj);
//=> {name: {}}

obj.name = {first: 'julia', middle: 'marie'};
sdp.delete(obj, 'name.first');
console.log(obj);
//=> {name: {middle: 'marie'}}

API

get(obj, path, [defaultValue])

set(obj, path, value)

Returns the object or false on error.

has(obj, path)

delete(obj, path)

obj

Type: Object

Object to get, set, or delete the path value.

path

Type: string

Path of the property in the object, using . to separate each nested key.

Do not use a . in the key (name).

value

Type: any

Value to set at path.

defaultValue

Type: any

Default value.

License

MIT © Alexander Vu