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

fonctional-object

v1.1.0

Published

Adds fonctional methods on the objects and some useful methods on objects and arrays.

Downloads

2

Readme

codecov

Fonctional Object

This module adds functional methods and some useful methods on objects and arrays. Each function can be rewritten so as not to block any other library. It is also important to indicate that no method uses another method defined by this library other than itself.

Installing

Install the package with npm :

npm install fonctional-object --save

Import the package in your project :

require("fonctional-object");

The methods are directly added to the prototypes of Object and Array.

Summary of methods

Callback

entryCallbackArray

entryCallbackArray (value, key, array)

Params :

  • value (*) - The current value of the array entry.
  • key (Number) - The current key of the array entry.
  • array (Array) - The array that contains the value.

entryCallbackObject

entryCallbackObject (value, key, object)

Params :

  • value (*) - The current value of the object entry.
  • key (Number) - The current key of the object entry.
  • object (Object) - The object that contains the value.

Array methods

clone

const array = [10, "test"];
const clone = array.clone ();

array[0] = 20;

// Value of array and clone at this point :
// array : [20, "test"]
// clone : [10, "test"]

Create a deep clone of the array.

Returns : Array

toObject

const key = (v) => v;
const value = (v, k) => k;

const array = [10, "test"];
const object = array.toObject(key, value) // {"10": 0, "test": 1}

Transforms the array into an object.

Params :

  • key (entryCallbackArray) - A callback that give the key.
  • value (entryCallbackArray) [optional] - A callback that give the value. The default value return simply the value of the entry.

Returns : Object

Object methods

clone

const object = {test: 10};
const clone = object.clone();

object.test = "hello";

// The value of object and clone at this point :
// object : {test: "hello"}
// clone : {test: 10}

Create a deep clone of the object.

Returns : Object

every

const object = {test: 10, hello: 20};
const success = object.every((value) => value >= 10); // True
const failure = object.every((value) => value >= 20); // False

Check if each entry of an object respect a callback.

Params :

  • callback (entryCallbackObject) - The callback for each entry of the object.
  • thisArg [Optional] - The value for this in the callback.

Returns : Boolean

find

const object = {test: {hello: 10}};
const num = object.find("test.hello"); // 10
const und = object.find("test.good"); // Undefined

Finds an element in the object. Use a dot for the recursion.

Params :

  • key (String) - The key of the element.

Returns : *

forEach

const num = 0;
const object = {test: 10, hello: 20};

object.forEach((value, key) => num += value + key.length);
// At this point, num = 39

Execute a callback on each entry of the object.

Params :

  • callback (entryCallbackObject) - The callback for each entry of the object.
  • thisArg [Optional] - The value for this in the callback.

has

const object = {test: {hello: 10}};
const num = object.find("test.hello"); // True
const und = object.find("test.good"); // False

Check the existence of an element in the object. Use a dot for the recursion.

Params :

  • key (String) - The key of the element.

Returns : Boolean

isEmpty

const object_1 = {};
const object_2 = {test: 10};

object_1.isEmpty // True
object_2.isEmpty // False

Indicates if the object is empty or not. It's not a function.

length

const object_1 = {};
const object_2 = {test: 10};

object_1.length // 0
object_2.length // 1

Gets the number of element in the object. It's not a function.

map

const key = (value) => value;
const value = (value, key) => key;

const object = {test: "t", hello: "h"};
const obj = object.map(value, key); // {t: "test", h: "hello"}

Create a new object from this object.

Params :

  • value (entryCallbackObject) - The callback for the key.
  • key (entryCallbackObject) [optional] - The callback for the key. The default value return simply the key of the entry.
  • thisArgValue [Optional] - The value for this in the value callback.
  • thisArgKey [Optional] - The value for this in the key callback.

Returns : Object

some

const object = {test: 10, hello: 20};
const success = object.some((value) => value >= 20); // True
const failure = object.some((value) => value >= 30); // False

Check if at least one entry of an object respect a callback.

Params :

  • callback (entryCallbackObject) - The callback for each entry of the object.
  • thisArg [Optional] - The value for this in the callback.

Returns : Boolean

Versions

1.1.0

This version defines the filter method for objects as well as the possibility to specify a value for this for every, some, map, forEach and filter methods.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.