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

v1.0.5

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

5

Readme

npm version

object-arrarify

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 shallowly, aka, they do not get applied into the inner objects recursively, so you will have to re-apply the module into inner objects if you wish to perform operations on them as-well which is out of the scope of this module but can be done regardless. or you can use the sister of this module(which uses this very module internally) and works recursively.
if you need recursive deep behavior please visit:
https://github.com/vasilevich/object-arrarify-deep

Usage and examples

  • Install.
yarn add object-arrarify
npm install object-arrarify
  • Import/RequireUsage
import objectArrayTools from 'object-arrarify';
  • Actual use examples
    • Assume our object is as follows:
    // Declare the object
    var obj = {
    a:1,
    b:2,
    c:3,
    d:"hello",
    };
    // Apply the objectArrayTools into the object.
    obj=objectArrayTools(obj);  
    • Or for short:
         // Declare the object
    var obj = objectArrayTools({
         a:1,
         b:2,
         c:3,
         d:"hello",
       });
    • Map usage
         // Declare the object
    var result=obj.map((value,key,index) => {
      return key;
    });
    // result will be: {a:"a",b:"b",c:"c",d:"d",...the arrayTools methods}
    • Map Keys usage
         // Declare the object
    var result=obj.mapKeys((value,key,index) => {
      return "test1"+key+"test2";
    });
    // result will be: {test1atest2:"1",test1btest2:"2",test1ctest2:"3",test1dtest2:"hello",...the arrayTools methods}
    • Filter usage
         // Declare the object
    var result=obj.filter((value,key,index) => {
      return key=="a";
    });
    // result will be: {a:"1" ,...the arrayTools methods}
    • mapToArray usage
           // Declare the object
      var result=obj.mapToArray((value,key,index) => {
        return value;
      });
      // result will be: normal array: ["a","b","c",...(all the values in the object)].
    • 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((value,key,index) => {
                         return key=="a";
                     })
                 //  Perform some value mapping logic 
                 .map((value,key,index) => {
                         return key;
                     })
                 .mapKeys((value,key,index) => {
                         return "test1"+key+"test2";
                     })
                 // Convert to an ordinary object without the arrayTools methods which might conflict with other object related tools/code.  
                   .toNormalObject();
    // result will be: {test1atest2:"a", (NO ARRAYTOOLS METHODS)}

Other examples are omitted because the use is pretty much obvious and in par with the usage of ordinary array functions, just look at index.ts to see all the available methods or use type completion in your ide, 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!