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-as-array

v1.8.0

Published

Manipulate a javascript object with some of the most used functions in arrays

Downloads

7

Readme

tests npm downloads

Manipulate a javascript object with some of the most used functions in arrays.

Access the complete documentation

Installation

Add the object-as-array package to your project with npm:

npm install object-as-array

Or with yarn:

yarn add object-as-array

Resources

Available resources:

  • Filter: Returns only the elements of the object that satisfy the test function
  • Some: Determines whether one of an object's members satisfies the specified test
  • Every: Determines whether all the members of an object satisfy the specified test
  • ForEach: Performs the specified action for each element in an object
  • ForEachAsync: Performs the specified async action for each element in an object
  • Map: Calls a defined callback function on each element of an object, and returns an array that contains the results.
  • KeysMap: Calls a defined callback function on each element of an object, and returns an object with the same keys that contains the results.
  • Sort: Sorts the position of the object's elements
  • Reduce: Calls the specified callback function for all the elements in an object. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function
  • ReduceRight: Calls the specified callback function for all the elements in an object reversed. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function
  • Slice: Returns a section of an object
  • Omit: Returns the elements that did not have their keys specified
  • Concat: Combines two objects. This method returns a new object without modifying any existing object
  • Reverse: Reverses the position of object elements
  • ToString: Turn object into a string
  • ToArray: Turn object into an array
  • Join: Joins all elements of an object separated by the specified separator string
  • Find: Returns the first element that satisfies the test function or returns null
  • FindLast: Returns the last element that satisfies the test function or returns null
  • KeyOf: Returns the key of the first occurrence of a value in an object or null
  • LastKeyOf: Returns the key of the last occurrence of a value in an object or null
  • ValueOf: Returns the value of an element of an object
  • Data: Original object elements
  • Push: Adds or modifies the original object
  • Length: Number of elements in the original object

Example with Filter Function

Functional programming:

import objectAsArray from "object-as-array";

export default function example() {
    
    const obj = objectAsArray({
        I : 1,
        V : 5,
        X : 10,
        L : 50,
        C : 100,
        D : 500,
        M : 1000
    });

    return obj.filter(v => v > 10 && v < 1000);

    // Result: {L: 50, C: 100, D: 500}

}

Modular programming:

import filter from "object-as-array/filter";

export default function example() {
    
    const obj = {
        I : 1,
        V : 5,
        X : 10,
        L : 50,
        C : 100,
        D : 500,
        M : 1000
    };

    return filter(obj, v => v > 10 && v < 1000);

    // Result: {L: 50, C: 100, D: 500}

}

Author

License

This project is under the MIT license - see the LICENSE file for details.