Skip to content

Commit bcddcdd

Browse files
committed
Add GitHub Actions workflow for tag creation and update utility functions
- Introduced a new workflow to automate the creation of tags and pull requests on the main branch. - Modified `filterArrayByKeyValue` to return false for empty array values. - Enhanced `getKeyValue` to handle nested keys more robustly and prevent returning empty arrays. - Updated `package.json` to include additional keywords and repository type.
1 parent 21ec8b9 commit bcddcdd

File tree

8 files changed

+2451
-453
lines changed

8 files changed

+2451
-453
lines changed

.github/workflows/npm-publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Node.js Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: 20
15+
- run: npm ci
16+
#- run: npm test
17+
18+
publish-npm:
19+
needs: build
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
registry-url: https://registry.npmjs.org/
27+
- run: npm ci
28+
- run: npm publish
29+
env:
30+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.github/workflows/tag-creation.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'Create New Tag'
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
create-new-tag:
9+
runs-on: ubuntu-24.04
10+
timeout-minutes: 5
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Git Config
15+
run: |
16+
git config --global user.name "${{ vars.USERNAME }}"
17+
git config --global user.email "${{ vars.EMAIL }}"
18+
19+
- name: Create New Branch
20+
run: |
21+
git pull
22+
git checkout -b newTag
23+
24+
- name: App Version
25+
run: npm version patch
26+
27+
- name: Commit Changes
28+
run: |
29+
git show
30+
git push origin newTag
31+
git push --tags
32+
33+
- name: Create Pull Request
34+
run: |
35+
gh pr create -B main -H newTag --title 'Tag Creation' --body "New tag created"
36+
gh pr merge newTag --squash --delete-branch --admin
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bun.lock

Lines changed: 0 additions & 405 deletions
This file was deleted.

lib/types.ts

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
type Primitive = number | string | boolean | null | undefined;
2+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33
export type TObject = Record<string, any>;
44

55
/**
@@ -15,26 +15,10 @@ export type KeyOf<T extends TObject> = keyof {
1515
| (T[K] extends Array<infer U>
1616
? U extends Primitive
1717
? `${K}.${number}`
18-
: `${K}.${number}.${KeyOf<T[K][number]>}`
19-
: `${K}.${KeyOf<T[K]>}`)
20-
: never]: unknown;
21-
};
22-
23-
/**
24-
* Represents the keys of an object, including nested objects and arrays,
25-
* but ignores the positions of arrays.
26-
* This type is useful for creating dynamic forms or validating object structures.
27-
*/
28-
export type SimpleKeyOf<T extends TObject> = keyof {
29-
[K in keyof T as T[K] extends Primitive
30-
? K
31-
: K extends string
32-
?
33-
| K
34-
| (T[K] extends Array<infer U>
35-
? U extends Primitive
36-
? never
37-
: `[${K}].${KeyOf<T[K][number]>}`
18+
:
19+
| `${K}.${number}`
20+
| `[${K}].${KeyOf<T[K][number]>}`
21+
| `${K}.${number}.${KeyOf<T[K][number]>}`
3822
: `${K}.${KeyOf<T[K]>}`)
3923
: never]: unknown;
4024
};
@@ -50,24 +34,9 @@ export type DeepKeyOf<T extends TObject> = keyof {
5034
? T[K] extends Array<infer U>
5135
? U extends Primitive
5236
? K
53-
: `${K}.${number}.${DeepKeyOf<T[K][number]>}`
54-
: `${K}.${DeepKeyOf<T[K]>}`
55-
: never]: unknown;
56-
};
57-
58-
/**
59-
* Represents the deepest keys of an object, including nested objects and arrays,
60-
* but ignores the positions of arrays.
61-
* This type is useful for creating dynamic forms or validating object structures.
62-
*/
63-
export type SimpleDeepKeyOf<T extends TObject> = keyof {
64-
[K in keyof T as T[K] extends Primitive
65-
? K
66-
: K extends string
67-
? T[K] extends Array<infer U>
68-
? U extends Primitive
69-
? K
70-
: `[${K}].${DeepKeyOf<T[K][number]>}`
37+
:
38+
| `[${K}].${DeepKeyOf<T[K][number]>}`
39+
| `${K}.${number}.${DeepKeyOf<T[K][number]>}`
7140
: `${K}.${DeepKeyOf<T[K]>}`
7241
: never]: unknown;
7342
};

lib/utils/filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const filterArrayByKeyValue = <T extends TObject>(
1818
return list.filter((item) => {
1919
if (Array.isArray(value)) {
2020
if (value.length === 0) {
21-
return true;
21+
return false;
2222
}
2323
return value.some((val) => val === getKeyValue(item, key));
2424
}

lib/utils/value.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,32 @@ export const getKeyValue = <T extends TObject>(
1111
object: T,
1212
key: KeyOf<T>
1313
): any => {
14-
const subKeys = (key as string).split('.');
14+
const subKeys = (key as string)
15+
.split('.')
16+
.map((key) => key.replace(/[[\]]/g, ''));
1517
// Initialize the value with the object
1618
let value: any = object;
1719

20+
// If the object is an array, return undefined
21+
// This is to prevent the function from returning an array empty objects
22+
if (Array.isArray(object)) {
23+
return undefined;
24+
}
25+
1826
// Iterate over the subKeys to get the nested value
1927
subKeys.forEach((key) => {
20-
value = Array.isArray(value)
21-
? value.map((item) => item?.[key])
22-
: value?.[key];
28+
if (!Array.isArray(value)) {
29+
value = value?.[key];
30+
return;
31+
}
32+
// If the key is a number, get the value at that index
33+
if (Number.isSafeInteger(Number(key))) {
34+
value = value?.[Number(key)];
35+
return;
36+
}
37+
value = value.map((item) => item?.[key]);
2338
});
2439

25-
// Return the deepest value for the desired key
40+
// Return the value for the desired key
2641
return value;
2742
};

0 commit comments

Comments
 (0)