@ibiliaze/stringman 3.19.0 → 3.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/package.json +2 -2
- package/src/index.ts +3 -5
package/dist/index.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export declare const valueKey: (v: unknown) => string;
|
|
|
152
152
|
* - keepFirst=false => last wins
|
|
153
153
|
* - keepNoKey=true => keep items where key is missing/invalid (kept in original order, before deduped items)
|
|
154
154
|
*/
|
|
155
|
-
export declare const dedupeBy: <T>(arr: T[] | undefined, key:
|
|
155
|
+
export declare const dedupeBy: <T>(arr: T[] | undefined, key: keyof T, { keepFirst, keepNoKey }?: DedupeByOptions) => T[];
|
|
156
156
|
export declare const invalidPw: (password: string, passwordLength?: number) => string | void;
|
|
157
157
|
export declare const b36: (n: number) => string;
|
|
158
158
|
export declare const luhn36: (s: string) => string;
|
package/dist/index.js
CHANGED
|
@@ -277,6 +277,8 @@ const dedupeBy = (arr = [], key, { keepFirst = true, keepNoKey = true } = {}) =>
|
|
|
277
277
|
console.error('dedupeBy(): expected an array, got:', arr);
|
|
278
278
|
return [];
|
|
279
279
|
}
|
|
280
|
+
if (typeof key !== 'string')
|
|
281
|
+
throw new Error('Key is not a string');
|
|
280
282
|
// Build a getter for a "dot.path" key like "user.id"
|
|
281
283
|
const getKey = (obj) => {
|
|
282
284
|
try {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiliaze/stringman",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"pub": "npm publish --access public",
|
|
10
|
-
"git": "git add .; git commit -m 'changes'; git tag -a 3.
|
|
10
|
+
"git": "git add .; git commit -m 'changes'; git tag -a 3.20.0 -m '3.20.0'; git push origin 3.20.0; git push",
|
|
11
11
|
"push": "npm run build; npm run git; npm run pub"
|
|
12
12
|
},
|
|
13
13
|
"author": "Ibi Hasanli",
|
package/src/index.ts
CHANGED
|
@@ -255,17 +255,15 @@ export const valueKey = (v: unknown): string => {
|
|
|
255
255
|
* - keepFirst=false => last wins
|
|
256
256
|
* - keepNoKey=true => keep items where key is missing/invalid (kept in original order, before deduped items)
|
|
257
257
|
*/
|
|
258
|
-
export const dedupeBy = <T>(
|
|
259
|
-
arr: T[] = [],
|
|
260
|
-
key: string,
|
|
261
|
-
{ keepFirst = true, keepNoKey = true }: DedupeByOptions = {}
|
|
262
|
-
): T[] => {
|
|
258
|
+
export const dedupeBy = <T>(arr: T[] = [], key: keyof T, { keepFirst = true, keepNoKey = true }: DedupeByOptions = {}): T[] => {
|
|
263
259
|
try {
|
|
264
260
|
if (!Array.isArray(arr)) {
|
|
265
261
|
console.error('dedupeBy(): expected an array, got:', arr);
|
|
266
262
|
return [];
|
|
267
263
|
}
|
|
268
264
|
|
|
265
|
+
if (typeof key !== 'string') throw new Error('Key is not a string');
|
|
266
|
+
|
|
269
267
|
// Build a getter for a "dot.path" key like "user.id"
|
|
270
268
|
const getKey = (obj: any): unknown => {
|
|
271
269
|
try {
|