12 Commits

Author SHA1 Message Date
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
c3f1f373e5 1.0.4 2023-08-02 14:39:59 +02:00
64557a8ac3 fix(core): update 2023-08-02 14:39:58 +02:00
9c5cc17968 switch to new org scheme 2023-07-11 00:14:43 +02:00
d5ae1ff92d switch to new org scheme 2023-07-10 02:42:11 +02:00
15 changed files with 5133 additions and 25611 deletions

View 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

View 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

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

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${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"
} }
] ]
} }

View File

@ -2,17 +2,34 @@
"gitzone": { "gitzone": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartarray", "gitrepo": "smartarray",
"shortDescription": "a package exposing async manipulation for arrays", "description": "a package exposing async manipulation for arrays",
"npmPackagename": "@pushrocks/smartarray", "npmPackagename": "@push.rocks/smartarray",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks",
"keywords": [
"async",
"arrays",
"manipulation",
"filter",
"deduplicate",
"typescript",
"nodejs",
"async programming",
"development",
"npm package",
"code quality",
"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"
} }
} }

25520
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartarray", "name": "@push.rocks/smartarray",
"version": "1.0.3", "version": "1.0.6",
"private": false, "private": false,
"description": "a package exposing async manipulation for arrays", "description": "a package exposing async manipulation for arrays",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -9,16 +9,16 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web)" "build": "(tsbuild --web)",
"buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@git.zone/tsbuild": "^2.1.66",
"@gitzone/tsbundle": "^1.0.78", "@git.zone/tsbundle": "^2.0.8",
"@gitzone/tstest": "^1.0.44", "@git.zone/tsrun": "^1.2.44",
"@pushrocks/tapbundle": "^3.2.9", "@git.zone/tstest": "^1.0.77",
"@types/node": "^15.12.5", "@push.rocks/tapbundle": "^5.0.12",
"tslint": "^6.1.3", "@types/node": "^20.4.6"
"tslint-config-prettier": "^1.15.0"
}, },
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
@ -34,5 +34,20 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"type": "module",
"keywords": [
"async",
"arrays",
"manipulation",
"filter",
"deduplicate",
"typescript",
"nodejs",
"async programming",
"development",
"npm package",
"code quality",
"open source"
] ]
} }

4729
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

View File

@ -1,39 +1,84 @@
# @pushrocks/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/@pushrocks/smartarray) To add `@push.rocks/smartarray` to your project, run the following command:
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartarray)
* [github.com (source mirror)](https://github.com/pushrocks/smartarray)
* [docs (typedoc)](https://pushrocks.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 | [![pipeline status](https://gitlab.com/pushrocks/smartarray/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartarray/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartarray)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartarray)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
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/@pushrocks/smartarray)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartarray)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartarray)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
Use TypeScript for best in class intellisense `@push.rocks/smartarray` simplifies the manipulation of arrays with asynchronous operations in TypeScript. It provides utility functions such as filtering and deduplication of arrays with asynchronous predicates or key generation functions. Let's delve into code examples to understand how to utilize these features effectively.
## Contribution ### Importing the module
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). :) First, import the functions you need from the module:
For further information read the linked docs at the top of this readme. ```typescript
import { filter, deduplicate } from '@push.rocks/smartarray';
```
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) ### Filtering an Array Asynchronously
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) The `filter` function allows you to filter an array based on a predicate function that returns a Promise. This is particularly useful when your filtering condition involves asynchronous operations, such as fetching data from an API or accessing a database.
Suppose you have an array of user IDs, and you want to filter out IDs that do not correspond to active users. You might have an asynchronous function `isActiveUser(userId): Promise<boolean>` that checks user's status. Here's how you can filter out inactive user IDs:
```typescript
const userIds = [1, 2, 3, 4, 5];
const activeUserIds = await filter(userIds, async (userId) => {
return isActiveUser(userId);
});
console.log(activeUserIds); // Logs: [1, 3, 5] assuming these IDs are active
```
### Deduplicating an Array Asynchronously
The `deduplicate` function removes duplicate elements from an array based on a key generated by an asynchronous function. This is handy when you need to remove duplicates based on complex or asynchronous criteria.
Imagine you have an array of objects representing job applications, where each object contains a `userId` and `applicationId`. If you want to ensure that there's only one application per user, you could use the `deduplicate` function as shown:
```typescript
const applications = [
{ userId: 1, applicationId: 'a1' },
{ userId: 2, applicationId: 'a2' },
{ userId: 1, applicationId: 'a3' }, // Duplicate user
{ userId: 3, applicationId: 'a4' }
];
const uniqueApplications = await deduplicate(applications, async (app) => {
// The key is the userId, ensuring uniqueness by user
return app.userId;
});
console.log(uniqueApplications);
// Logs: [{ userId: 1, applicationId: 'a1' }, { userId: 2, applicationId: 'a2' }, { userId: 3, applicationId: 'a4' }]
```
In this example, the second application from the same user (`userId: 1`) was removed, leaving only unique user applications in the array.
These examples illustrate how `@push.rocks/smartarray` can be utilized for asynchronous array manipulation, offering flexibility and performance for handling complex data processing tasks in a modern JavaScript or TypeScript application.
Remember, all operations return promises, so ensure you handle them properly using `async/await` syntax or `.then().catch()` chains according to your application's structure or personal preference.
## 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,13 +1,36 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as smartarray from '../ts/index'; import * as smartarray from '../ts/index.js';
tap.test('should filter', async () => { tap.test('should filter', async () => {
const originalArray = [1,2,3,4,5,6]; const originalArray = [1, 2, 3, 4, 5, 6];
expect(originalArray).to.contain(2); expect(originalArray).toContain(2);
expect(originalArray).to.contain(3); expect(originalArray).toContain(3);
const result = await smartarray.filter(originalArray, async itemArg => itemArg !== 3); const result = await smartarray.filter(originalArray, async (itemArg) => itemArg !== 3);
expect(originalArray).to.contain(2); expect(originalArray).toContain(2);
expect(result).to.not.contain(3); 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); console.log(result);
}); });

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartarray',
version: '1.0.6',
description: 'a package exposing async manipulation for arrays'
}

View File

@ -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[] = []; const returnArray: T[] = [];
for (const itemArg of arrayArg) { for (const itemArg of arrayArg) {
const filterResult = await filterFunction(itemArg); const filterResult = await filterFunction(itemArg);
@ -7,4 +24,22 @@ export const filter = async<T>(arrayArg: T[], filterFunction: (itemArg: T) => Pr
} }
} }
return returnArray; 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
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -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"
}