Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff920f89f0 | |||
795c7231eb | |||
2a9f1622a5 | |||
cbfe7927e7 | |||
d608aa81a8 | |||
b9c828f092 | |||
4635d0b941 | |||
50eed923b3 | |||
a197cdbc96 | |||
17271eddf9 | |||
c3f1f373e5 | |||
64557a8ac3 | |||
9c5cc17968 | |||
d5ae1ff92d |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
@ -121,7 +121,7 @@ pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci command npm install -g @git.zone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -2,17 +2,31 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartarray",
|
||||
"shortDescription": "a package exposing async manipulation for arrays",
|
||||
"npmPackagename": "@pushrocks/smartarray",
|
||||
"description": "A library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.",
|
||||
"npmPackagename": "@push.rocks/smartarray",
|
||||
"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": {
|
||||
"npmGlobalTools": [],
|
||||
"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"
|
||||
}
|
||||
}
|
25520
package-lock.json
generated
25520
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -1,24 +1,24 @@
|
||||
{
|
||||
"name": "@pushrocks/smartarray",
|
||||
"version": "1.0.3",
|
||||
"name": "@push.rocks/smartarray",
|
||||
"version": "1.0.7",
|
||||
"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",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsbundle": "^1.0.78",
|
||||
"@gitzone/tstest": "^1.0.44",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^15.12.5",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsbundle": "^2.0.8",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.12",
|
||||
"@types/node": "^20.4.6"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
@ -34,5 +34,17 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"asynchronous array operations",
|
||||
"typescript library",
|
||||
"array filtering",
|
||||
"array mapping",
|
||||
"array deduplication",
|
||||
"async/await",
|
||||
"npm package",
|
||||
"modern JavaScript development",
|
||||
"open source"
|
||||
]
|
||||
}
|
||||
|
4729
pnpm-lock.yaml
generated
Normal file
4729
pnpm-lock.yaml
generated
Normal file
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 @@
|
||||
|
110
readme.md
110
readme.md
@ -1,39 +1,95 @@
|
||||
# @pushrocks/smartarray
|
||||
```markdown
|
||||
# @push.rocks/smartarray
|
||||
a package exposing async manipulation for arrays
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartarray)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartarray)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartarray)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartarray/)
|
||||
## Install
|
||||
To add `@push.rocks/smartarray` to your project, run the following command:
|
||||
|
||||
## Status for master
|
||||
```bash
|
||||
npm install @push.rocks/smartarray --save
|
||||
```
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
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)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
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
|
||||
|
||||
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';
|
||||
```
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
### Mapping Arrays Asynchronously
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
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.
|
||||
|
37
test/test.ts
37
test/test.ts
@ -1,13 +1,36 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartarray from '../ts/index';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartarray from '../ts/index.js';
|
||||
|
||||
tap.test('should filter', async () => {
|
||||
const originalArray = [1, 2, 3, 4, 5, 6];
|
||||
expect(originalArray).to.contain(2);
|
||||
expect(originalArray).to.contain(3);
|
||||
const result = await smartarray.filter(originalArray, async itemArg => itemArg !== 3);
|
||||
expect(originalArray).to.contain(2);
|
||||
expect(result).to.not.contain(3);
|
||||
expect(originalArray).toContain(2);
|
||||
expect(originalArray).toContain(3);
|
||||
const result = await smartarray.filter(originalArray, async (itemArg) => itemArg !== 3);
|
||||
expect(originalArray).toContain(2);
|
||||
expect(result).not.toContain(3);
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test('should deduplicate', async () => {
|
||||
const originalArray = [1, 2, 2, 3, 3, 3, 4, 5, 6, 6];
|
||||
const result = await smartarray.deduplicate(originalArray, async (itemArg) => itemArg);
|
||||
|
||||
// Check the length of the array after deduplication
|
||||
expect(result.length).toEqual(6);
|
||||
|
||||
// Check if the result contains only unique values
|
||||
expect(result).toContain(1);
|
||||
expect(result).toContain(2);
|
||||
expect(result).toContain(3);
|
||||
expect(result).toContain(4);
|
||||
expect(result).toContain(5);
|
||||
expect(result).toContain(6);
|
||||
|
||||
// Make sure duplicates have been removed
|
||||
expect(result.filter(item => item === 2).length).toEqual(1);
|
||||
expect(result.filter(item => item === 3).length).toEqual(1);
|
||||
expect(result.filter(item => item === 6).length).toEqual(1);
|
||||
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartarray',
|
||||
version: '1.0.7',
|
||||
description: 'A library providing asynchronous operations like filter, map, and deduplication for arrays in TypeScript.'
|
||||
}
|
37
ts/index.ts
37
ts/index.ts
@ -1,4 +1,21 @@
|
||||
export const filter = async<T>(arrayArg: T[], filterFunction: (itemArg: T) => Promise<boolean>): Promise<T[]> => {
|
||||
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>(
|
||||
arrayArg: T[],
|
||||
filterFunction: (itemArg: T) => Promise<boolean>
|
||||
): Promise<T[]> => {
|
||||
const returnArray: T[] = [];
|
||||
for (const itemArg of arrayArg) {
|
||||
const filterResult = await filterFunction(itemArg);
|
||||
@ -7,4 +24,22 @@ export const filter = async<T>(arrayArg: T[], filterFunction: (itemArg: T) => Pr
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
};
|
||||
|
||||
export const deduplicate = async <T, K>(
|
||||
arrayArg: T[],
|
||||
keyCreation: (itemArg: T) => Promise<K>
|
||||
): Promise<T[]> => {
|
||||
const keysSet: Set<K> = new Set();
|
||||
const returnArray: T[] = [];
|
||||
|
||||
for (const itemArg of arrayArg) {
|
||||
const key = await keyCreation(itemArg);
|
||||
if (!keysSet.has(key)) {
|
||||
keysSet.add(key);
|
||||
returnArray.push(itemArg);
|
||||
}
|
||||
}
|
||||
|
||||
return returnArray;
|
||||
};
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user