Package Exports
- extra-object.web
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 set 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.
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)
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 }
// → ]reference
| Method | Action |
|---|---|
| size | Gets size of object. |
| head | Gets first entry. |
| take | Keeps first n entries only. |
| shift | Removes first entry. |
| fromEntries | Creates object from entries. |
| concat | Combines entries from objects, preferring last. |
| flat | Flattens nested object to given depth. |
| chunk | Breaks object into chunks of given size. |
| filterAt | Gets object with given keys. |
| map | Updates values based on map function. |
| filter | Keeps entries which pass a test. |
| reduce | Reduces values to a single value. |
| range | Finds smallest and largest entries. |
| count | Counts values which satisfy a test. |
| partition | Segregates values by test result. |
| cartesianProduct | Lists cartesian product of objects. |
| some | Checks if any value satisfies a test. |
| zip | Combines entries from objects. |
| union | Gives entries present in any object. |
| intersection | Gives entries present in both objects. |
| difference | Gives entries of object not present in another. |
| symmetricDifference | Gives entries not present in both objects. |
| isDisjoint | Checks if objects have no common keys. |
| key | Picks an arbitrary key. |
| value | Picks an arbitrary value. |
| entry | Picks an arbitrary entry. |
| subset | Picks an arbitrary subset. |
| isEmpty | Checks if object is empty. |
| isEqual | Checks if two objects are equal. |
| compare | Compares two objects. |
| find | Finds value of an entry passing a test. |
| search | Finds key of an entry passing a test. |
| scanWhile | Finds key of first entry not passing a test. |