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

@push.rocks/smartarray

v1.0.8

Published

A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.

Downloads

145

Readme

@push.rocks/smartarray

A library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.

Install

To install @push.rocks/smartarray in your project, run the following command:

npm install @push.rocks/smartarray --save

Make sure you have Node.js and npm installed beforehand.

Usage

The @push.rocks/smartarray library is designed to facilitate asynchronous array operations in TypeScript projects. It simplifies tasks like mapping, filtering, and deduplication by embracing async/await patterns, making it an invaluable tool for modern JavaScript development. Below, we delve into the capabilities of this library, providing comprehensive examples to illustrate its use in a variety of scenarios.

Importing the Library

Before you can utilize the library's functions, you need to import them into your TypeScript files. Depending on your use case, you can import specific functions or the entire library:

import { map, filter, deduplicate } from '@push.rocks/smartarray';

Async Map: Transforming Arrays

The map function lets you apply an asynchronous operation to each item in an array, constructing a new array with the transformed items.

Example: Doubling Numbers

const numbers = [1, 2, 3, 4];
const doubleNumbers = await map(numbers, async (number) => number * 2);
console.log(doubleNumbers); // Output: [2, 4, 6, 8]

Async Filter: Conditional Array Traversal

With the filter function, you can asynchronously judge whether to keep or remove items from the array.

Example: Filtering Even Numbers

const numbers = [1, 2, 3, 4, 5, 6];
const evenNumbers = await filter(numbers, async (number) => number % 2 === 0);
console.log(evenNumbers); // Output: [2, 4, 6]

Async Deduplicate: Removing Duplication

The deduplicate function excels in removing duplicates from an array based on asynchronously derived unique keys for each element.

Example: Deduplicating User Array

const users = [
  { id: 1, name: 'John' },
  { id: 2, name: 'Jane' },
  { id: 1, name: 'John' }
];
const deduplicatedUsers = await deduplicate(users, async (user) => user.id);
console.log(deduplicatedUsers);
// Output: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]

Deep-Dive Use Cases

Complex Data Transformation

Imagine you're working with a dataset of user objects fetched from an API, and you need to perform several transformations: filter out inactive users, double the user IDs for a new report, and ensure the list is deduplicated based on usernames.

import { map, filter, deduplicate } from '@push.rocks/smartarray';

// Example users array
const users = [
  { id: 1, active: true, username: 'user1' },
  { id: 2, active: false, username: 'user2' },
  { id: 3, active: true, username: 'user3' },
  { id: 1, active: true, username: 'user1' } // Duplicate for demonstration
];

// First, filter out inactive users
const activeUsers = await filter(users, async (user) => user.active);

// Next, transform the user IDs
const transformedUsers = await map(activeUsers, async (user) => ({
  ...user,
  id: user.id * 2
}));

// Finally, deduplicate based on usernames
const uniqueUsers = await deduplicate(transformedUsers, async (user) => user.username);

console.log(uniqueUsers);

This example demonstrates @push.rocks/smartarray's power in handling complex, asynchronous data operations in an efficient, readable manner. By chaining these methods, you can achieve sophisticated data manipulation objectives with minimal code.

Conclusion

@push.rocks/smartarray significantly simplifies the development experience when working with arrays in asynchronous environments. It not only enhances readability and maintainability but also ensures that your codebase remains scalable and efficient. By integrating this library into your projects, you unlock a higher level of programming paradigm where array manipulations are no longer a chore but a streamlined process.

For developers aiming to harness the full potential of asynchronous operations in TypeScript, @push.rocks/smartarray offers a comprehensive, easy-to-use solution that stands out for its performance and versatility. Whether you’re mapping, filtering, or deduplicating arrays, this library empowers you to write cleaner, more efficient code, elevating your development workflow to new heights.

License and Legal Information

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at [email protected].

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.