.gitea/workflows | ||
.vscode | ||
test | ||
ts | ||
.gitignore | ||
.gitlab-ci.yml | ||
license | ||
npmextra.json | ||
package.json | ||
pnpm-lock.yaml | ||
readme.hints.md | ||
readme.md | ||
tsconfig.json |
# @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.