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

kickstart-chainable-object

v1.1.0

Published

Chainable methods to the Object

Downloads

7

Readme

kickstart-chainable-object GitHub license

A function that extends Object with chainable methods.

More functionality to the "simple" Object, but only with chainable methods (with one exception - forEach method). Don't expect for functions which are not chainable, i.e. methods which won't return an object.

Installation

npm install kickstart-chainable-object

Usage

import _O from 'kickstart-chainable-object';

const obj = { a: 1, b: 2, c: 3 }

_O(obj)
  .mapValues(v => v * 2) // { a: 2, b: 4, c: 6, ... }
  .mapKeys(k => k.toUpperCase()) // { A: 2, B: 4, C: 6, ... }
  .map((key, val) => [key + key, val + 10]) // { AA: 12, BB: 14, CC: 16, ... }
  .val() // { AA: 12, BB: 14, CC: 16 }

API

**All the APIs (except forEach) returns a new object

concat

Similar to Array.prototype.concat.

The concat method merges two or more objects.

Args: one or more objects

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: { c: 3 } }).concat({ a: 2, d: 4 }) // { a: 1, b: { c: 3 }, d: 4 }

filter

Similar to Array.prototype.concat.

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: { c: 3 } }).filter(v => v > 0) // { a: 1 }

forEach

Similar to Array.prototype.concat.

The ONLY function which returns void.

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: { c: 3 } }).forEach((val, key) => {
  // do something
})

log

Simple, console.log for debugging

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: { c: 3 } }).log() // { a: 1, b: { c: 3 } }

map

Map through the object replacing key-value pairs.

Args: cb: (key, value) => [key: string | number | symbol, value: any]

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: 2 }).map((key, val) => [key.toUpperCase(), val * 2]) // { A: 2, B: 4 }

mapKeys

Map through the object replacing keys.

Args: cb: (key, value) => string | number | symbol

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: 2 }).mapKeys(k => k.toUpperCase()) // { A: 1, B: 2 }

mapValues

Map through the object replacing values.

Args: cb: (value, key) => any

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: 2 }).mapKeys(v => v * 2) // { a: 2, b: 4 }

remove

Remove elements from the object

Args: ((value, key) => boolean)

import _O from 'kickstart-chainable-object';

_O({ a: 1, b: 2 })
  .remove((key, val) => val > 1) // { a: 1 }
  .remove((key, val) => key === "b") // { }

val

Returns the object literal without ChainableObject methods

import _O from 'kickstart-chainable-object';

for (const key in _O({ a: 1 })) console.log(key) // a, log, map, forEach ...
for (const key in _O({ a: 1 }).val()) console.log(key) // a