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

arachnea

v0.0.9

Published

A simple api to perform array operations in a single loop

Downloads

8

Readme

arachnea

arachnea is a JavaScript library that allows you to perform efficient array operations using a fluent API approach inspired by the agility and efficiency of spiders.

Features

  • Map: Transform each element of an array using a provided function.
  • Filter: Filter elements of an array based on a provided condition.
  • Reduce: Reduce an array to a single value based on a provided accumulator and transformation function.
  • Find: Find the first element in the array that meets the given condition.
  • Remove: Remove the first element in the array that meets the given condition.
  • ForEach: Execute a provided function once for each array element.

Installation

You can install arachnea via npm or yarn:

npm install arachnea

# or yarn

yarn add arachnea

Usage

Basic Usage

import arachnea from "arachnea";

const numbers = [1, 2, 3, 4, 5];

arachnea(numbers).forEach((num) => {
  console.log(num * 2); // Example of using forEach
});

API Examples

Mapping and Reducing

const sumOfSquares = arachnea(numbers)
  .map((num) => num * num)
  .reduce((acc, num) => acc + num, 0);

console.log(sumOfSquares); // Output: 55

Filtering and Collecting

const oddNumbers = arachnea(numbers)
  .filter((num) => num % 2 !== 0)
  .collect();

console.log(oddNumbers); // Output: [1, 3, 5]

Removing Elements

const remove4 = arachnea(numbers)
  .map((num) => num * num)
  .remove(4)
  .collect();

console.log(remove4); // Output: [1, 9, 16, 25]

Finding Elements

const greaterThanTwentyFour = arachnea(numbers)
  .map((num) => num * num)
  .find((num) => num > 24);

console.log(greaterThanTwentyFour); // Output: 25

Chaining Operations

const result = arachnea(numbers)
  .filter((num) => num > 2)
  .map((num) => num * 3)
  .reduce((acc, num) => acc + num, 0);

console.log(result); // Output: 39

API

map(transformer: (element: T) => K): Stream<K>

Transforms each element of the array using the provided transformer function.

filter(condition: (element: T) => boolean): Stream<T>

Filters elements of the array based on the provided boolean condition function.

reduce(reducer: (accumulator: K, element: T) => K, initialValue: K): K

Reduces the array to a single value using the provided reducer function and initial value.

remove(condition: (element: T) => boolean | T): Stream<T>

Removes the first element in the array that meets the given condition or is equal to the given parameter.

find(condition: (element: T) => boolean | T): T

Finds the first element in the array that meets the given condition or is equal to the given parameter.

forEach(action: (element: T) => void): void

Executes a provided function once for each array element.

collect(): Array<T>

Collects the elements after applying all transformations and filters, returning them as an array.

Todo

  • Combine successive filter operations into a single operation.
  • Document actionsLoop for custom terminating operation injection.
  • Improve the performance of atomic operations.
  • Add sorting, flattening functionality.
  • Enhance performance optimizations.
  • Implement error handling for edge cases.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.