@flemist/simple-utils 1.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 +5 -0
- package/README.md +19 -0
- package/build/browser/index.cjs +1 -0
- package/build/browser/index.d.ts +1 -0
- package/build/browser/index.mjs +53 -0
- package/build/common/async/abort/index.d.ts +2 -0
- package/build/common/async/abort/timeout.d.ts +3 -0
- package/build/common/async/abort/timeoutAbortController.d.ts +8 -0
- package/build/common/async/index.d.ts +2 -0
- package/build/common/async/lazy.d.ts +31 -0
- package/build/common/crypto/index.d.ts +2 -0
- package/build/common/crypto/sha256.d.ts +10 -0
- package/build/common/crypto/sha256Node.d.ts +2 -0
- package/build/common/crypto/toHex.d.ts +8 -0
- package/build/common/debug/console/alertReplace.d.ts +2 -0
- package/build/common/debug/console/consoleReplace.d.ts +13 -0
- package/build/common/debug/console/index.d.ts +2 -0
- package/build/common/debug/index.d.ts +2 -0
- package/build/common/debug/stack-trace/fixStackTrace.d.ts +1 -0
- package/build/common/debug/stack-trace/getCallerStackFrame.d.ts +2 -0
- package/build/common/debug/stack-trace/getStackTrace.d.ts +1 -0
- package/build/common/debug/stack-trace/index.d.ts +2 -0
- package/build/common/debug/stack-trace/parseStackTrace.d.ts +8 -0
- package/build/common/index.cjs +1 -0
- package/build/common/index.d.ts +10 -0
- package/build/common/index.mjs +53 -0
- package/build/common/number/floatAsInt.d.ts +7 -0
- package/build/common/number/index.d.ts +2 -0
- package/build/common/number/minMax.d.ts +10 -0
- package/build/common/number/numberMod.d.ts +2 -0
- package/build/common/number/prime.d.ts +3 -0
- package/build/common/number/round.d.ts +19 -0
- package/build/common/object/deepCloneJsonLike.d.ts +6 -0
- package/build/common/object/deepEqualJsonLike.d.ts +6 -0
- package/build/common/object/deepEqualJsonLikeMap.d.ts +5 -0
- package/build/common/object/equalArray.d.ts +2 -0
- package/build/common/object/getNormalizedObject.d.ts +1 -0
- package/build/common/object/index.d.ts +5 -0
- package/build/common/random/Random.d.ts +16 -0
- package/build/common/random/createUniquePseudoRandom.d.ts +6 -0
- package/build/common/random/helpers.d.ts +9 -0
- package/build/common/random/index.d.ts +3 -0
- package/build/common/string/color/rgbaToHex.d.ts +2 -0
- package/build/common/string/escape/escapeHtml.d.ts +2 -0
- package/build/common/string/escape/escapeRegExp.d.ts +2 -0
- package/build/common/string/escape/index.d.ts +2 -0
- package/build/common/string/format/formatAny.d.ts +9 -0
- package/build/common/string/format/formatDate.d.ts +4 -0
- package/build/common/string/format/formatDateFileName.d.ts +4 -0
- package/build/common/string/format/getObjectId.d.ts +2 -0
- package/build/common/string/format/index.d.ts +3 -0
- package/build/common/string/index.d.ts +2 -0
- package/build/common/time/dateNowUnique.d.ts +5 -0
- package/build/common/time/dateToString.d.ts +2 -0
- package/build/common/time/getDateInet.d.ts +8 -0
- package/build/common/time/index.d.ts +3 -0
- package/build/common/time/timeZone.d.ts +2 -0
- package/build/common/types/common.d.ts +21 -0
- package/build/common/types/index.d.ts +1 -0
- package/build/common/url/index.d.ts +1 -0
- package/build/common/url/urlGet.d.ts +8 -0
- package/build/node/fs/fileLock.d.ts +6 -0
- package/build/node/fs/glob/createMatchPath.d.ts +28 -0
- package/build/node/fs/glob/globGitIgnoreToPicomatch.d.ts +1 -0
- package/build/node/fs/glob/globToRelative.d.ts +6 -0
- package/build/node/fs/glob/index.d.ts +4 -0
- package/build/node/fs/glob/loadGlobs.d.ts +19 -0
- package/build/node/fs/index.d.ts +5 -0
- package/build/node/fs/pathNormalize.d.ts +2 -0
- package/build/node/fs/pools.d.ts +2 -0
- package/build/node/fs/walk/helpers.d.ts +4 -0
- package/build/node/fs/walk/index.d.ts +2 -0
- package/build/node/fs/walk/walkPaths.d.ts +52 -0
- package/build/node/index.cjs +2 -0
- package/build/node/index.d.ts +2 -0
- package/build/node/index.mjs +348 -0
- package/build/urlGet-B8-MSnoY.mjs +764 -0
- package/build/urlGet-CZFNBQ4G.js +11 -0
- package/package.json +137 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Unlimited Free Licence
|
|
2
|
+
|
|
3
|
+
Point one: Everyone can do whatever they want with this code, except to limit others from using point one.
|
|
4
|
+
Point two: Whoever and whatever does with this code, it does not entail any obligations for anyone to the author.
|
|
5
|
+
Point three: The author is not responsible for anything.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[![NPM Version][npm-image]][npm-url]
|
|
2
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
3
|
+
[![Build Status][github-image]][github-url]
|
|
4
|
+
<!-- [![Test Coverage][coveralls-image]][coveralls-url] -->
|
|
5
|
+
|
|
6
|
+
Simple simple utils
|
|
7
|
+
|
|
8
|
+
# License
|
|
9
|
+
|
|
10
|
+
[Unlimited Free](LICENSE)
|
|
11
|
+
|
|
12
|
+
[npm-image]: https://img.shields.io/npm/v/@flemist/simple-utils.svg
|
|
13
|
+
[npm-url]: https://npmjs.org/package/@flemist/simple-utils
|
|
14
|
+
[downloads-image]: https://img.shields.io/npm/dm/@flemist/simple-utils.svg
|
|
15
|
+
[downloads-url]: https://npmjs.org/package/@flemist/simple-utils
|
|
16
|
+
[github-image]: https://github.com/NikolayMakhonin/simple-utils/actions/workflows/test.yml/badge.svg
|
|
17
|
+
[github-url]: https://github.com/NikolayMakhonin/simple-utils/actions
|
|
18
|
+
[coveralls-image]: https://coveralls.io/repos/github/NikolayMakhonin/simple-utils/badge.svg
|
|
19
|
+
[coveralls-url]: https://coveralls.io/github/NikolayMakhonin/simple-utils
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../urlGet-CZFNBQ4G.js");exports.ConsoleMessageLevel=e.ConsoleMessageLevel;exports.Lazy=e.Lazy;exports.LazyWithId=e.LazyWithId;exports.Random=e.Random;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=e.UNIQUE_PSEUDO_RANDOM_MAX_COUNT;exports.alertReplace=e.alertReplace;exports.consoleReplace=e.consoleReplace;exports.convertTimeZone=e.convertTimeZone;exports.createUniquePseudoRandom=e.createUniquePseudoRandom;exports.dateNowUnique=e.dateNowUnique;exports.deepCloneJsonLike=e.deepCloneJsonLike;exports.deepEqualJsonLike=e.deepEqualJsonLike;exports.deepEqualJsonLikeMap=e.deepEqualJsonLikeMap;exports.equalArray=e.equalArray;exports.escapeHtml=e.escapeHtml;exports.escapeRegExp=e.escapeRegExp;exports.fixStackTrace=e.fixStackTrace;exports.formatAny=e.formatAny;exports.formatDate=e.formatDate;exports.formatDateFileName=e.formatDateFileName;exports.getDateInet=e.getDateInet;exports.getNormalizedObject=e.getNormalizedObject;exports.getRandomFunc=e.getRandomFunc;exports.getRandomSeed=e.getRandomSeed;exports.getStackTrace=e.getStackTrace;exports.max=e.max;exports.min=e.min;exports.minMax=e.minMax;exports.numberMod=e.numberMod;exports.randomBoolean=e.randomBoolean;exports.randomEnum=e.randomEnum;exports.randomFloat=e.randomFloat;exports.randomIndexWeighted=e.randomIndexWeighted;exports.randomInt=e.randomInt;exports.randomItem=e.randomItem;exports.randomItems=e.randomItems;exports.sha256=e.sha256;exports.sha256Buffer=e.sha256Buffer;exports.timeoutAbortController=e.timeoutAbortController;exports.toHex=e.toHex;exports.urlGetBoolean=e.urlGetBoolean;exports.urlGetFloat=e.urlGetFloat;exports.urlGetInt=e.urlGetInt;exports.urlGetParams=e.urlGetParams;exports.urlGetString=e.urlGetString;exports.urlParamToBoolean=e.urlParamToBoolean;exports.urlParamToFloat=e.urlParamToFloat;exports.urlParamToInt=e.urlParamToInt;exports.withConsoleReplace=e.withConsoleReplace;exports.withTimeout=e.withTimeout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../common';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { F as s, M as o, N as t, R as n, U as r, E as m, G as l, q as d, l as u, o as i, z as c, A as p, B as g, C as I, x as R, y as T, I as f, u as x, v as h, w as E, p as L, D as M, d as N, g as P, J as U, b as k, m as q, c as A, n as C, f as D, k as F, r as G, h as S, e as y, i as B, j as O, a as b, s as w, K as z, t as J, V as _, X as v, W as H, O as W, T as j, P as Q, S as X, Q as K, H as V, L as Z } from "../urlGet-B8-MSnoY.mjs";
|
|
2
|
+
export {
|
|
3
|
+
s as ConsoleMessageLevel,
|
|
4
|
+
o as Lazy,
|
|
5
|
+
t as LazyWithId,
|
|
6
|
+
n as Random,
|
|
7
|
+
r as UNIQUE_PSEUDO_RANDOM_MAX_COUNT,
|
|
8
|
+
m as alertReplace,
|
|
9
|
+
l as consoleReplace,
|
|
10
|
+
d as convertTimeZone,
|
|
11
|
+
u as createUniquePseudoRandom,
|
|
12
|
+
i as dateNowUnique,
|
|
13
|
+
c as deepCloneJsonLike,
|
|
14
|
+
p as deepEqualJsonLike,
|
|
15
|
+
g as deepEqualJsonLikeMap,
|
|
16
|
+
I as equalArray,
|
|
17
|
+
R as escapeHtml,
|
|
18
|
+
T as escapeRegExp,
|
|
19
|
+
f as fixStackTrace,
|
|
20
|
+
x as formatAny,
|
|
21
|
+
h as formatDate,
|
|
22
|
+
E as formatDateFileName,
|
|
23
|
+
L as getDateInet,
|
|
24
|
+
M as getNormalizedObject,
|
|
25
|
+
N as getRandomFunc,
|
|
26
|
+
P as getRandomSeed,
|
|
27
|
+
U as getStackTrace,
|
|
28
|
+
k as max,
|
|
29
|
+
q as min,
|
|
30
|
+
A as minMax,
|
|
31
|
+
C as numberMod,
|
|
32
|
+
D as randomBoolean,
|
|
33
|
+
F as randomEnum,
|
|
34
|
+
G as randomFloat,
|
|
35
|
+
S as randomIndexWeighted,
|
|
36
|
+
y as randomInt,
|
|
37
|
+
B as randomItem,
|
|
38
|
+
O as randomItems,
|
|
39
|
+
b as sha256,
|
|
40
|
+
w as sha256Buffer,
|
|
41
|
+
z as timeoutAbortController,
|
|
42
|
+
J as toHex,
|
|
43
|
+
_ as urlGetBoolean,
|
|
44
|
+
v as urlGetFloat,
|
|
45
|
+
H as urlGetInt,
|
|
46
|
+
W as urlGetParams,
|
|
47
|
+
j as urlGetString,
|
|
48
|
+
Q as urlParamToBoolean,
|
|
49
|
+
X as urlParamToFloat,
|
|
50
|
+
K as urlParamToInt,
|
|
51
|
+
V as withConsoleReplace,
|
|
52
|
+
Z as withTimeout
|
|
53
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IAbortSignalFast } from '@flemist/abort-controller-fast';
|
|
2
|
+
import { TimeoutArgs } from './timeoutAbortController';
|
|
3
|
+
export declare function withTimeout<T>(func: (abortSignal: IAbortSignalFast | null) => Promise<T>, args: undefined | null | TimeoutArgs): Promise<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAbortControllerFast, IAbortSignalFast } from '@flemist/abort-controller-fast';
|
|
2
|
+
import { ITimeController } from '@flemist/time-controller';
|
|
3
|
+
export type TimeoutArgs = {
|
|
4
|
+
abortSignal?: null | IAbortSignalFast;
|
|
5
|
+
timeout?: null | number;
|
|
6
|
+
timeController?: ITimeController;
|
|
7
|
+
};
|
|
8
|
+
export declare function timeoutAbortController(args: undefined | null | TimeoutArgs): IAbortControllerFast | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PromiseOrValue } from '@flemist/async-utils';
|
|
2
|
+
export interface ILazy<T = void> {
|
|
3
|
+
run(): PromiseOrValue<T>;
|
|
4
|
+
}
|
|
5
|
+
export type LazyOptions<T> = {
|
|
6
|
+
func: () => PromiseOrValue<T>;
|
|
7
|
+
/** If true, the result will be cached */
|
|
8
|
+
persist?: null | boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare class Lazy<T = void> implements ILazy<T> {
|
|
11
|
+
private readonly _options;
|
|
12
|
+
private _hasValue;
|
|
13
|
+
private _promiseOrValue;
|
|
14
|
+
constructor(options: LazyOptions<T>);
|
|
15
|
+
run(): PromiseOrValue<T>;
|
|
16
|
+
set(value: PromiseOrValue<T>): void;
|
|
17
|
+
}
|
|
18
|
+
export interface ILazyWithId<Id, Result = void> {
|
|
19
|
+
run(id: Id): PromiseOrValue<Result>;
|
|
20
|
+
}
|
|
21
|
+
export type LazyWithIdOptions<Id, Result> = {
|
|
22
|
+
func: (id: Id) => PromiseOrValue<Result>;
|
|
23
|
+
persist?: null | boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare class LazyWithId<Id, Result = void> implements ILazyWithId<Id, Result> {
|
|
26
|
+
private readonly _options;
|
|
27
|
+
private _promiseOrValues;
|
|
28
|
+
constructor(options: LazyWithIdOptions<Id, Result>);
|
|
29
|
+
run(id: Id): PromiseOrValue<Result>;
|
|
30
|
+
set(id: Id, value: PromiseOrValue<Result>): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates SHA-256 and returns the raw hash as a Uint8Array (32 bytes).
|
|
3
|
+
*/
|
|
4
|
+
export declare function sha256Buffer(content: string | ArrayBufferView): Uint8Array;
|
|
5
|
+
export declare function sha256Buffer(content: null | undefined | string | ArrayBufferView): Uint8Array | null;
|
|
6
|
+
/**
|
|
7
|
+
* Calculates SHA-256 and returns a Hex string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sha256(content: string | ArrayBufferView): string;
|
|
10
|
+
export declare function sha256(content: null | undefined | string | ArrayBufferView): string | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum ConsoleMessageLevel {
|
|
2
|
+
log = "log",
|
|
3
|
+
warn = "warn",
|
|
4
|
+
error = "error",
|
|
5
|
+
info = "info",
|
|
6
|
+
debug = "debug",
|
|
7
|
+
trace = "trace",
|
|
8
|
+
assert = "assert"
|
|
9
|
+
}
|
|
10
|
+
export type Console = Record<ConsoleMessageLevel, (...args: any[]) => void>;
|
|
11
|
+
export declare function consoleReplace(handler: (console: Console, level: ConsoleMessageLevel, args: any[]) => void): () => void;
|
|
12
|
+
export type WithConsoleReplaceFunc = <T>(callback: () => T) => T;
|
|
13
|
+
export declare function withConsoleReplace(handler: (console: Console, level: ConsoleMessageLevel, args: any[]) => void): WithConsoleReplaceFunc;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fixStackTrace<This, Args extends any[], Return>(func: (this: This, ...args: Args) => Return): (this: This, ...args: Args) => Return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getStackTrace(): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type StackFrame = {
|
|
2
|
+
func: string | undefined | null;
|
|
3
|
+
file: string | undefined | null;
|
|
4
|
+
line: number | undefined | null;
|
|
5
|
+
column: number | undefined | null;
|
|
6
|
+
};
|
|
7
|
+
/** @deprecated Пока не ясно нужно ли это */
|
|
8
|
+
export declare function parseStackTrace(stackTrace: string, maxFrames?: null | number): StackFrame[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../urlGet-CZFNBQ4G.js");exports.ConsoleMessageLevel=e.ConsoleMessageLevel;exports.Lazy=e.Lazy;exports.LazyWithId=e.LazyWithId;exports.Random=e.Random;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=e.UNIQUE_PSEUDO_RANDOM_MAX_COUNT;exports.alertReplace=e.alertReplace;exports.consoleReplace=e.consoleReplace;exports.convertTimeZone=e.convertTimeZone;exports.createUniquePseudoRandom=e.createUniquePseudoRandom;exports.dateNowUnique=e.dateNowUnique;exports.deepCloneJsonLike=e.deepCloneJsonLike;exports.deepEqualJsonLike=e.deepEqualJsonLike;exports.deepEqualJsonLikeMap=e.deepEqualJsonLikeMap;exports.equalArray=e.equalArray;exports.escapeHtml=e.escapeHtml;exports.escapeRegExp=e.escapeRegExp;exports.fixStackTrace=e.fixStackTrace;exports.formatAny=e.formatAny;exports.formatDate=e.formatDate;exports.formatDateFileName=e.formatDateFileName;exports.getDateInet=e.getDateInet;exports.getNormalizedObject=e.getNormalizedObject;exports.getRandomFunc=e.getRandomFunc;exports.getRandomSeed=e.getRandomSeed;exports.getStackTrace=e.getStackTrace;exports.max=e.max;exports.min=e.min;exports.minMax=e.minMax;exports.numberMod=e.numberMod;exports.randomBoolean=e.randomBoolean;exports.randomEnum=e.randomEnum;exports.randomFloat=e.randomFloat;exports.randomIndexWeighted=e.randomIndexWeighted;exports.randomInt=e.randomInt;exports.randomItem=e.randomItem;exports.randomItems=e.randomItems;exports.sha256=e.sha256;exports.sha256Buffer=e.sha256Buffer;exports.timeoutAbortController=e.timeoutAbortController;exports.toHex=e.toHex;exports.urlGetBoolean=e.urlGetBoolean;exports.urlGetFloat=e.urlGetFloat;exports.urlGetInt=e.urlGetInt;exports.urlGetParams=e.urlGetParams;exports.urlGetString=e.urlGetString;exports.urlParamToBoolean=e.urlParamToBoolean;exports.urlParamToFloat=e.urlParamToFloat;exports.urlParamToInt=e.urlParamToInt;exports.withConsoleReplace=e.withConsoleReplace;exports.withTimeout=e.withTimeout;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './crypto';
|
|
2
|
+
export * from './number';
|
|
3
|
+
export * from './random';
|
|
4
|
+
export * from './time';
|
|
5
|
+
export * from './string';
|
|
6
|
+
export * from './object';
|
|
7
|
+
export * from './debug';
|
|
8
|
+
export * from './async';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './url';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { F as s, M as o, N as t, R as n, U as r, E as m, G as l, q as d, l as u, o as i, z as c, A as p, B as g, C as I, x as R, y as T, I as f, u as x, v as h, w as E, p as L, D as M, d as N, g as P, J as U, b as k, m as q, c as A, n as C, f as D, k as F, r as G, h as S, e as y, i as B, j as O, a as b, s as w, K as z, t as J, V as _, X as v, W as H, O as W, T as j, P as Q, S as X, Q as K, H as V, L as Z } from "../urlGet-B8-MSnoY.mjs";
|
|
2
|
+
export {
|
|
3
|
+
s as ConsoleMessageLevel,
|
|
4
|
+
o as Lazy,
|
|
5
|
+
t as LazyWithId,
|
|
6
|
+
n as Random,
|
|
7
|
+
r as UNIQUE_PSEUDO_RANDOM_MAX_COUNT,
|
|
8
|
+
m as alertReplace,
|
|
9
|
+
l as consoleReplace,
|
|
10
|
+
d as convertTimeZone,
|
|
11
|
+
u as createUniquePseudoRandom,
|
|
12
|
+
i as dateNowUnique,
|
|
13
|
+
c as deepCloneJsonLike,
|
|
14
|
+
p as deepEqualJsonLike,
|
|
15
|
+
g as deepEqualJsonLikeMap,
|
|
16
|
+
I as equalArray,
|
|
17
|
+
R as escapeHtml,
|
|
18
|
+
T as escapeRegExp,
|
|
19
|
+
f as fixStackTrace,
|
|
20
|
+
x as formatAny,
|
|
21
|
+
h as formatDate,
|
|
22
|
+
E as formatDateFileName,
|
|
23
|
+
L as getDateInet,
|
|
24
|
+
M as getNormalizedObject,
|
|
25
|
+
N as getRandomFunc,
|
|
26
|
+
P as getRandomSeed,
|
|
27
|
+
U as getStackTrace,
|
|
28
|
+
k as max,
|
|
29
|
+
q as min,
|
|
30
|
+
A as minMax,
|
|
31
|
+
C as numberMod,
|
|
32
|
+
D as randomBoolean,
|
|
33
|
+
F as randomEnum,
|
|
34
|
+
G as randomFloat,
|
|
35
|
+
S as randomIndexWeighted,
|
|
36
|
+
y as randomInt,
|
|
37
|
+
B as randomItem,
|
|
38
|
+
O as randomItems,
|
|
39
|
+
b as sha256,
|
|
40
|
+
w as sha256Buffer,
|
|
41
|
+
z as timeoutAbortController,
|
|
42
|
+
J as toHex,
|
|
43
|
+
_ as urlGetBoolean,
|
|
44
|
+
v as urlGetFloat,
|
|
45
|
+
H as urlGetInt,
|
|
46
|
+
W as urlGetParams,
|
|
47
|
+
j as urlGetString,
|
|
48
|
+
Q as urlParamToBoolean,
|
|
49
|
+
X as urlParamToFloat,
|
|
50
|
+
K as urlParamToInt,
|
|
51
|
+
V as withConsoleReplace,
|
|
52
|
+
Z as withTimeout
|
|
53
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated (work with number string instead of calc)
|
|
3
|
+
* Safe converts an integer cents to float: 123 → 1.23
|
|
4
|
+
*/
|
|
5
|
+
export declare function intAsFloat<T extends number | null | undefined>(value: T, decimals: number): T;
|
|
6
|
+
/** @deprecated (work with number string instead of calc) Safe converts a float to integer cents: 1.23 → 123 */
|
|
7
|
+
export declare function floatAsInt<T extends number | null | undefined>(value: T, decimals: number): T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function min(a: number, b: number | null | undefined): number;
|
|
2
|
+
export declare function min(a: number | null | undefined, b: number): number;
|
|
3
|
+
export declare function min(a: number | null | undefined, b: number | null | undefined): number | null | undefined;
|
|
4
|
+
export declare function max(a: number, b: number | null | undefined): number;
|
|
5
|
+
export declare function max(a: number | null | undefined, b: number): number;
|
|
6
|
+
export declare function max(a: number | null | undefined, b: number | null | undefined): number | null | undefined;
|
|
7
|
+
export declare function minMax(value: number, min: number | null | undefined, max: number | null | undefined): number;
|
|
8
|
+
export declare function minMax(value: number | null | undefined, min: number, max: number | null | undefined): number;
|
|
9
|
+
export declare function minMax(value: number | null | undefined, min: number | null | undefined, max: number): number;
|
|
10
|
+
export declare function minMax(value: number | null | undefined, _min: number | null | undefined, _max: number | null | undefined): number | null | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const MAX_FLOAT_PRECISION = 13;
|
|
2
|
+
/** @deprecated (work with number string instead of calc) Safe rounding to N significant digits; prevents "messy" float tails in toString(). */
|
|
3
|
+
export declare function roundPrecision(value: number, digits: number): number;
|
|
4
|
+
/** @deprecated (work with number string instead of calc) Safe floor to N significant digits; prevents "messy" float tails in toString(). */
|
|
5
|
+
export declare function floorPrecision(value: number, digits: number): number;
|
|
6
|
+
/** @deprecated (work with number string instead of calc) Safe ceil to N significant digits; prevents "messy" float tails in toString(). */
|
|
7
|
+
export declare function ceilPrecision(value: number, digits: number): number;
|
|
8
|
+
/** @deprecated (work with number string instead of calc) Safe rounding to N decimal places; prevents "messy" float tails in toString(). */
|
|
9
|
+
export declare function roundFraction(value: number, fractionDigits?: number): number;
|
|
10
|
+
/** @deprecated (work with number string instead of calc) Safe floor to N decimal places; prevents "messy" float tails in toString(). */
|
|
11
|
+
export declare function floorFraction(value: number, fractionDigits?: number): number;
|
|
12
|
+
/** @deprecated (work with number string instead of calc) Safe ceil to N decimal places; prevents "messy" float tails in toString(). */
|
|
13
|
+
export declare function ceilFraction(value: number, fractionDigits?: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated (work with number string instead of calc) Safe cleanup float to prevent "messy" float tails in toString()
|
|
16
|
+
* @example 0.0000000000001 => 0
|
|
17
|
+
* @example 0.9999999999999 => 1
|
|
18
|
+
*/
|
|
19
|
+
export declare function fixFloat(value: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getNormalizedObject<T>(obj: T): T;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function getRandomSeed(): number;
|
|
2
|
+
export declare function getRandomFunc(seed?: null | number): () => number;
|
|
3
|
+
/**
|
|
4
|
+
* Generate random number in range [0..1) like Math.random() or other,
|
|
5
|
+
* but can be pseudorandom with seed
|
|
6
|
+
*/
|
|
7
|
+
export declare class Random {
|
|
8
|
+
private readonly _seed;
|
|
9
|
+
private readonly _rnd;
|
|
10
|
+
constructor(seed?: null | number);
|
|
11
|
+
get seed(): number | null | undefined;
|
|
12
|
+
nextSeed(): number;
|
|
13
|
+
nextRandom(): Random;
|
|
14
|
+
next(): number;
|
|
15
|
+
clone(): Random;
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const UNIQUE_PSEUDO_RANDOM_MAX_COUNT: number;
|
|
2
|
+
/**
|
|
3
|
+
* Very simple algorithm for generating unique pseudo-random numbers in range 0..count-1
|
|
4
|
+
* Some kind of shuffle without extra memory allocation
|
|
5
|
+
*/
|
|
6
|
+
export declare function createUniquePseudoRandom(count?: number, startFrom?: null | number): () => number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Random } from './Random';
|
|
2
|
+
export declare function randomFloat(rnd: Random, from: number, toExclusive?: null | number): number;
|
|
3
|
+
export declare function randomInt(rnd: Random, from: number, toExclusive?: null | number): number;
|
|
4
|
+
export declare function randomBoolean(rnd: Random, trueProbability?: null | number): boolean;
|
|
5
|
+
export declare function randomIndexWeighted(rnd: Random, weights: number[]): number;
|
|
6
|
+
export declare function randomIndexWeighted(rnd: Random, length: number, getWeight: (index: number) => number): number;
|
|
7
|
+
export declare function randomItem<T>(rnd: Random, items: ArrayLike<T>): T;
|
|
8
|
+
export declare function randomItems<T>(rnd: Random, items: T[], count: number): T[];
|
|
9
|
+
export declare function randomEnum<EnumType extends Record<string, any>>(rnd: Random, enumType: EnumType, predicate?: null | ((value: EnumType[keyof EnumType]) => boolean)): EnumType[keyof EnumType];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function formatAny(obj: any, options?: {
|
|
2
|
+
pretty?: boolean;
|
|
3
|
+
filter?: null | ((path: string[], value: any) => boolean);
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
maxItems?: number;
|
|
6
|
+
showObjectId?: boolean;
|
|
7
|
+
showArrayIndex?: boolean;
|
|
8
|
+
customToString?: null | ((obj: any, toString: (obj: any) => any) => string | null | undefined | void);
|
|
9
|
+
}, path?: string[], visited?: Set<any>): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type Obj = Record<string, any>;
|
|
2
|
+
export type PartialWithNull<T, Keys extends keyof T = keyof T> = {
|
|
3
|
+
[P in Keys]?: T[P] | null;
|
|
4
|
+
} & Omit<T, Keys>;
|
|
5
|
+
export type RequiredNonNullable<T, Keys extends keyof T = keyof T> = {
|
|
6
|
+
[P in Keys]-?: NonNullable<T[P]>;
|
|
7
|
+
} & Omit<T, Keys>;
|
|
8
|
+
export type NumberRangeOptional = [
|
|
9
|
+
from: number | undefined | null,
|
|
10
|
+
to: number | undefined | null
|
|
11
|
+
];
|
|
12
|
+
export type NumberRange = [from: number, to: number];
|
|
13
|
+
export type PromiseOrValue<T> = T | Promise<T>;
|
|
14
|
+
export type Unsubscribe = () => void;
|
|
15
|
+
export type Func<This, Args extends any[], Result> = (this: This, ...args: Args) => Result;
|
|
16
|
+
export type Mutable<T> = {
|
|
17
|
+
-readonly [P in keyof T]: T[P];
|
|
18
|
+
};
|
|
19
|
+
export type Ref<T> = {
|
|
20
|
+
value: T;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './urlGet';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function urlGetParams(urlOrParams?: null | string | URL | URLSearchParams): URLSearchParams;
|
|
2
|
+
export declare function urlParamToBoolean(paramValue: string | null | undefined): boolean | null;
|
|
3
|
+
export declare function urlParamToInt(paramValue: string | null | undefined): number | null;
|
|
4
|
+
export declare function urlParamToFloat(paramValue: string | null | undefined): number | null;
|
|
5
|
+
export declare function urlGetString(paramName: any, urlOrParams?: null | string | URL | URLSearchParams): string | null;
|
|
6
|
+
export declare function urlGetBoolean(paramName: any, urlOrParams?: null | string | URL | URLSearchParams): boolean | null;
|
|
7
|
+
export declare function urlGetInt(paramName: any, urlOrParams?: null | string | URL | URLSearchParams): number | null;
|
|
8
|
+
export declare function urlGetFloat(paramName: any, urlOrParams?: null | string | URL | URLSearchParams): number | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type FileLockOptions<Result> = {
|
|
2
|
+
filePath: string;
|
|
3
|
+
func: () => Promise<Result>;
|
|
4
|
+
};
|
|
5
|
+
/** Execute func with exclusive file access and limited parallel file operations */
|
|
6
|
+
export declare function fileLock<Result>(options: FileLockOptions<Result>): Promise<Result>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* true - include the path
|
|
3
|
+
* false - exclude the path
|
|
4
|
+
* null - no match, do default action
|
|
5
|
+
*/
|
|
6
|
+
export type MatchPath = (path: string) => boolean | null;
|
|
7
|
+
export type CreateMatchPathOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Behavior:
|
|
10
|
+
* let include = false
|
|
11
|
+
* let exclude = false
|
|
12
|
+
*
|
|
13
|
+
* for each glob:
|
|
14
|
+
* if glob matched
|
|
15
|
+
* if pattern is `glob` then include = true; exclude = false
|
|
16
|
+
* if pattern is `!glob` then include = false; exclude = false
|
|
17
|
+
* if pattern is `^glob` then exclude = true
|
|
18
|
+
* if pattern is `^!glob` then exclude = false
|
|
19
|
+
* if pattern is `!^glob` then incorrect should throw error
|
|
20
|
+
*
|
|
21
|
+
* result = include && !exclude
|
|
22
|
+
*/
|
|
23
|
+
globs: string[];
|
|
24
|
+
rootDir?: string | null;
|
|
25
|
+
noCase?: null | boolean;
|
|
26
|
+
};
|
|
27
|
+
/** .gitignore-like path matching function */
|
|
28
|
+
export declare function createMatchPath({ globs, rootDir, noCase, }: CreateMatchPathOptions): MatchPath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function globGitIgnoreToPicomatch(glob: string): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param glob - .gitignore glob pattern
|
|
3
|
+
* @param relativePath - relative path from the directory where the glob should be applied
|
|
4
|
+
* @return - glob pattern relative to the given path
|
|
5
|
+
*/
|
|
6
|
+
export declare function globToRelative(glob: string, relativePath: string): string;
|