Socket
Socket
Sign inDemoInstall

extra-object

Package Overview
Dependencies
0
Maintainers
1
Versions
245
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    extra-object

A collection of methods for working with Objects.


Version published
Weekly downloads
21
decreased by-92.02%
Maintainers
1
Install size
83.1 kB
Created
Weekly downloads
 

Readme

Source

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

PropertyDescription
isCheck if value is an object.
keysList all keys.
valuesList all values.
entriesList all key-value pairs.
fromEntriesConvert entries to object.
fromListsConvert lists to object.
compareCompare two objects.
isEqualCheck if two objects are equal.
sizeGet the number of keys in an object.
isEmptyCheck if an object is empty.
getGet value at specified key.
getAllGet values at keys.
getPathGet value at path in a nested object.
hasPathCheck if nested object has a path.
setSet value at specified key.
set$Set value at specified key.
setPath$Set value at path in a nested object.
swapExchange two values in an object.
swap$Exchange two values in an object.
removeRemove an entry from object.
remove$Remove an entry from object.
removePath$Remove value at path in a nested object.
countCount values which satisfy a test.
countAsCount occurrences of values.
minFind smallest value.
minEntryFind smallest entry.
maxFind largest value.
maxEntryFind largest entry.
rangeFind smallest and largest values.
rangeEntriesFind smallest and largest entries.
headGets first entry from object (default order).
tailGet object without its first entry (default order).
takeKeep first n entries only (default order).
take$Keep first n entries only (default order).
dropRemove first n entries (default order).
drop$Remove first n entries (default order).
subsetsList all possible subsets.
randomKeyPick an arbitrary key.
randomEntryPick an arbitrary entry.
randomSubsetPick an arbitrary subset.
hasCheck if object has a key.
hasValueCheck if object has a value.
hasEntryCheck if object has an entry.
hasSubsetCheck if object has a subset.
findFind value of an entry passing a test.
findAllFind values of entries passing a test.
searchFind key of an entry passing a test.
searchAllFind all keys of entries passing a test.
searchValueFind key with a given value.
searchValueAllFind keys with a given value.
forEachCall a function for each entry.
someCheck if any value satisfies a test.
everyCheck if all values satisfy a test.
mapTransform values of an object.
map$Transform values of an object.
reduceReduce values to a single value.
filterKeep entries which pass a test.
filter$Keep entries which pass a test.
filterAtGet object with given keys.
filterAt$Get object with given keys.
rejectDiscard entries which pass a test.
reject$Discard entries which pass a test.
rejectAtGet object without given keys.
rejectAt$Get object without given keys.
flatFlatten nested object to given depth.
flatMapFlatten nested object, using map function.
zipCombine matching entries from objects.
partitionSegregate entries by test result.
partitionAsSegregate entries by similarity.
chunkBreak object into chunks of given size.
concatCombine entries from objects, preferring last.
concat$Combines entries from objects, preferring last.
joinJoin entries together into a string.
isDisjointCheck if objects have no common keys.
unionKeysObtain keys present in any object.
unionObtain entries present in any object.
union$Obtain entries present in any object.
intersectionKeysObtain keys present in all objects.
intersectionObtain entries present in both objects.
intersection$Obtain entries present in both objects.
differenceObtain entries not present in another object.
difference$Obtain entries not present in another object.
symmetricDifferenceObtain entries not present in both objects.
symmetricDifference$Obtain entries not present in both objects.
cartesianProductList 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

Keywords

FAQs

Last updated on 14 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc