Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff920f89f0 | |||
795c7231eb | |||
2a9f1622a5 | |||
cbfe7927e7 | |||
d608aa81a8 | |||
b9c828f092 | |||
4635d0b941 | |||
50eed923b3 |
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -2,17 +2,31 @@
|
|||||||
"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 library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.",
|
||||||
"npmPackagename": "@push.rocks/smartarray",
|
"npmPackagename": "@push.rocks/smartarray",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks",
|
||||||
|
"keywords": [
|
||||||
|
"asynchronous array operations",
|
||||||
|
"typescript library",
|
||||||
|
"array filtering",
|
||||||
|
"array mapping",
|
||||||
|
"array deduplication",
|
||||||
|
"async/await",
|
||||||
|
"npm package",
|
||||||
|
"modern JavaScript development",
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
25
package.json
25
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartarray",
|
"name": "@push.rocks/smartarray",
|
||||||
"version": "1.0.5",
|
"version": "1.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a package exposing async manipulation for arrays",
|
"description": "A library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.",
|
||||||
"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,10 +13,10 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsbundle": "^2.0.8",
|
"@git.zone/tsbundle": "^2.0.8",
|
||||||
"@gitzone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@gitzone/tstest": "^1.0.77",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"@push.rocks/tapbundle": "^5.0.12",
|
"@push.rocks/tapbundle": "^5.0.12",
|
||||||
"@types/node": "^20.4.6"
|
"@types/node": "^20.4.6"
|
||||||
},
|
},
|
||||||
@ -35,5 +35,16 @@
|
|||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"type": "module"
|
"type": "module",
|
||||||
|
"keywords": [
|
||||||
|
"asynchronous array operations",
|
||||||
|
"typescript library",
|
||||||
|
"array filtering",
|
||||||
|
"array mapping",
|
||||||
|
"array deduplication",
|
||||||
|
"async/await",
|
||||||
|
"npm package",
|
||||||
|
"modern JavaScript development",
|
||||||
|
"open source"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
2652
pnpm-lock.yaml
generated
2652
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
108
readme.md
108
readme.md
@ -1,37 +1,95 @@
|
|||||||
|
```markdown
|
||||||
# @push.rocks/smartarray
|
# @push.rocks/smartarray
|
||||||
a package exposing async manipulation for arrays
|
a package exposing async manipulation for arrays
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartarray)
|
To add `@push.rocks/smartarray` to your project, run the following command:
|
||||||
* [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
|
```bash
|
||||||
|
npm install @push.rocks/smartarray --save
|
||||||
|
```
|
||||||
|
|
||||||
Status Category | Status Badge
|
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.
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
|
||||||
npm | [](https://lossless.cloud)
|
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense
|
`@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.
|
||||||
|
|
||||||
## Contribution
|
### Getting Started
|
||||||
|
|
||||||
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). :)
|
To use `@push.rocks/smartarray`, first import the functionalities you require:
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
```typescript
|
||||||
|
import { map, filter, deduplicate } from '@push.rocks/smartarray';
|
||||||
|
```
|
||||||
|
|
||||||
## Legal
|
### Mapping Arrays Asynchronously
|
||||||
> 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 allows you to apply an asynchronous function to each item in an array and collect the results.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
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:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
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:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
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.
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartarray',
|
name: '@push.rocks/smartarray',
|
||||||
version: '1.0.5',
|
version: '1.0.7',
|
||||||
description: 'a package exposing async manipulation for arrays'
|
description: 'A library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.'
|
||||||
}
|
}
|
||||||
|
14
ts/index.ts
14
ts/index.ts
@ -1,3 +1,17 @@
|
|||||||
|
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>
|
||||||
|
@ -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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user