@minvws/mgo-utils 0.1.1-2 → 0.1.2
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/CHANGELOG.md +23 -0
- package/dist/createJsonApi/createJsonApi.d.ts +10 -0
- package/dist/createJsonApi/createJsonApi.d.ts.map +1 -0
- package/dist/createJsonApi/createJsonApi.js +16 -0
- package/dist/hasIntersection/hasIntersection.d.ts +2 -0
- package/dist/hasIntersection/hasIntersection.d.ts.map +1 -0
- package/dist/hasIntersection/hasIntersection.js +4 -0
- package/dist/includesAll/includesAll.d.ts +2 -0
- package/dist/includesAll/includesAll.d.ts.map +1 -0
- package/dist/includesAll/includesAll.js +4 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/map/map.d.ts +17 -0
- package/dist/map/map.d.ts.map +1 -0
- package/dist/map/map.js +7 -0
- package/dist/omitUndefined/omitUndefined.d.ts +9 -0
- package/dist/omitUndefined/omitUndefined.d.ts.map +1 -0
- package/dist/omitUndefined/omitUndefined.js +10 -0
- package/dist/types/AllOrNone.d.ts +8 -0
- package/dist/types/AllOrNone.d.ts.map +1 -0
- package/dist/types/AllOrNone.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/uniqueSlug/uniqueSlug.d.ts.map +1 -1
- package/dist/uniqueSlug/uniqueSlug.js +4 -1
- package/package.json +11 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## 0.1.2 (2026-10-08)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **utils:** add omitUndefined ([e7d507ec](https://github.com/minvws/nl-mgo-app-web-private/commit/e7d507ec))
|
|
6
|
+
- **utils:** add seeded mock factory helper ([a09013c8](https://github.com/minvws/nl-mgo-app-web-private/commit/a09013c8))
|
|
7
|
+
- **utils:** add expectJson helper for tests ([3bcb4a74](https://github.com/minvws/nl-mgo-app-web-private/commit/3bcb4a74))
|
|
8
|
+
- **utils:** add includesAll ([cad84f1e](https://github.com/minvws/nl-mgo-app-web-private/commit/cad84f1e))
|
|
9
|
+
- **utils:** add has intersection helper ([c63a51ca](https://github.com/minvws/nl-mgo-app-web-private/commit/c63a51ca))
|
|
10
|
+
- **utils:** add fallback slug for empty/undefined values when creating unique slugs ([62b52120](https://github.com/minvws/nl-mgo-app-web-private/commit/62b52120))
|
|
11
|
+
- add AllOrNone utility type ([1740434e](https://github.com/minvws/nl-mgo-app-web-private/commit/1740434e))
|
|
12
|
+
- update utils package to be node compatible ([1c8a12ee](https://github.com/minvws/nl-mgo-app-web-private/commit/1c8a12ee))
|
|
13
|
+
- add initial nx config ([#798](https://github.com/minvws/nl-mgo-app-web-private/pull/798))
|
|
14
|
+
|
|
15
|
+
### 🩹 Fixes
|
|
16
|
+
|
|
17
|
+
- remove DOM dependencies ([19cc83ba](https://github.com/minvws/nl-mgo-app-web-private/commit/19cc83ba))
|
|
18
|
+
- **utils:** avoid factory method trigger during setup ([498db9cc](https://github.com/minvws/nl-mgo-app-web-private/commit/498db9cc))
|
|
19
|
+
|
|
20
|
+
### ❤️ Thank You
|
|
21
|
+
|
|
22
|
+
- Geert Fokke
|
|
23
|
+
- Otto Boekesteijn
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Func = (...args: any[]) => any;
|
|
2
|
+
type JsonParam<TParams extends readonly any[]> = {
|
|
3
|
+
[K in keyof TParams]: string;
|
|
4
|
+
};
|
|
5
|
+
type JsonInterfacedFunction<F> = F extends (...args: infer T) => infer R ? (...args: JsonParam<T>) => R extends undefined ? string | undefined : string : never;
|
|
6
|
+
export declare function createJsonApi<T extends Func>(func: T, options?: {
|
|
7
|
+
lossless?: boolean;
|
|
8
|
+
}): JsonInterfacedFunction<T>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=createJsonApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createJsonApi.d.ts","sourceRoot":"","sources":["../../src/createJsonApi/createJsonApi.ts"],"names":[],"mappings":"AAGA,KAAK,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAGpC,KAAK,SAAS,CAAC,OAAO,SAAS,SAAS,GAAG,EAAE,IAAI;KAC5C,CAAC,IAAI,MAAM,OAAO,GAAG,MAAM;CAC/B,CAAC;AAEF,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAClE,CAAC,GAAG,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAC5E,KAAK,CAAC;AAQZ,wBAAgB,aAAa,CAAC,CAAC,SAAS,IAAI,EACxC,IAAI,EAAE,CAAC,EACP,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GACrC,sBAAsB,CAAC,CAAC,CAAC,CAa3B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { losslessParse, losslessStringify } from '@minvws/mgo-utils';
|
|
2
|
+
function isPromise(value) {
|
|
3
|
+
return (typeof value === 'object' && typeof value?.then === 'function');
|
|
4
|
+
}
|
|
5
|
+
export function createJsonApi(func, options = {}) {
|
|
6
|
+
const parse = options.lossless ? losslessParse : (value) => JSON.parse(value);
|
|
7
|
+
const stringify = options.lossless ? losslessStringify : JSON.stringify;
|
|
8
|
+
const replaceUndefinedWithNull = (_key, value) => value === undefined ? null : value;
|
|
9
|
+
return function (...args) {
|
|
10
|
+
const result = func(...args.map(parse));
|
|
11
|
+
if (isPromise(result)) {
|
|
12
|
+
return result.then((value) => stringify(value, replaceUndefinedWithNull));
|
|
13
|
+
}
|
|
14
|
+
return stringify(result, replaceUndefinedWithNull);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasIntersection.d.ts","sourceRoot":"","sources":["../../src/hasIntersection/hasIntersection.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAG1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"includesAll.d.ts","sourceRoot":"","sources":["../../src/includesAll/includesAll.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,GAAG,OAAO,CAGxE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
export * from './types/index.js';
|
|
2
|
+
export * from './createJsonApi/createJsonApi.js';
|
|
2
3
|
export * from './defer/defer.js';
|
|
3
4
|
export * from './flushCallStack/flushCallStack.js';
|
|
5
|
+
export * from './hasIntersection/hasIntersection.js';
|
|
6
|
+
export * from './includesAll/includesAll.js';
|
|
4
7
|
export * from './isNonNullish/isNonNullish.js';
|
|
5
8
|
export * from './isNullish/isNullish.js';
|
|
6
|
-
export * from './log/log.js';
|
|
7
9
|
export * from './lossless/lossless.js';
|
|
10
|
+
export * from './map/map.js';
|
|
11
|
+
export * from './omitUndefined/omitUndefined.js';
|
|
8
12
|
export * from './uniqueSlug/uniqueSlug.js';
|
|
9
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC;AACjC,cAAc,oCAAoC,CAAC;AACnD,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export * from './types/index.js';
|
|
2
|
+
export * from './createJsonApi/createJsonApi.js';
|
|
2
3
|
export * from './defer/defer.js';
|
|
3
4
|
export * from './flushCallStack/flushCallStack.js';
|
|
5
|
+
export * from './hasIntersection/hasIntersection.js';
|
|
6
|
+
export * from './includesAll/includesAll.js';
|
|
4
7
|
export * from './isNonNullish/isNonNullish.js';
|
|
5
8
|
export * from './isNullish/isNullish.js';
|
|
6
|
-
export * from './log/log.js';
|
|
7
9
|
export * from './lossless/lossless.js';
|
|
10
|
+
export * from './map/map.js';
|
|
11
|
+
export * from './omitUndefined/omitUndefined.js';
|
|
8
12
|
export * from './uniqueSlug/uniqueSlug.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Nullable } from '../types/Nullable.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array of values by running each element in collection thru iteratee.
|
|
4
|
+
* If the collection is empty or undefined it will return undefined, unless the `returnEmpty` parameter is set to true.
|
|
5
|
+
* The resulting array will NOT contain any undefined or null values.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const iteratee = (x: string | null | undefined) => x;
|
|
9
|
+
* map(undefined, iteratee); // => undefined
|
|
10
|
+
* map(undefined, iteratee, true); // => []
|
|
11
|
+
* map([], iteratee); // => undefined
|
|
12
|
+
* map(['foo', 'bar'], iteratee); // => ['foo', 'bar']
|
|
13
|
+
* map(['foo', undefined, 'bar', null, undefined], iteratee); // => ['foo', 'bar']
|
|
14
|
+
*/
|
|
15
|
+
export declare function map<Items extends unknown[], Iteratee extends (arg: Items[number], key: number) => unknown, T = NonNullable<ReturnType<Iteratee>>>(items: Nullable<Items>, iteratee: Iteratee, returnEmpty: true): T[];
|
|
16
|
+
export declare function map<Items extends unknown[], Iteratee extends (arg: Items[number], key: number) => unknown, T = NonNullable<ReturnType<Iteratee>>>(items: Nullable<Items>, iteratee: Iteratee, returnEmpty?: false): T[] | undefined;
|
|
17
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/map/map.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACf,KAAK,SAAS,OAAO,EAAE,EACvB,QAAQ,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,EAC7D,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EACvC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC;AACtE,wBAAgB,GAAG,CACf,KAAK,SAAS,OAAO,EAAE,EACvB,QAAQ,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,EAC7D,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EACvC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC"}
|
package/dist/map/map.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omits all undefined values from an object.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* omitUndefined({ a: 1, b: undefined, c: 3 }) // { a: 1, c: 3 }
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export declare function omitUndefined<T extends Record<string, unknown>>(value: T): Partial<T>;
|
|
9
|
+
//# sourceMappingURL=omitUndefined.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omitUndefined.d.ts","sourceRoot":"","sources":["../../src/omitUndefined/omitUndefined.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIrF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omits all undefined values from an object.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* omitUndefined({ a: 1, b: undefined, c: 3 }) // { a: 1, c: 3 }
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export function omitUndefined(value) {
|
|
9
|
+
return Object.fromEntries(Object.entries(value).filter(([_, propValue]) => propValue !== undefined));
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AllOrNone.d.ts","sourceRoot":"","sources":["../../src/types/AllOrNone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK;CAAE,EAAE,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
package/dist/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueSlug.d.ts","sourceRoot":"","sources":["../../src/uniqueSlug/uniqueSlug.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"uniqueSlug.d.ts","sourceRoot":"","sources":["../../src/uniqueSlug/uniqueSlug.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,UAYtE"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { kebabCase } from 'lodash-es';
|
|
2
2
|
export function createUniqueSlug(value, existingSlugs) {
|
|
3
|
-
|
|
3
|
+
let slug = kebabCase(value);
|
|
4
|
+
if (slug.length === 0) {
|
|
5
|
+
slug = 'undefined';
|
|
6
|
+
}
|
|
4
7
|
let uniqueSlug = slug;
|
|
5
8
|
let i = 2;
|
|
6
9
|
while (existingSlugs.includes(uniqueSlug)) {
|
package/package.json
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
"name": "@minvws/mgo-utils",
|
|
3
3
|
"license": "EUPL-1.2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.2",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/minvws/nl-mgo-app-web"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
|
-
"dist/"
|
|
11
|
+
"dist/",
|
|
12
|
+
"CHANGELOG.md"
|
|
12
13
|
],
|
|
13
14
|
"exports": {
|
|
14
15
|
"./package.json": "./package.json",
|
|
@@ -17,16 +18,20 @@
|
|
|
17
18
|
"types": "./dist/index.d.ts",
|
|
18
19
|
"import": "./dist/index.js",
|
|
19
20
|
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./test/shared": {
|
|
23
|
+
"development": "./test/shared/index.ts"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"lodash-es": "^4.
|
|
24
|
-
"lossless-json": "^4.
|
|
27
|
+
"lodash-es": "^4.18.1",
|
|
28
|
+
"lossless-json": "^4.3.1"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
27
|
-
"@faker-js/faker": "^
|
|
31
|
+
"@faker-js/faker": "^10.6.0",
|
|
28
32
|
"@types/lodash-es": "^4.17.12",
|
|
29
|
-
"
|
|
33
|
+
"@types/node": "^24.1.0",
|
|
34
|
+
"type-fest": "^5.10.0",
|
|
30
35
|
"typescript": "^5.4.5"
|
|
31
36
|
},
|
|
32
37
|
"scripts": {}
|