A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.
Go to file
2024-04-26 15:36:25 +02:00
.gitea/workflows fix(core): update 2024-04-26 14:05:48 +02:00
.vscode fix(core): update 2023-08-02 14:39:58 +02:00
test fix(core): update 2023-08-02 14:39:58 +02:00
ts fix(core): update 2024-04-26 15:36:25 +02:00
.gitignore fix(core): update 2021-06-29 20:41:15 +02:00
.gitlab-ci.yml fix(core): update 2024-04-26 14:05:48 +02:00
license fix(core): update 2021-06-29 20:41:15 +02:00
npmextra.json fix(core): update 2024-04-26 15:36:25 +02:00
package.json fix(core): update 2024-04-26 15:36:25 +02:00
pnpm-lock.yaml fix(core): update 2024-04-26 14:05:48 +02:00
readme.hints.md update tsconfig 2024-04-14 17:20:59 +02:00
readme.md fix(core): update 2024-04-26 15:36:25 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:33:50 +02:00

# @push.rocks/smartarray
a package exposing async manipulation for arrays

## Install
To add `@push.rocks/smartarray` to your project, run the following command:

```bash
npm install @push.rocks/smartarray --save

This will install the package and add it to your project's dependencies. Ensure you have Node.js and npm installed on your machine before running this command.

Usage

@push.rocks/smartarray is designed to enhance array manipulation with asynchronous operations in TypeScript. Below, we explore various functionalities provided by the package, including mapping, filtering, and deduplication, with a focus on their asynchronous nature.

Getting Started

To use @push.rocks/smartarray, first import the functionalities you require:

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

Mapping Arrays Asynchronously

The map function allows you to apply an asynchronous function to each item in an array and collect the results.

Example:

const numbers = [1, 2, 3];
const doubledNumbers = await map(numbers, async (number) => {
  return number * 2;
});
console.log(doubledNumbers); // [2, 4, 6]

Filtering Arrays Asynchronously

You can asynchronously decide which items to keep in an array using the filter function.

Example:

const userIds = [1, 2, 3, 4];
const activeUserIds = await filter(userIds, async (userId) => {
  // Let's assume isActiveUser is an async function returning a boolean
  return isActiveUser(userId);
});
console.log(activeUserIds); // Assuming users 1, 3, and 4 are active: [1, 3, 4]

Deduplicating Arrays Asynchronously

Deduplicate an array based on a unique key derived asynchronously from each element using the deduplicate function.

Example:

const users = [
  { id: 1, email: 'user1@example.com' },
  { id: 2, email: 'user2@example.com' },
  { id: 1, email: 'user1@example.com' } // Duplicate based on 'id'
];
const uniqueUsers = await deduplicate(users, async (user) => {
  return user.id;
});
console.log(uniqueUsers);
// Output: [{ id: 1, email: 'user1@example.com' }, { id: 2, email: 'user2@example.com' }]

These examples underline the versatility and power of @push.rocks/smartarray in handling arrays with asynchronous operations, making it easier to integrate asynchronous logic into array manipulation tasks. Remember to handle asynchronous operations with async/await syntax to maintain clear and comprehensible code.


## 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](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 hello@task.vc.

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.