Compare commits

...

15 Commits

Author SHA1 Message Date
52396913c7 1.1.0 2025-01-04 13:11:59 +01:00
7b3965ab2b feat(core): Add concurrent processing support 2025-01-04 13:11:58 +01:00
e0a9030bcd update description 2024-05-29 14:11:48 +02:00
809b5d0b62 1.0.8 2024-04-27 08:12:29 +02:00
92e251b8d4 fix(core): update 2024-04-27 08:12:29 +02:00
ff920f89f0 1.0.7 2024-04-26 15:36:26 +02:00
795c7231eb fix(core): update 2024-04-26 15:36:25 +02:00
2a9f1622a5 1.0.6 2024-04-26 14:05:49 +02:00
cbfe7927e7 fix(core): update 2024-04-26 14:05:48 +02:00
d608aa81a8 update tsconfig 2024-04-14 17:20:59 +02:00
b9c828f092 update npmextra.json: githost 2024-04-01 21:33:50 +02:00
4635d0b941 update npmextra.json: githost 2024-04-01 19:57:41 +02:00
50eed923b3 update npmextra.json: githost 2024-03-30 21:46:37 +01:00
a197cdbc96 1.0.5 2023-08-02 20:55:23 +02:00
17271eddf9 fix(core): update 2023-08-02 20:55:22 +02:00
12 changed files with 7776 additions and 3452 deletions

View File

@ -119,6 +119,6 @@ jobs:
run: | run: |
npmci node install stable npmci node install stable
npmci npm install npmci npm install
pnpm install -g @gitzone/tsdoc pnpm install -g @git.zone/tsdoc
npmci command tsdoc npmci command tsdoc
continue-on-error: true continue-on-error: true

View File

@ -121,7 +121,7 @@ pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @git.zone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command tsdoc

29
changelog.md Normal file
View File

@ -0,0 +1,29 @@
# Changelog
## 2025-01-04 - 1.1.0 - feat(core)
Add concurrent processing support
- Introduced ConcurrentProcessor class for handling asynchronous operations with a concurrency limit.
## 2024-05-29 - 1.0.8 - Documentation
Updated project description for clarity and accuracy.
- Enhanced documentation details in the project description.
## 2024-04-01 to 2024-04-27 - 1.0.5 to 1.0.7 - Maintenance and Configuration Updates
Multiple updates focusing on configuration and core functionality.
- Updated `tsconfig` for improved TypeScript setup.
- Refined `npmextra.json` to configure `githost`.
- Applied numerous core functionality enhancements and fixes.
## 2023-07-10 to 2023-08-02 - 1.0.3 to 1.0.4 - Organizational Changes and Fixes
Transition to new organizational structure and related updates.
- Implemented a new organizational scheme for the project.
- Applied essential fixes to core components ensuring stability.
## 2021-06-29 to 2021-06-30 - 1.0.1 to 1.0.2 - Core Fixes
Addressed core system updates and enhancements.
- Implemented bug fixes to enhance core functionality.

View File

@ -2,17 +2,32 @@
"gitzone": { "gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartarray", "gitrepo": "smartarray",
"description": "a package exposing async manipulation for arrays", "description": "A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.",
"npmPackagename": "@push.rocks/smartarray", "npmPackagename": "@push.rocks/smartarray",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks",
"keywords": [
"TypeScript",
"asynchronous programming",
"array manipulation",
"array mapping",
"array filtering",
"deduplication",
"async/await",
"software development",
"npm package",
"open source"
]
} }
}, },
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis 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. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n"
} }
} }

View File

@ -1,8 +1,8 @@
{ {
"name": "@push.rocks/smartarray", "name": "@push.rocks/smartarray",
"version": "1.0.4", "version": "1.1.0",
"private": false, "private": false,
"description": "a package exposing async manipulation for arrays", "description": "A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
@ -13,12 +13,12 @@
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.66", "@git.zone/tsbuild": "^2.2.0",
"@gitzone/tsbundle": "^2.0.8", "@git.zone/tsbundle": "^2.1.0",
"@gitzone/tsrun": "^1.2.44", "@git.zone/tsrun": "^1.3.3",
"@gitzone/tstest": "^1.0.77", "@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.12", "@push.rocks/tapbundle": "^5.5.4",
"@types/node": "^20.4.5" "@types/node": "^22.10.5"
}, },
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
@ -35,5 +35,22 @@
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
], ],
"type": "module" "type": "module",
"keywords": [
"TypeScript",
"asynchronous programming",
"array manipulation",
"array mapping",
"array filtering",
"deduplication",
"async/await",
"software development",
"npm package",
"open source"
],
"homepage": "https://code.foss.global/push.rocks/smartarray",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartarray.git"
}
} }

10930
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

140
readme.md
View File

@ -1,37 +1,125 @@
# @push.rocks/smartarray # @push.rocks/smartarray
a package exposing async manipulation for arrays
## Availabililty and Links A library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartarray)
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartarray)
* [github.com (source mirror)](https://github.com/push.rocks/smartarray)
* [docs (typedoc)](https://push.rocks.gitlab.io/smartarray/)
## Status for master ## Install
Status Category | Status Badge To install `@push.rocks/smartarray` in your project, run the following command:
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartarray/badges/master/pipeline.svg)](https://lossless.cloud) ```bash
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartarray/badges/master/coverage.svg)](https://lossless.cloud) npm install @push.rocks/smartarray --save
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartarray)](https://lossless.cloud) ```
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartarray)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) Make sure you have Node.js and npm installed beforehand.
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartarray)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartarray)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartarray)](https://lossless.cloud)
## Usage ## Usage
Use TypeScript for best in class intellisense 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.
## Contribution ### Importing the Library
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) 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:
For further information read the linked docs at the top of this readme. ```typescript
import { map, filter, deduplicate } from '@push.rocks/smartarray';
```
## Legal ### Async Map: Transforming Arrays
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) 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
```typescript
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
```typescript
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
```typescript
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.
```typescript
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 youre 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](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.

View File

@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @push.rocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartarray', name: '@push.rocks/smartarray',
version: '1.0.4', version: '1.1.0',
description: 'a package exposing async manipulation for arrays' description: 'A TypeScript library for enhancing array manipulation with asynchronous operations such as mapping, filtering, and deduplication.'
} }

View File

@ -0,0 +1,35 @@
export class ConcurrentProcessor<T> {
private asyncFunction: (item: T) => Promise<void>;
private concurrencyLimit: number;
constructor(asyncFunction: (item: T) => Promise<void>, concurrencyLimit: number) {
this.asyncFunction = asyncFunction;
this.concurrencyLimit = concurrencyLimit;
}
async process(items: T[]): Promise<void> {
const queue: Array<Promise<void>> = [];
let totalProcessed = 0;
for (const item of items) {
const promise = this.asyncFunction(item).then(() => {
totalProcessed++;
if (totalProcessed % 10000 === 0) {
console.log(`${totalProcessed} items processed.`);
}
// Remove the completed promise from the queue
queue.splice(queue.indexOf(promise), 1);
});
queue.push(promise);
// Wait if the number of promises exceeds the concurrency limit
if (queue.length >= this.concurrencyLimit) {
await Promise.race(queue);
}
}
// Wait for the remaining promises to resolve
await Promise.all(queue);
}
}

View File

@ -1,3 +1,19 @@
export * from './classes.concurrentprocessor.js';
export const map = async <T = any, R = any>(
arrayArg: T[],
mapFunction: (itemArg: T) => Promise<R>
): Promise<R[]> => {
const returnArray: R[] = [];
for (const itemArg of arrayArg) {
const mapResult = await mapFunction(itemArg);
if (mapResult !== undefined) {
returnArray.push(mapResult);
}
}
return returnArray;
};
export const filter = async <T>( export const filter = async <T>(
arrayArg: T[], arrayArg: T[],
filterFunction: (itemArg: T) => Promise<boolean> filterFunction: (itemArg: T) => Promise<boolean>

View File

@ -3,9 +3,12 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true
} },
"exclude": [
"dist_*/**/*.d.ts"
]
} }