Modules@robinpath/collection

@robinpath/collection

0.1.0Public

Array and collection manipulation utilities: filtering, sorting, grouping, aggregation, and set operations

@robinpath/collection

Array and collection manipulation utilities: filtering, sorting, grouping, aggregation, and set operations

Category Functions Auth License

Why use this module?

The collection module lets you:

  • Extract a single property value from each object in an array
  • Filter array to items where a property equals a given value
  • Filter array to items where a numeric property is greater than a value
  • Filter array to items where a numeric property is less than a value
  • Filter array to items where a numeric property is greater than or equal to a value

All functions are callable directly from RobinPath scripts with a simple, consistent API.

Installation

npm install @robinpath/collection

Quick Start

No credentials needed — start using it right away:

collection.where $arr "age" 25

Available Functions

FunctionDescription
collection.pluckExtract a single property value from each object in an array
collection.whereFilter array to items where a property equals a given value
collection.whereGtFilter array to items where a numeric property is greater than a value
collection.whereLtFilter array to items where a numeric property is less than a value
collection.whereGteFilter array to items where a numeric property is greater than or equal to a value
collection.whereLteFilter array to items where a numeric property is less than or equal to a value
collection.whereNotFilter array to items where a property does not equal a given value
collection.sortBySort an array of objects by a property in ascending order
collection.sortByDescSort an array of objects by a property in descending order
collection.uniqueRemove duplicate values from an array
collection.flattenFlatten nested arrays by one level
collection.reverseReverse the order of elements in an array
collection.chunkSplit an array into chunks of a given size
collection.firstGet the first element of an array
collection.lastGet the last element of an array
collection.countCount the number of elements in an array
collection.sumSum numeric values in an array, optionally by a property name
collection.avgCalculate the average of numeric values in an array, optionally by a property name
collection.minFind the minimum numeric value in an array, optionally by a property name
collection.maxFind the maximum numeric value in an array, optionally by a property name
collection.groupByGroup array items by a property value
collection.compactRemove all falsy values (null, undefined, false, 0, empty string) from an array
collection.zipZip two arrays together into an array of pairs
collection.differenceGet elements that are in the first array but not in the second
collection.intersectionGet elements that exist in both arrays
collection.unionCombine two arrays into one with unique elements
collection.takeTake the first N elements from an array
collection.skipSkip the first N elements of an array
collection.containsCheck if an array contains a specific value
collection.indexOfFind the index of a value in an array

Examples

Filter array to items where a property equals a given value

collection.where $arr "age" 25

Filter array to items where a numeric property is greater than a value

collection.whereGt $arr "age" 25

Filter array to items where a numeric property is less than a value

collection.whereLt $arr "age" 25

Integration with RobinPath

import { RobinPath } from "@wiredwp/robinpath";
import Module from "@robinpath/collection";

const rp = new RobinPath();
rp.registerModule(Module.name, Module.functions);
rp.registerModuleMeta(Module.name, Module.functionMetadata);

const result = await rp.executeScript(`
  collection.where $arr "age" 25
`);

Full API Reference

See MODULE.md for complete documentation including all parameters, return types, error handling, and advanced examples.

Related Modules

License

MIT

Versions (1)

VersionTagPublished
0.1.0latestyesterday
Install
$ robinpath install @robinpath/collection
Version0.1.0
LicenseMIT
Unpacked Size10.5 KB
Versions1
Weekly Downloads0
Total Downloads0
Stars0
Last Publishyesterday
Createdyesterday

Category

utilities