@minvws/mgo-utils 0.1.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/LICENSE.md +7 -0
- package/README.md +36 -0
- package/dist/defer/defer.d.ts +7 -0
- package/dist/defer/defer.d.ts.map +1 -0
- package/dist/defer/defer.js +8 -0
- package/dist/flushCallStack/flushCallStack.d.ts +6 -0
- package/dist/flushCallStack/flushCallStack.d.ts.map +1 -0
- package/dist/flushCallStack/flushCallStack.js +12 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/isNonNullish/isNonNullish.d.ts +2 -0
- package/dist/isNonNullish/isNonNullish.d.ts.map +1 -0
- package/dist/isNonNullish/isNonNullish.js +4 -0
- package/dist/isNullish/isNullish.d.ts +3 -0
- package/dist/isNullish/isNullish.d.ts.map +1 -0
- package/dist/isNullish/isNullish.js +3 -0
- package/dist/log/log.d.ts +11 -0
- package/dist/log/log.d.ts.map +1 -0
- package/dist/log/log.js +18 -0
- package/dist/lossless/DeepReplaceType.d.ts +16 -0
- package/dist/lossless/DeepReplaceType.d.ts.map +1 -0
- package/dist/lossless/DeepReplaceType.js +1 -0
- package/dist/lossless/lossless.d.ts +12 -0
- package/dist/lossless/lossless.d.ts.map +1 -0
- package/dist/lossless/lossless.js +13 -0
- package/dist/types/Nullable.d.ts +2 -0
- package/dist/types/Nullable.d.ts.map +1 -0
- package/dist/types/Nullable.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/uniqueSlug/uniqueSlug.d.ts +2 -0
- package/dist/uniqueSlug/uniqueSlug.d.ts.map +1 -0
- package/dist/uniqueSlug/uniqueSlug.js +11 -0
- package/package.json +33 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
The source code is released under the [EUPL license](./LICENSES/EUPL-1.2.txt).
|
|
2
|
+
The documentation is released under the [CC0 license](./LICENSES/CC0-1.0.txt).
|
|
3
|
+
The EUPL 1.2 and the CC0 do not apply to photos, videos, infographics, fonts or other forms of media.
|
|
4
|
+
Specifically the rijkslogo and rijkshuisstijl have specific [terms of use](./LICENSES/LicenseRef-Rijkshuisstijl.txt).
|
|
5
|
+
|
|
6
|
+
This repository follows the [REUSE Specfication v3.3](https://reuse.software/spec/).
|
|
7
|
+
Please see [REUSE.toml](./REUSE.toml) and the individual `*.license` files for copyright and license information.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @minvws/mgo-utils
|
|
2
|
+
|
|
3
|
+
This package contains commonly used utility functions within [MGO][repo].
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm i --save @minvws/mgo-utils
|
|
9
|
+
|
|
10
|
+
# or
|
|
11
|
+
|
|
12
|
+
pnpm add @minvws/mgo-utils
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
|
|
19
|
+
import { isNullish } from '@minvws/mgo-utils'
|
|
20
|
+
|
|
21
|
+
...
|
|
22
|
+
|
|
23
|
+
if( isNullish(value) ) {
|
|
24
|
+
...
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
See the **[package source][source]** for more details
|
|
30
|
+
|
|
31
|
+
<hr>
|
|
32
|
+
|
|
33
|
+
_This package and its documentation are still under development._
|
|
34
|
+
|
|
35
|
+
[repo]: https://github.com/minvws/nl-mgo-app-web
|
|
36
|
+
[source]: https://github.com/minvws/nl-mgo-app-web/tree/main/packages/utils
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer.d.ts","sourceRoot":"","sources":["../../src/defer/defer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ,CAAC,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,KAAK,CAAC,CAAC,GAAG,OAAO,iBAOhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flushCallStack.d.ts","sourceRoot":"","sources":["../../src/flushCallStack/flushCallStack.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,cAAc,CAAC,UAAU,SAAI,iBAKlD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// save reference to the real setTimeout so we can still flush the callstack even when timers are faked.
|
|
2
|
+
const realSetTimeout = setTimeout;
|
|
3
|
+
/**
|
|
4
|
+
* Flushes the Promise stack by awaiting a new immediate Promise.
|
|
5
|
+
* @returns {Promise<void>} The Promise to be awaited for flush
|
|
6
|
+
*/
|
|
7
|
+
export async function flushCallStack(stackCount = 1) {
|
|
8
|
+
while (stackCount >= 1) {
|
|
9
|
+
await new Promise((resolve) => realSetTimeout(resolve));
|
|
10
|
+
stackCount--;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './types/index.js';
|
|
2
|
+
export * from './defer/defer.js';
|
|
3
|
+
export * from './flushCallStack/flushCallStack.js';
|
|
4
|
+
export * from './isNonNullish/isNonNullish.js';
|
|
5
|
+
export * from './isNullish/isNullish.js';
|
|
6
|
+
export * from './log/log.js';
|
|
7
|
+
export * from './lossless/lossless.js';
|
|
8
|
+
export * from './uniqueSlug/uniqueSlug.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './types/index.js';
|
|
2
|
+
export * from './defer/defer.js';
|
|
3
|
+
export * from './flushCallStack/flushCallStack.js';
|
|
4
|
+
export * from './isNonNullish/isNonNullish.js';
|
|
5
|
+
export * from './isNullish/isNullish.js';
|
|
6
|
+
export * from './log/log.js';
|
|
7
|
+
export * from './lossless/lossless.js';
|
|
8
|
+
export * from './uniqueSlug/uniqueSlug.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNonNullish.d.ts","sourceRoot":"","sources":["../../src/isNonNullish/isNonNullish.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,KAAK,CAAC,CAE7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNullish.d.ts","sourceRoot":"","sources":["../../src/isNullish/isNullish.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC;AAEtD,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAE1D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function logWarning(message?: any, ...optionalParams: any[]): void;
|
|
2
|
+
declare function logError(message?: any, ...optionalParams: any[]): void;
|
|
3
|
+
/**
|
|
4
|
+
* A very simple utility to log warning or error messages during vite development mode
|
|
5
|
+
*/
|
|
6
|
+
export declare const log: {
|
|
7
|
+
warn: typeof logWarning;
|
|
8
|
+
error: typeof logError;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log/log.ts"],"names":[],"mappings":"AAEA,iBAAS,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,QAI1D;AAED,iBAAS,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,QAIxD;AAED;;GAEG;AACH,eAAO,MAAM,GAAG;;;CAGf,CAAC"}
|
package/dist/log/log.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
function logWarning(message, ...optionalParams) {
|
|
3
|
+
if (import.meta?.env?.DEV) {
|
|
4
|
+
console.warn(message, ...optionalParams);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function logError(message, ...optionalParams) {
|
|
8
|
+
if (import.meta?.env?.DEV) {
|
|
9
|
+
console.error(message, ...optionalParams);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A very simple utility to log warning or error messages during vite development mode
|
|
14
|
+
*/
|
|
15
|
+
export const log = {
|
|
16
|
+
warn: logWarning,
|
|
17
|
+
error: logError,
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform a deep replacement of a type in another type definition.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* type Foo = { foo: string; bar: number; baz: { qux: number } }
|
|
6
|
+
* DeepReplaceType<Foo, number, boolean> // { foo: string, bar: boolean, baz: { qux: boolean } }
|
|
7
|
+
* DeepReplaceType<number, number, boolean> // boolean
|
|
8
|
+
* DeepReplaceType<number | string, number, boolean> // boolean | string
|
|
9
|
+
* DeepReplaceType<(number | string)[], number, boolean> // (boolean | string)[]
|
|
10
|
+
*/
|
|
11
|
+
export type DeepReplaceType<T, ToReplace, Replacement> = T extends ToReplace ? Exclude<T, ToReplace> | Replacement : T extends object ? DeepReplaceTypeInObject<T, ToReplace, Replacement> : T;
|
|
12
|
+
type DeepReplaceTypeInObject<T extends object, ToReplace, Replacement> = {
|
|
13
|
+
[key in keyof T]: T[key] extends object ? DeepReplaceTypeInObject<T[key], ToReplace, Replacement> : T[key] extends (infer U)[] ? DeepReplaceType<U, ToReplace, Replacement>[] : DeepReplaceType<T[key], ToReplace, Replacement>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=DeepReplaceType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeepReplaceType.d.ts","sourceRoot":"","sources":["../../src/lossless/DeepReplaceType.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,WAAW,IAAI,CAAC,SAAS,SAAS,GACtE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,WAAW,GACnC,CAAC,SAAS,MAAM,GACd,uBAAuB,CAAC,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,GAClD,CAAC,CAAC;AAEV,KAAK,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,WAAW,IAAI;KACpE,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GACjC,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,GACvD,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACxB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,GAC5C,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC;CAC1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { stringify, type LosslessNumber } from 'lossless-json';
|
|
2
|
+
import { type DeepReplaceType } from './DeepReplaceType.js';
|
|
3
|
+
export type { LosslessNumber };
|
|
4
|
+
export type LosslessObject<T = unknown> = DeepReplaceType<T, number, LosslessNumber>;
|
|
5
|
+
export type Lossless<T> = T extends number ? LosslessNumber : T extends object ? LosslessObject<T> : T;
|
|
6
|
+
/**
|
|
7
|
+
* Prevent loss of precision when parsing JSON numbers.
|
|
8
|
+
* @see https://www.hl7.org/fhir/json.html#primitive
|
|
9
|
+
*/
|
|
10
|
+
export declare function losslessParse<T = any>(text: string): LosslessObject<T>;
|
|
11
|
+
export declare const losslessStringify: typeof stringify;
|
|
12
|
+
//# sourceMappingURL=lossless.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lossless.d.ts","sourceRoot":"","sources":["../../src/lossless/lossless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;AAErF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACpC,cAAc,GACd,CAAC,SAAS,MAAM,GACd,cAAc,CAAC,CAAC,CAAC,GACjB,CAAC,CAAC;AAEV;;;GAGG;AAGH,wBAAgB,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,CAMtE;AAED,eAAO,MAAM,iBAAiB,kBAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parse, stringify } from 'lossless-json';
|
|
2
|
+
/**
|
|
3
|
+
* Prevent loss of precision when parsing JSON numbers.
|
|
4
|
+
* @see https://www.hl7.org/fhir/json.html#primitive
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
export function losslessParse(text) {
|
|
8
|
+
if (typeof text !== 'string') {
|
|
9
|
+
throw new Error('Input is not a (JSON) string');
|
|
10
|
+
}
|
|
11
|
+
return parse(text);
|
|
12
|
+
}
|
|
13
|
+
export const losslessStringify = stringify;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Nullable.d.ts","sourceRoot":"","sources":["../../src/types/Nullable.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Nullable.js';
|
|
@@ -0,0 +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,UAStE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { kebabCase } from 'lodash-es';
|
|
2
|
+
export function createUniqueSlug(value, existingSlugs) {
|
|
3
|
+
const slug = kebabCase(value);
|
|
4
|
+
let uniqueSlug = slug;
|
|
5
|
+
let i = 2;
|
|
6
|
+
while (existingSlugs.includes(uniqueSlug)) {
|
|
7
|
+
uniqueSlug = `${slug}-${i}`;
|
|
8
|
+
i++;
|
|
9
|
+
}
|
|
10
|
+
return uniqueSlug;
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@minvws/mgo-utils",
|
|
3
|
+
"license": "EUPL-1.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.1.1-2",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/minvws/nl-mgo-app-web"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
".": {
|
|
16
|
+
"development": "./src/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"lodash-es": "^4.17.21",
|
|
24
|
+
"lossless-json": "^4.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@faker-js/faker": "^8.4.1",
|
|
28
|
+
"@types/lodash-es": "^4.17.12",
|
|
29
|
+
"type-fest": "^4.23.0",
|
|
30
|
+
"typescript": "^5.4.5"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {}
|
|
33
|
+
}
|