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

stdobj

v0.6.2

Published

Fast, small, dependency-free lib for common work with object literals.

Downloads

14

Readme

STDOBJ

Fast, small, dependency-free lib for common work with object literals.

Installation

yarn add stdobj
# ...or...
npm i stdobj

Usage

stdobj provides a number of methods which can be destructured and used in code. Below is a list of the supported methods:

  • isObj - Checks if parameter passed is an object literal
  • keys - Retruns array of keys from object
  • toPairs - Converts object to array of key-value pair arrays
  • fromPairs - Converts array of key-value pairs to object
  • get - Gets a value using standard or dot-notated key
  • set - Sets a value using standard or dot-notated key
  • flatten - Flattens object to dot-notated key-value object
  • expand - Expands a flattened, dot-notated object to nested object
  • redact - Redacts keys or values on an object literal
  • merge - Performs a deep merge on object parameter(s)

isObj

isObj(<*>) - Checks if parameter passed is an object literal

const obj = { foo: 'bar' }
const notObj = 42

isObj(obj) // -> true
isObj(notObj) // -> false

keys

keys(<Object>) - Retruns array of keys from object

const obj = { foo: 'bar', fizz: 'buzz' }

keys(obj) // -> [ 'foo', 'fizz' ]

toPairs

toPairs(<Object>) - Converts object to array of key-value pair arrays

const obj = { foo: 'bar', fizz: 'buzz' }

toPairs(obj) // -> [ [ 'foo', 'bar' ], [ 'fizz', 'buzz' ] ]

fromPairs

fromPairs(<Array>) - Converts array of key-value pairs to object

const pairs = [ [ 'foo', 'bar' ], [ 'fizz', 'buzz' ] ]

fromPairs(pairs) // -> { foo: 'bar', fizz: 'buzz' }

get

get(<String>) - Gets a value using standard or dot-notated key

const obj = {
  foo: 'bar',
  fizz: {
    buzz: 'bizz'
  }
}

get('foo') // -> 'bar'
get('fizz.buzz') // -> 'bizz'

set

set(Obj<Object>, Key<String>, Value<*>) - Sets a value using standard or dot-notated key

const obj = {}

set(obj, 'foo.bar', 'fizz') // obj = { foo: { bar: 'fizz' } }

flatten

flatten(<Object>) - Flattens object to dot-notated key-value object

const obj = {
  foo: 'bar',
  fizz: {
    buzz: 'bizz'
  }
}

flatten(obj) // -> { foo: 'bar', 'fizz.buzz': 'bizz' }

expand

expand(<Object>) - Expands a flattened, dot-notated object to nested object

const flatObj = { foo: 'bar', 'fizz.buzz': 'bizz' }

expand(flatObj) // -> { foo: 'bar', fizz: { buzz: 'bizz' } }

redact

redact(Obj<Object>, <Object{keys<Array>, values<Array>}> - Redacts keys or values on an object literal

const obj = {
  foo: 'bar',
  quz: 'baz',
  fizz: {
    buzz: 'fizz',
    bizz: 'fuzz'
  }
}

redact(obj, { keys: [ 'fizz.bizz' ], values: [ 'baz' ] }) // -> { foo: 'bar', fizz: { buzz: 'fizz' } }

Note: for arrays, you can specify the index explicity: foo.bar[1]... or specify that all keys be affected during redaction with n; foo.bar[n].... This is useful for picking off properties of object nested in arrays

merge

merge(...<Object>) - Performs a deep merge on object parameter(s)

const objOne = { foo: 'bar' }
const objTwo = { fizz: { buzz: 'fizz' } }

merge(objOne, objTwo) // -> { foo: 'bar', fizz: { buzz: 'fizz' } }