@augment-vir/core 30.0.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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/dist/augments/array/array.d.ts +4 -0
- package/dist/augments/array/array.js +1 -0
- package/dist/augments/array/tuple.d.ts +13 -0
- package/dist/augments/array/tuple.js +1 -0
- package/dist/augments/enum/enum-type.d.ts +1 -0
- package/dist/augments/enum/enum-type.js +1 -0
- package/dist/augments/enum/enum-values.d.ts +2 -0
- package/dist/augments/enum/enum-values.js +10 -0
- package/dist/augments/error/ensure-error.d.ts +2 -0
- package/dist/augments/error/ensure-error.js +14 -0
- package/dist/augments/error/error-message.d.ts +3 -0
- package/dist/augments/error/error-message.js +41 -0
- package/dist/augments/function/generic-function-type.d.ts +2 -0
- package/dist/augments/function/generic-function-type.js +1 -0
- package/dist/augments/function/typed-function-type.d.ts +17 -0
- package/dist/augments/function/typed-function-type.js +1 -0
- package/dist/augments/http/http-status.d.ts +496 -0
- package/dist/augments/http/http-status.js +564 -0
- package/dist/augments/narrow-type.d.ts +2 -0
- package/dist/augments/narrow-type.js +1 -0
- package/dist/augments/object/generic-object-type.d.ts +2 -0
- package/dist/augments/object/generic-object-type.js +1 -0
- package/dist/augments/object/object-keys.d.ts +7 -0
- package/dist/augments/object/object-keys.js +14 -0
- package/dist/augments/object/object-value-types.d.ts +3 -0
- package/dist/augments/object/object-value-types.js +1 -0
- package/dist/augments/object/required-keys.d.ts +36 -0
- package/dist/augments/object/required-keys.js +1 -0
- package/dist/augments/object/stringify.d.ts +1 -0
- package/dist/augments/object/stringify.js +9 -0
- package/dist/augments/overwrite-type.d.ts +2 -0
- package/dist/augments/overwrite-type.js +1 -0
- package/dist/augments/partial-type.d.ts +7 -0
- package/dist/augments/partial-type.js +1 -0
- package/dist/augments/promise/deferred-promise.d.ts +7 -0
- package/dist/augments/promise/deferred-promise.js +19 -0
- package/dist/augments/promise/maybe-promise.d.ts +1 -0
- package/dist/augments/promise/maybe-promise.js +1 -0
- package/dist/augments/promise/wait.d.ts +3 -0
- package/dist/augments/promise/wait.js +16 -0
- package/dist/augments/runtime-env.d.ts +33 -0
- package/dist/augments/runtime-env.js +43 -0
- package/dist/augments/string/ansi.d.ts +3 -0
- package/dist/augments/string/ansi.js +36 -0
- package/dist/augments/string/punctuation.d.ts +6 -0
- package/dist/augments/string/punctuation.js +13 -0
- package/dist/augments/string/uuid.d.ts +4 -0
- package/dist/augments/string/uuid.js +4 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/package.json +54 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AnyObject } from './object/generic-object-type.js';
|
|
2
|
+
export type PartialWithNullable<T extends AnyObject> = {
|
|
3
|
+
[Prop in keyof T]?: T[Prop] | null | undefined;
|
|
4
|
+
};
|
|
5
|
+
export type PartialWithUndefined<T extends AnyObject> = {
|
|
6
|
+
[Prop in keyof T]?: T[Prop] | undefined;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ensureError } from '../error/ensure-error.js';
|
|
2
|
+
export class DeferredPromise {
|
|
3
|
+
promise;
|
|
4
|
+
resolve;
|
|
5
|
+
reject;
|
|
6
|
+
isSettled = false;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.promise = new Promise((resolve, reject) => {
|
|
9
|
+
this.resolve = (value) => {
|
|
10
|
+
this.isSettled = true;
|
|
11
|
+
return resolve(value);
|
|
12
|
+
};
|
|
13
|
+
this.reject = (reason) => {
|
|
14
|
+
this.isSettled = true;
|
|
15
|
+
reject(ensureError(reason));
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertDuration, DurationUnit } from '@date-vir/duration';
|
|
2
|
+
import { DeferredPromise } from './deferred-promise.js';
|
|
3
|
+
export function wait(duration) {
|
|
4
|
+
const deferredPromise = new DeferredPromise();
|
|
5
|
+
const milliseconds = convertDuration(duration, DurationUnit.Milliseconds).milliseconds;
|
|
6
|
+
if (milliseconds !== Infinity) {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
deferredPromise.resolve();
|
|
9
|
+
}, milliseconds <= 0 ? 0 : milliseconds);
|
|
10
|
+
}
|
|
11
|
+
return deferredPromise.promise;
|
|
12
|
+
}
|
|
13
|
+
export async function waitValue(duration, value) {
|
|
14
|
+
await wait(duration);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript run-time env. code, which usually has its own env definition as well.
|
|
3
|
+
*
|
|
4
|
+
* @category Env
|
|
5
|
+
*/
|
|
6
|
+
export declare enum RuntimeEnv {
|
|
7
|
+
Node = "node",
|
|
8
|
+
Web = "web"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Determine the current {@link RuntimeEnv} value. Usually you shouldn't need to call this, you can
|
|
12
|
+
* simply import {@link currentRuntimeEnv} directly.
|
|
13
|
+
*
|
|
14
|
+
* @category Env
|
|
15
|
+
*/
|
|
16
|
+
export declare function determineRuntimeEnv(): RuntimeEnv;
|
|
17
|
+
/**
|
|
18
|
+
* The current {@link RuntimeEnv} value.
|
|
19
|
+
*
|
|
20
|
+
* @category Env
|
|
21
|
+
*/
|
|
22
|
+
export declare const currentRuntimeEnv: RuntimeEnv;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given {@link RuntimeEnv} value is the current {@link RuntimeEnv} value.
|
|
25
|
+
*
|
|
26
|
+
* @category Env
|
|
27
|
+
* @returns `true` if the given {@link RuntimeEnv} is the current {@link RuntimeEnv}.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isRuntimeEnv(itItThisEnv: RuntimeEnv): boolean;
|
|
30
|
+
export declare class RuntimeEnvError extends Error {
|
|
31
|
+
readonly name = "RuntimeEnvError";
|
|
32
|
+
}
|
|
33
|
+
export declare function forEachEnv<T>(perEnv: Record<RuntimeEnv, () => T>): T;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isNode } from 'browser-or-node';
|
|
2
|
+
/**
|
|
3
|
+
* JavaScript run-time env. code, which usually has its own env definition as well.
|
|
4
|
+
*
|
|
5
|
+
* @category Env
|
|
6
|
+
*/
|
|
7
|
+
export var RuntimeEnv;
|
|
8
|
+
(function (RuntimeEnv) {
|
|
9
|
+
RuntimeEnv["Node"] = "node";
|
|
10
|
+
RuntimeEnv["Web"] = "web";
|
|
11
|
+
})(RuntimeEnv || (RuntimeEnv = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Determine the current {@link RuntimeEnv} value. Usually you shouldn't need to call this, you can
|
|
14
|
+
* simply import {@link currentRuntimeEnv} directly.
|
|
15
|
+
*
|
|
16
|
+
* @category Env
|
|
17
|
+
*/
|
|
18
|
+
export function determineRuntimeEnv() {
|
|
19
|
+
/** Coverage in this package is only run in Node. */
|
|
20
|
+
/* node:coverage ignore next */
|
|
21
|
+
return isNode ? RuntimeEnv.Node : RuntimeEnv.Web;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The current {@link RuntimeEnv} value.
|
|
25
|
+
*
|
|
26
|
+
* @category Env
|
|
27
|
+
*/
|
|
28
|
+
export const currentRuntimeEnv = determineRuntimeEnv();
|
|
29
|
+
/**
|
|
30
|
+
* Checks if the given {@link RuntimeEnv} value is the current {@link RuntimeEnv} value.
|
|
31
|
+
*
|
|
32
|
+
* @category Env
|
|
33
|
+
* @returns `true` if the given {@link RuntimeEnv} is the current {@link RuntimeEnv}.
|
|
34
|
+
*/
|
|
35
|
+
export function isRuntimeEnv(itItThisEnv) {
|
|
36
|
+
return currentRuntimeEnv === itItThisEnv;
|
|
37
|
+
}
|
|
38
|
+
export class RuntimeEnvError extends Error {
|
|
39
|
+
name = 'RuntimeEnvError';
|
|
40
|
+
}
|
|
41
|
+
export function forEachEnv(perEnv) {
|
|
42
|
+
return perEnv[currentRuntimeEnv]();
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function removeAnsiEscapeCodes(input) {
|
|
2
|
+
return input.replace(ansiRegExp, '');
|
|
3
|
+
}
|
|
4
|
+
export const removeColor = removeAnsiEscapeCodes;
|
|
5
|
+
// cspell:disable
|
|
6
|
+
/**
|
|
7
|
+
* Copied from
|
|
8
|
+
* https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/index.js
|
|
9
|
+
*
|
|
10
|
+
* The package has the following license from
|
|
11
|
+
* https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/license
|
|
12
|
+
*
|
|
13
|
+
* MIT License Copyright (c) Sindre Sorhus [sindresorhus@gmail.com](mailto:sindresorhus@gmail.com)
|
|
14
|
+
* (https://sindresorhus.com)
|
|
15
|
+
*
|
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
17
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
18
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
19
|
+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all copies or
|
|
23
|
+
* substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
26
|
+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
27
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
28
|
+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
// cspell:enable
|
|
32
|
+
const patterns = [
|
|
33
|
+
String.raw `[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
|
34
|
+
String.raw `(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`,
|
|
35
|
+
];
|
|
36
|
+
export const ansiRegExp = new RegExp(patterns.join('|'), 'g');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArrayElement } from '../array/array.js';
|
|
2
|
+
export declare const punctuationLetters: readonly [".", ":", ";", ",", "?", "!"];
|
|
3
|
+
export declare const punctuationRegExp: RegExp;
|
|
4
|
+
export declare const endsWithPunctuationRegExp: RegExp;
|
|
5
|
+
export type PunctuationLetter = ArrayElement<typeof punctuationLetters>;
|
|
6
|
+
export declare function removeEndingPunctuation(value: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const punctuationLetters = [
|
|
2
|
+
'.',
|
|
3
|
+
':',
|
|
4
|
+
';',
|
|
5
|
+
',',
|
|
6
|
+
'?',
|
|
7
|
+
'!',
|
|
8
|
+
];
|
|
9
|
+
export const punctuationRegExp = new RegExp(`[${punctuationLetters.join('')}]+`);
|
|
10
|
+
export const endsWithPunctuationRegExp = new RegExp(`[${punctuationLetters.join('')}]+$`);
|
|
11
|
+
export function removeEndingPunctuation(value) {
|
|
12
|
+
return value.replace(endsWithPunctuationRegExp, '');
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** @category String */
|
|
2
|
+
export type Uuid = `${string}-${string}-${string}-${string}-${string}`;
|
|
3
|
+
/** Creates a cryptographically secure random v4 UUID using `crypto.randomUUID`. */
|
|
4
|
+
export declare function createUuidV4(): `${string}-${string}-${string}-${string}-${string}`;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './augments/array/array.js';
|
|
2
|
+
export * from './augments/array/tuple.js';
|
|
3
|
+
export * from './augments/enum/enum-type.js';
|
|
4
|
+
export * from './augments/enum/enum-values.js';
|
|
5
|
+
export * from './augments/error/ensure-error.js';
|
|
6
|
+
export * from './augments/error/error-message.js';
|
|
7
|
+
export * from './augments/function/generic-function-type.js';
|
|
8
|
+
export * from './augments/function/typed-function-type.js';
|
|
9
|
+
export * from './augments/http/http-status.js';
|
|
10
|
+
export * from './augments/narrow-type.js';
|
|
11
|
+
export * from './augments/object/generic-object-type.js';
|
|
12
|
+
export * from './augments/object/object-keys.js';
|
|
13
|
+
export * from './augments/object/object-value-types.js';
|
|
14
|
+
export * from './augments/object/required-keys.js';
|
|
15
|
+
export * from './augments/object/stringify.js';
|
|
16
|
+
export * from './augments/overwrite-type.js';
|
|
17
|
+
export * from './augments/partial-type.js';
|
|
18
|
+
export * from './augments/promise/deferred-promise.js';
|
|
19
|
+
export * from './augments/promise/maybe-promise.js';
|
|
20
|
+
export * from './augments/promise/wait.js';
|
|
21
|
+
export * from './augments/runtime-env.js';
|
|
22
|
+
export * from './augments/string/ansi.js';
|
|
23
|
+
export * from './augments/string/punctuation.js';
|
|
24
|
+
export * from './augments/string/uuid.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './augments/array/array.js';
|
|
2
|
+
export * from './augments/array/tuple.js';
|
|
3
|
+
export * from './augments/enum/enum-type.js';
|
|
4
|
+
export * from './augments/enum/enum-values.js';
|
|
5
|
+
export * from './augments/error/ensure-error.js';
|
|
6
|
+
export * from './augments/error/error-message.js';
|
|
7
|
+
export * from './augments/function/generic-function-type.js';
|
|
8
|
+
export * from './augments/function/typed-function-type.js';
|
|
9
|
+
export * from './augments/http/http-status.js';
|
|
10
|
+
export * from './augments/narrow-type.js';
|
|
11
|
+
export * from './augments/object/generic-object-type.js';
|
|
12
|
+
export * from './augments/object/object-keys.js';
|
|
13
|
+
export * from './augments/object/object-value-types.js';
|
|
14
|
+
export * from './augments/object/required-keys.js';
|
|
15
|
+
export * from './augments/object/stringify.js';
|
|
16
|
+
export * from './augments/overwrite-type.js';
|
|
17
|
+
export * from './augments/partial-type.js';
|
|
18
|
+
export * from './augments/promise/deferred-promise.js';
|
|
19
|
+
export * from './augments/promise/maybe-promise.js';
|
|
20
|
+
export * from './augments/promise/wait.js';
|
|
21
|
+
export * from './augments/runtime-env.js';
|
|
22
|
+
export * from './augments/string/ansi.js';
|
|
23
|
+
export * from './augments/string/punctuation.js';
|
|
24
|
+
export * from './augments/string/uuid.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@augment-vir/core",
|
|
3
|
+
"version": "30.0.0",
|
|
4
|
+
"description": "Core augment-vir augments, especially including run-time environment determination.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"augment-vir",
|
|
7
|
+
"vir",
|
|
8
|
+
"core",
|
|
9
|
+
"env"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/electrovir/augment-vir",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/electrovir/augment-vir.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "(MIT or CC0 1.0)",
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "electrovir",
|
|
22
|
+
"url": "https://github.com/electrovir"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"module": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"compile": "virmator compile",
|
|
30
|
+
"docs": "virmator docs",
|
|
31
|
+
"start": "tsx src/index.ts",
|
|
32
|
+
"test": "virmator test node",
|
|
33
|
+
"test:coverage": "npm run test coverage",
|
|
34
|
+
"test:docs": "virmator docs check",
|
|
35
|
+
"test:update": "npm test"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@date-vir/duration": "^6.0.0",
|
|
39
|
+
"browser-or-node": "^3.0.0",
|
|
40
|
+
"json5": "^2.2.3",
|
|
41
|
+
"type-fest": "^4.25.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.5.0",
|
|
45
|
+
"c8": "^10.1.2",
|
|
46
|
+
"istanbul-smart-text-reporter": "^1.1.4"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=22"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|