GithubHelp home page GithubHelp logo

guilhermeasn / object-as-array Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 815 KB

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

Home Page: https://guilhermeasn.github.io/object-as-array/

License: MIT License

TypeScript 97.41% JavaScript 0.46% PowerShell 1.21% Shell 0.92%
object array javascript functional typescript

object-as-array's Introduction

object-as-array

tests npm downloads

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

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.

object-as-array's People

Contributors

guilhermeasn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.