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

extra-object

v3.2.0

Published

A collection of methods for working with Objects.

Downloads

339

Readme

A collection of methods for working with Objects. 📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs, 📘 Wiki.

An Object is a collection of properties (entries), each with a name (key) and a value. These properties can be values of any data type, including primitive data types like strings and numbers, as well as more complex data types like other objects. Objects in JavaScript are very similar to objects in other programming languages. They are used to store and organize data, and they can be manipulated and accessed using a variety of built-in methods and operators.

One of the quirks of objects is that they are dynamic, which means that properties can be added, removed, and modified at any time. This can be useful for some types of programming, but it can also make it difficult to keep track of an object's properties and values. Another quirk of JavaScript objects is that they are not strongly typed. This means that the same property can hold values of different data types, and the type of a property's value can change over time. This can make it difficult to ensure the correctness of your code, and it can lead to runtime errors if you are not careful. Despite these quirks, objects are a powerful and versatile tool for organizing and manipulating data in your code. They are an essential part of any program, and they are used in a wide range of applications.

This package includes common set functions related to querying about objects, generating them, comparing one with another, finding their size, adding and removing entries, obtaining its characteristics, getting a part of it, getting subset entries in it, finding an entry in it, performing functional operations, manipulating it in various ways, combining together objects or its entries, of performing set operations upon it.

All functions except from*() take object as 1st parameter. Methods like swap() are pure and do not modify the object itself, while methods like swap$() do modify (update) the object itself.

Stability: Experimental.

const object = require('extra-object');
// import * as object from "extra-object";
// import * as object from "https://unpkg.com/extra-object/index.mjs"; (deno)

var x = {a: 1, b: 2, c: 3, d: 4};
object.swap(x, 'a', 'b');
// → { a: 2, b: 1, c: 3, d: 4 }

var x = {a: 1, b: 2, c: 3, d: 4};
var y = {b: 20, c: 30, e: 50};
object.intersection(x, y);
// → { b: 2, c: 3 }

var x = {a: 1, b: 2, c: 3, d: -2};
object.searchAll(x, v => Math.abs(v) === 2);
// → [ 'b', 'd' ]

var x = {a: 1, b: 2, c: 3};
[...object.subsets(x)];
// → [
// →   {},
// →   { a: 1 },
// →   { b: 2 },
// →   { a: 1, b: 2 },
// →   { c: 3 },
// →   { a: 1, c: 3 },
// →   { b: 2, c: 3 },
// →   { a: 1, b: 2, c: 3 }
// → ]

Index

| Property | Description | | ---- | ---- | | is | Check if value is an object. | | keys | List all keys. | | values | List all values. | | entries | List all key-value pairs. | | | | | fromEntries | Convert entries to object. | | fromLists | Convert lists to object. | | | | | compare | Compare two objects. | | isEqual | Check if two objects are equal. | | | | | size | Get the number of keys in an object. | | isEmpty | Check if an object is empty. | | | | | get | Get value at specified key. | | getAll | Get values at keys. | | getPath | Get value at path in a nested object. | | hasPath | Check if nested object has a path. | | set | Set value at specified key. | | set$ | Set value at specified key. | | setPath$ | Set value at path in a nested object. | | swap | Exchange two values in an object. | | swap$ | Exchange two values in an object. | | remove | Remove an entry from object. | | remove$ | Remove an entry from object. | | removePath$ | Remove value at path in a nested object. | | | | | count | Count values which satisfy a test. | | countAs | Count occurrences of values. | | min | Find smallest value. | | minEntry | Find smallest entry. | | max | Find largest value. | | maxEntry | Find largest entry. | | range | Find smallest and largest values. | | rangeEntries | Find smallest and largest entries. | | | | | head | Gets first entry from object (default order). | | tail | Get object without its first entry (default order). | | take | Keep first n entries only (default order). | | take$ | Keep first n entries only (default order). | | drop | Remove first n entries (default order). | | drop$ | Remove first n entries (default order). | | | | | subsets | List all possible subsets. | | randomKey | Pick an arbitrary key. | | randomEntry | Pick an arbitrary entry. | | randomSubset | Pick an arbitrary subset. | | | | | has | Check if object has a key. | | hasValue | Check if object has a value. | | hasEntry | Check if object has an entry. | | hasSubset | Check if object has a subset. | | find | Find value of an entry passing a test. | | findAll | Find values of entries passing a test. | | search | Find key of an entry passing a test. | | searchAll | Find all keys of entries passing a test. | | searchValue | Find key with a given value. | | searchValueAll | Find keys with a given value. | | | | | forEach | Call a function for each entry. | | some | Check if any value satisfies a test. | | every | Check if all values satisfy a test. | | map | Transform values of an object. | | map$ | Transform values of an object. | | reduce | Reduce values to a single value. | | filter | Keep entries which pass a test. | | filter$ | Keep entries which pass a test. | | filterAt | Get object with given keys. | | filterAt$ | Get object with given keys. | | reject | Discard entries which pass a test. | | reject$ | Discard entries which pass a test. | | rejectAt | Get object without given keys. | | rejectAt$ | Get object without given keys. | | flat | Flatten nested object to given depth. | | flatMap | Flatten nested object, using map function. | | zip | Combine matching entries from objects. | | | | | partition | Segregate entries by test result. | | partitionAs | Segregate entries by similarity. | | chunk | Break object into chunks of given size. | | | | | concat | Combine entries from objects, preferring last. | | concat$ | Combines entries from objects, preferring last. | | join | Join entries together into a string. | | | | | isDisjoint | Check if objects have no common keys. | | unionKeys | Obtain keys present in any object. | | union | Obtain entries present in any object. | | union$ | Obtain entries present in any object. | | intersectionKeys | Obtain keys present in all objects. | | intersection | Obtain entries present in both objects. | | intersection$ | Obtain entries present in both objects. | | difference | Obtain entries not present in another object. | | difference$ | Obtain entries not present in another object. | | symmetricDifference | Obtain entries not present in both objects. | | symmetricDifference$ | Obtain entries not present in both objects. | | cartesianProduct | List cartesian product of objects. |

In the future when you think of just giving up on life, remember that the letter was in your hands, the cab was at the gate, only if you had thought about it once more, your entire life would have been better. (1)

ORG DOI Coverage Status Test Coverage Maintainability