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

object-arrarify-deep

v1.0.1

Published

A npm module which converts an ordinary object into an object with various tools which natively are found within an array, such as map, filter, find, forEach, and more, all behave similar to the native array version however, instead of index, it provides

Downloads

2

Readme

npm version

object-arrarify-deep

A npm module which converts an ordinary object into an object with various methods which natively are found within an Array,
such as map, filter, find, forEach, and more, all behave similar to the native array version however, instead of index,
it provides key(second param), and index(third param).

This module was mainly made to help you use an object in the same way you would use an array, while saving you the struggle of using complex methods such as reduce, or writing your own for var ..in loops from scratch, and thus achieving the desired Declarative Programming pattern which is arguably preferred by many over the sometimes longer and harder to read Imperative way.

NOTE: the methods are working deeply, recursively, aka, they do get applied into the inner objects recursively, if you wish to get the original shallow behavior, please check the project
which predated, and is depended upon:
https://github.com/vasilevich/object-arrarify

Usage and examples

  • Install.
yarn add object-arrarify-deep
npm install object-arrarify-deep
  • Import/Require Usage
import objectArrayDeepTools from 'object-arrarify-deep';
  • Actual use examples
    • Assume our object is as follows:
    // Declare the object
    var obj = {
        a: 1,
        b: 2,
        c: 3,
        d: "hello",
        e: {a: 2},
    };
    // Apply the objectArrayTools into the object.
    obj=objectArrayDeepTools(obj);  
    • Or for short:
         // Declare the object
    var obj = objectArrayDeepTools({
                                       a: 1,
                                       b: 2,
                                       c: 3,
                                       d: "hello",
                                       e: {a: 2},
                                   });
    • Map usage
         // Declare the object
    var result=obj.map((key,value,index) => {
      return key;
    });
    // result will be: {a:"a",b:"b",c:"c",d:"d","e":"e",...the arrayTools methods}
    • Filter usage
         // Declare the object
    var result=obj.filter((key,value,index) => {
      return key=="a";
    });
    // result will be: {a:"1" ,...the arrayTools methods}
    • toNormalObject usage
         // Declare the object
    var result=obj.toNormalObject();
    // result will be: the original object, without the methods which were applied by the objectArrayTools.
    • Real world use example and the reason this module was created in the first place.
         // Declare the object
    var result=obj
                 // Perform some filtering logic
                 .filter((key,value,index) => {
                         return key=="a";
                     })
                 //  Perform some value mapping logic 
                 .map((key,value,index) => {
                         return key;
                     })
                 // Convert to an ordinary object without the arrayTools methods which might conflict with other object related tools/code.  
                   .toNormalObject();
    // result will be: {a:"a", (NO ARRAYTOOLS METHODS)}

Other examples are omitted becaus the use is pretty much obvious and in par with the usage of ordinary array functions, including find and forEach, feel free to make a pull request with a more detailed readme.

License

The license chosen for this project can be found inside package.json: MIT

Hopefully this module will save you a little bit of time, have fun and best of luck!