@augment-vir/common 31.14.1 → 31.15.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/augments/array/array-map.d.ts +2 -2
- package/dist/augments/array/create-array.d.ts +1 -1
- package/dist/augments/enum/enum-value-check.d.ts +1 -1
- package/dist/augments/function/debounce.d.ts +1 -1
- package/dist/augments/function/execution-duration.d.ts +1 -1
- package/dist/augments/json/append-json.d.ts +1 -2
- package/dist/augments/json/copy-through-json.d.ts +1 -1
- package/dist/augments/json/jsonify.d.ts +1 -1
- package/dist/augments/log/log-string.d.ts +1 -1
- package/dist/augments/log/log.d.ts +2 -2
- package/dist/augments/log/logger.d.ts +1 -1
- package/dist/augments/number/clamp.d.ts +1 -1
- package/dist/augments/number/wrap-number.d.ts +1 -1
- package/dist/augments/object/diff.d.ts +1 -1
- package/dist/augments/object/empty.d.ts +1 -1
- package/dist/augments/object/get-or-set.d.ts +1 -1
- package/dist/augments/object/map-entries.d.ts +1 -1
- package/dist/augments/object/map-enum.d.ts +1 -1
- package/dist/augments/object/merge-deep.d.ts +1 -1
- package/dist/augments/object/merge-defined-properties.d.ts +1 -1
- package/dist/augments/object/object-entries.d.ts +1 -1
- package/dist/augments/object/object-values.d.ts +1 -1
- package/dist/augments/prisma/base-prisma-types.d.ts +1 -1
- package/dist/augments/prisma/prisma-basic-model.d.ts +4 -4
- package/dist/augments/prisma/prisma-full-model.d.ts +3 -3
- package/dist/augments/prisma/prisma-model-create.d.ts +8 -8
- package/dist/augments/prisma/prisma-model-create.js +2 -2
- package/dist/augments/prisma/prisma-model-name.d.ts +3 -3
- package/dist/augments/promise/promise-object.d.ts +1 -1
- package/dist/augments/promise/promise-queue.d.ts +1 -1
- package/dist/augments/promise/timed-promise.d.ts +1 -1
- package/dist/augments/random/seeded-random.d.ts +57 -0
- package/dist/augments/random/seeded-random.js +140 -0
- package/dist/augments/selection-set/select-collapsed.d.ts +5 -5
- package/dist/augments/selection-set/select-from.d.ts +2 -2
- package/dist/augments/string/casing/capitalization.d.ts +1 -1
- package/dist/augments/string/casing/casing.d.ts +1 -1
- package/dist/augments/string/casing/kebab-and-camel.d.ts +1 -1
- package/dist/augments/string/split.d.ts +1 -1
- package/dist/augments/string/white-space.d.ts +1 -1
- package/dist/augments/type/type-recursion.d.ts +20 -20
- package/dist/augments/type/writable.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { Writable } from '../type/writable.js';
|
|
1
|
+
import { type ArrayElement } from '@augment-vir/core';
|
|
2
|
+
import { type Writable } from '../type/writable.js';
|
|
3
3
|
/**
|
|
4
4
|
* Performs
|
|
5
5
|
* [`[].map()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tuple } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Creates an array of size `size` and calls the given `callback` for each entry in the array and
|
|
4
4
|
* fills the array with the results. The returned array is typed to exactly fit the given size.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Duration, DurationUnit } from '@date-vir/duration';
|
|
1
|
+
import { type Duration, type DurationUnit } from '@date-vir/duration';
|
|
2
2
|
/**
|
|
3
3
|
* Measures how long (in milliseconds) the given callback takes to run to completion. By default
|
|
4
4
|
* this is synchronous, but it will automatically switch to async and await the callback if it
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { JsonCompatiblePrimitive } from '@augment-vir/core';
|
|
1
|
+
import { type JsonCompatibleArray, type JsonCompatibleObject, type JsonCompatiblePrimitive, type JsonCompatibleValue } from '@augment-vir/core';
|
|
3
2
|
export declare function appendJson(entry: JsonCompatibleArray | JsonCompatiblePrimitive, ...entries: ReadonlyArray<JsonCompatibleValue | undefined>): JsonCompatibleArray;
|
|
4
3
|
export declare function appendJson(entry: JsonCompatibleObject, ...entries: ReadonlyArray<JsonCompatibleObject | JsonCompatibleArray | undefined>): JsonCompatibleObject;
|
|
5
4
|
export declare function appendJson(...entries: ReadonlyArray<JsonCompatibleValue | undefined>): JsonCompatibleObject | JsonCompatibleArray;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Jsonify, Writable } from 'type-fest';
|
|
1
|
+
import { type Jsonify, type Writable } from 'type-fest';
|
|
2
2
|
/**
|
|
3
3
|
* Deeply copy an object through JSON. This is the fastest deep copy, but the input must already be
|
|
4
4
|
* JSON serializable otherwise the copy will not match the original.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PartialWithUndefined } from '@augment-vir/core';
|
|
2
|
-
import { LoggerOptions } from './log-string.js';
|
|
3
|
-
import { LogWriters } from './log-writer.js';
|
|
2
|
+
import { type LoggerOptions } from './log-string.js';
|
|
3
|
+
import { type LogWriters } from './log-writer.js';
|
|
4
4
|
import { type Logger } from './logger.js';
|
|
5
5
|
/**
|
|
6
6
|
* Default implementation of {@link LogWriters} that is dependent on the current runtime environment.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/core';
|
|
2
2
|
import { LogColorKey } from './log-colors.js';
|
|
3
3
|
import { type LoggerOptions } from './log-string.js';
|
|
4
4
|
import { type LogWriters } from './log-writer.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MinMax } from '@augment-vir/core';
|
|
1
|
+
import { type MinMax } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* If the given value is outside the given min/max bounds, instead of clamping the number (as the
|
|
4
4
|
* `clamp` function does), this function wraps the value around to the next bound (inclusive).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type AnyObject, type MaybePromise } from '@augment-vir/core';
|
|
2
2
|
export declare function getOrSetFromMap<MapKey extends object, MapValue>(map: WeakMap<MapKey, MapValue>, key: MapKey, createCallback: () => MapValue): MapValue;
|
|
3
3
|
export declare function getOrSetFromMap<MapKey, MapValue>(map: Map<MapKey, MapValue>, key: MapKey, createCallback: () => MapValue): MapValue;
|
|
4
4
|
export declare function getOrSetFromMap<MapKey extends object, MapValue>(map: WeakMap<MapKey, MapValue>, key: MapKey, createCallback: () => Promise<MapValue>): Promise<MapValue>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type MaybePromise, type Values } from '@augment-vir/core';
|
|
2
2
|
export declare function mapObject<const OriginalObject, const NewKey extends PropertyKey, const NewValue>(inputObject: OriginalObject, mapCallback: (originalKey: keyof OriginalObject, originalValue: Values<OriginalObject>, originalObject: OriginalObject) => Promise<{
|
|
3
3
|
key: NewKey;
|
|
4
4
|
value: NewValue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyObject, type PartialWithNullable } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Merge all objects together but ignore any override values that are `undefined` or `null` or
|
|
4
4
|
* missing. This only merges objects at the top level, it is not a deep merge.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompleteRequire } from '@augment-vir/core';
|
|
1
|
+
import { type CompleteRequire } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Gets an object's entries. This is the same as
|
|
4
4
|
* [`Object.entries`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompleteRequire } from '@augment-vir/core';
|
|
1
|
+
import { type CompleteRequire } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Gets an object's values. This is the same as
|
|
4
4
|
* [`Object.values`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type AnyFunction, type AnyObject } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* A base type for Prisma model payloads because Prisma doesn't give us one. This currently only
|
|
4
4
|
* includes the properties that are used within this package.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type BasePrismaClient } from './base-prisma-types.js';
|
|
2
|
+
import { type PrismaModelName } from './prisma-model-name.js';
|
|
3
3
|
/**
|
|
4
4
|
* A basic model entry with only its immediate properties.
|
|
5
5
|
*
|
|
@@ -8,8 +8,8 @@ import type { PrismaModelName } from './prisma-model-name.js';
|
|
|
8
8
|
* @example
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* import type
|
|
12
|
-
* import type
|
|
11
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
12
|
+
* import {type PrismaBasicModel} from '@augment-vir/common';
|
|
13
13
|
*
|
|
14
14
|
* function doThing(fullModel: PrismaBasicModel<PrismaClient, 'user'>) {}
|
|
15
15
|
* ```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BasePrismaClient, type BasePrismaPayload } from './base-prisma-types.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type PrismaModelName } from './prisma-model-name.js';
|
|
3
3
|
/**
|
|
4
4
|
* A full model entry with all relations from the given Prisma type map and model name.
|
|
5
5
|
*
|
|
@@ -8,8 +8,8 @@ import type { PrismaModelName } from './prisma-model-name.js';
|
|
|
8
8
|
* @example
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* import type
|
|
12
|
-
* import type
|
|
11
|
+
* import {type Prisma} from '@prisma/client';
|
|
12
|
+
* import {type FullPrismaModel} from '@augment-vir/common';
|
|
13
13
|
*
|
|
14
14
|
* function doThing(fullModel: FullModel<Prisma.TypeMap, 'User'>) {}
|
|
15
15
|
* ```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type BasePrismaClient } from './base-prisma-types.js';
|
|
2
|
+
import { type PrismaModelName } from './prisma-model-name.js';
|
|
3
3
|
/**
|
|
4
4
|
* Use this to define mock entries that _shouldn't_ be saved to the database so that we can easily
|
|
5
5
|
* write tests for missing data.
|
|
@@ -9,7 +9,7 @@ import type { PrismaModelName } from './prisma-model-name.js';
|
|
|
9
9
|
* @example
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
|
-
* import type
|
|
12
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
13
13
|
* import {prismaModelCreateExclude, PrismaKeyedModelCreate} from '@augment-vir/common';
|
|
14
14
|
*
|
|
15
15
|
* export const mockUsers = {
|
|
@@ -38,7 +38,7 @@ export declare const prismaModelCreateExclude: unique symbol;
|
|
|
38
38
|
* @example
|
|
39
39
|
*
|
|
40
40
|
* ```ts
|
|
41
|
-
* import type
|
|
41
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
42
42
|
* import {prismaModelCreateOmitId, PrismaKeyedModelCreate} from '@augment-vir/common';
|
|
43
43
|
*
|
|
44
44
|
* export const mockUsers = {
|
|
@@ -66,8 +66,8 @@ export declare const prismaModelCreateOmitId: unique symbol;
|
|
|
66
66
|
* @example
|
|
67
67
|
*
|
|
68
68
|
* ```ts
|
|
69
|
-
* import type
|
|
70
|
-
* import type
|
|
69
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
70
|
+
* import {type PrismaModelCreate} from '@augment-vir/common';
|
|
71
71
|
*
|
|
72
72
|
* function doThing(entry: PrismaModelCreate<PrismaClient, 'User'>) {}
|
|
73
73
|
* ```
|
|
@@ -89,7 +89,7 @@ export type PrismaModelCreate<PrismaClient extends BasePrismaClient, Model exten
|
|
|
89
89
|
*
|
|
90
90
|
* ```ts
|
|
91
91
|
* import {PrismaKeyedModelCreate} from '@augment-vir/common';
|
|
92
|
-
* import type
|
|
92
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
93
93
|
*
|
|
94
94
|
* const mockUsers = {
|
|
95
95
|
* mockUser1: {
|
|
@@ -121,7 +121,7 @@ export type PrismaKeyedModelCreate<PrismaClient extends BasePrismaClient, Model
|
|
|
121
121
|
*
|
|
122
122
|
* ```ts
|
|
123
123
|
* import {PrismaKeyedModelCreate} from '@augment-vir/common';
|
|
124
|
-
* import type
|
|
124
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
125
125
|
*
|
|
126
126
|
* const mockData: ModelCreateData<PrismaClient> = {
|
|
127
127
|
* user: {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @example
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
|
-
* import type
|
|
10
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
11
11
|
* import {prismaModelCreateExclude, PrismaKeyedModelCreate} from '@augment-vir/common';
|
|
12
12
|
*
|
|
13
13
|
* export const mockUsers = {
|
|
@@ -36,7 +36,7 @@ export const prismaModelCreateExclude = Symbol('prisma-model-create-exclude');
|
|
|
36
36
|
* @example
|
|
37
37
|
*
|
|
38
38
|
* ```ts
|
|
39
|
-
* import type
|
|
39
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
40
40
|
* import {prismaModelCreateOmitId, PrismaKeyedModelCreate} from '@augment-vir/common';
|
|
41
41
|
*
|
|
42
42
|
* export const mockUsers = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePrismaClient } from './base-prisma-types.js';
|
|
1
|
+
import { type BasePrismaClient } from './base-prisma-types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts all model names from a generated `PrismaClient`.
|
|
4
4
|
*
|
|
@@ -7,8 +7,8 @@ import { BasePrismaClient } from './base-prisma-types.js';
|
|
|
7
7
|
* @example
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
|
-
* import type
|
|
11
|
-
* import type
|
|
10
|
+
* import {type PrismaClient} from '@prisma/client';
|
|
11
|
+
* import {type PrismaModelName} from '@augment-vir/common';
|
|
12
12
|
*
|
|
13
13
|
* function doThing(modelName: PrismaModelName<PrismaClient>) {}
|
|
14
14
|
* ```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyObject } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Awaits all Promise properties inside of the given object and wraps them all in a single promise.
|
|
4
4
|
* This is akin to `Promise.all` but for an object instead of an array.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeferredPromise, type MaybePromise } from '@augment-vir/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type RequireExactlyOne } from 'type-fest';
|
|
3
3
|
import { ListenTarget } from 'typed-event-target';
|
|
4
4
|
/**
|
|
5
5
|
* An individual item in a {@link PromiseQueue} instance.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that produces deterministic, pseudo random numbers based on a given seed. This uses the
|
|
3
|
+
* Alea v0.9 algorithm from Johannes Baagøe.
|
|
4
|
+
*
|
|
5
|
+
* @category Random : Util
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export type SeededRandomState = [number, number, number, number];
|
|
10
|
+
/**
|
|
11
|
+
* A class that produces deterministic, pseudo random numbers based on a given seed. This uses the
|
|
12
|
+
* Alea v0.9 algorithm from Johannes Baagøe.
|
|
13
|
+
*
|
|
14
|
+
* @category Random
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {SeededRandom} from '@augment-vir/common';
|
|
20
|
+
*
|
|
21
|
+
* const random = SeededRandom.fromSeed('hello there');
|
|
22
|
+
* console.info(random.next()); // this value will always be the same
|
|
23
|
+
*
|
|
24
|
+
* const random2 = SeededRandom.fromState(random.exportState());
|
|
25
|
+
* console.info(random.next(), random2.next()); // both of these values will always be identical
|
|
26
|
+
*
|
|
27
|
+
* const random3 = random2.clone();
|
|
28
|
+
* console.info(random.next(), random2.next(), random3.next()); // all of these values will always be identical
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
32
|
+
*/
|
|
33
|
+
export declare class SeededRandom {
|
|
34
|
+
private readonly alea;
|
|
35
|
+
/** Generate a new {@link SeededRandom} instance from a seed. */
|
|
36
|
+
static fromSeed(seed: string | number): SeededRandom;
|
|
37
|
+
/** Generate a new {@link SeededRandom} instance from a specific state. */
|
|
38
|
+
static fromState(state: SeededRandomState): SeededRandom;
|
|
39
|
+
/**
|
|
40
|
+
* Exports the current state of the seeded random number generator so it can be cloned to
|
|
41
|
+
* another instance. Use {@link SeededRandom.fromState} to consume this state.
|
|
42
|
+
*/
|
|
43
|
+
exportState(): SeededRandomState;
|
|
44
|
+
/**
|
|
45
|
+
* This constructor is private. Use {@link SeededRandom.fromSeed} or
|
|
46
|
+
* {@link SeededRandom.fromState} instead.
|
|
47
|
+
*/
|
|
48
|
+
private constructor();
|
|
49
|
+
/** Generates the next deterministic pseudo random number. */
|
|
50
|
+
next(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Create a {@link SeededRandom} copy with the same state as this one. This is the same as
|
|
53
|
+
* calling {@link SeededRandom.exportState} and passing it directly into
|
|
54
|
+
* {@link SeededRandom.fromState}.
|
|
55
|
+
*/
|
|
56
|
+
clone(): SeededRandom;
|
|
57
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that produces deterministic, pseudo random numbers based on a given seed. This uses the
|
|
3
|
+
* Alea v0.9 algorithm from Johannes Baagøe.
|
|
4
|
+
*
|
|
5
|
+
* @category Random
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {SeededRandom} from '@augment-vir/common';
|
|
11
|
+
*
|
|
12
|
+
* const random = SeededRandom.fromSeed('hello there');
|
|
13
|
+
* console.info(random.next()); // this value will always be the same
|
|
14
|
+
*
|
|
15
|
+
* const random2 = SeededRandom.fromState(random.exportState());
|
|
16
|
+
* console.info(random.next(), random2.next()); // both of these values will always be identical
|
|
17
|
+
*
|
|
18
|
+
* const random3 = random2.clone();
|
|
19
|
+
* console.info(random.next(), random2.next(), random3.next()); // all of these values will always be identical
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
23
|
+
*/
|
|
24
|
+
export class SeededRandom {
|
|
25
|
+
alea;
|
|
26
|
+
/** Generate a new {@link SeededRandom} instance from a seed. */
|
|
27
|
+
static fromSeed(seed) {
|
|
28
|
+
return new SeededRandom(new AleaRandom(seed));
|
|
29
|
+
}
|
|
30
|
+
/** Generate a new {@link SeededRandom} instance from a specific state. */
|
|
31
|
+
static fromState(state) {
|
|
32
|
+
const alea = new AleaRandom('');
|
|
33
|
+
alea.importState(state);
|
|
34
|
+
return new SeededRandom(alea);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Exports the current state of the seeded random number generator so it can be cloned to
|
|
38
|
+
* another instance. Use {@link SeededRandom.fromState} to consume this state.
|
|
39
|
+
*/
|
|
40
|
+
exportState() {
|
|
41
|
+
return this.alea.exportState();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This constructor is private. Use {@link SeededRandom.fromSeed} or
|
|
45
|
+
* {@link SeededRandom.fromState} instead.
|
|
46
|
+
*/
|
|
47
|
+
constructor(alea) {
|
|
48
|
+
this.alea = alea;
|
|
49
|
+
}
|
|
50
|
+
/** Generates the next deterministic pseudo random number. */
|
|
51
|
+
next() {
|
|
52
|
+
return this.alea.next();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a {@link SeededRandom} copy with the same state as this one. This is the same as
|
|
56
|
+
* calling {@link SeededRandom.exportState} and passing it directly into
|
|
57
|
+
* {@link SeededRandom.fromState}.
|
|
58
|
+
*/
|
|
59
|
+
clone() {
|
|
60
|
+
return SeededRandom.fromState(this.exportState());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Alea algorithm has the following license from http://baagoe.com/en/RandomMusings/javascript. The
|
|
65
|
+
* code has been modified to fit into a class structure and simplify code flow and arguments. The
|
|
66
|
+
* algorithm itself has not changed.
|
|
67
|
+
*
|
|
68
|
+
* Copyright (C) 2010 by Johannes Baagøe (baagoe@baagoe.org)
|
|
69
|
+
*
|
|
70
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
71
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
72
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
73
|
+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
74
|
+
* furnished to do so, subject to the following conditions:
|
|
75
|
+
*
|
|
76
|
+
* The above copyright notice and this permission notice shall be included in all copies or
|
|
77
|
+
* substantial portions of the Software.
|
|
78
|
+
*
|
|
79
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
80
|
+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
81
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
82
|
+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
83
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
84
|
+
*/
|
|
85
|
+
/** Alea v0.9 */
|
|
86
|
+
class AleaRandom {
|
|
87
|
+
n = 0xef_c8_24_9d;
|
|
88
|
+
s = [
|
|
89
|
+
this.mash(' '),
|
|
90
|
+
this.mash(' '),
|
|
91
|
+
this.mash(' '),
|
|
92
|
+
1,
|
|
93
|
+
];
|
|
94
|
+
/** Mash v0.9. */
|
|
95
|
+
mash(input) {
|
|
96
|
+
const data = input.toString();
|
|
97
|
+
for (let i = 0; i < data.length; i++) {
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
99
|
+
this.n += data.codePointAt(i);
|
|
100
|
+
let h = 0.025_196_032_824_169_38 * this.n;
|
|
101
|
+
this.n = h >>> 0;
|
|
102
|
+
h -= this.n;
|
|
103
|
+
h *= this.n;
|
|
104
|
+
this.n = h >>> 0;
|
|
105
|
+
h -= this.n;
|
|
106
|
+
this.n += h * 0x1_00_00_00_00; // 2^32
|
|
107
|
+
}
|
|
108
|
+
return (this.n >>> 0) * 2.328_306_436_538_696_3e-10; // 2^-32
|
|
109
|
+
}
|
|
110
|
+
constructor(seed) {
|
|
111
|
+
this.s[0] -= this.mash(seed);
|
|
112
|
+
if (this.s[0] < 0) {
|
|
113
|
+
this.s[0] += 1;
|
|
114
|
+
}
|
|
115
|
+
this.s[1] -= this.mash(seed);
|
|
116
|
+
if (this.s[1] < 0) {
|
|
117
|
+
this.s[1] += 1;
|
|
118
|
+
}
|
|
119
|
+
this.s[2] -= this.mash(seed);
|
|
120
|
+
/* node:coverage ignore next 3: I don't care if we don't cover this */
|
|
121
|
+
if (this.s[2] < 0) {
|
|
122
|
+
this.s[2] += 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
next() {
|
|
126
|
+
const t = 2_091_639 * this.s[0] + this.s[3] * 2.328_306_436_538_696_3e-10; // 2^-32
|
|
127
|
+
this.s[0] = this.s[1];
|
|
128
|
+
this.s[1] = this.s[2];
|
|
129
|
+
// eslint-disable-next-line sonarjs/no-nested-assignment
|
|
130
|
+
return (this.s[2] = t - (this.s[3] = t | 0));
|
|
131
|
+
}
|
|
132
|
+
importState(state) {
|
|
133
|
+
this.s = state;
|
|
134
|
+
}
|
|
135
|
+
exportState() {
|
|
136
|
+
return [
|
|
137
|
+
...this.s,
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { ExcludeEmpty } from '../object/empty.js';
|
|
3
|
-
import { KeyCount } from '../object/key-count.js';
|
|
4
|
-
import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type/type-recursion.js';
|
|
5
|
-
import { GenericSelectionSet, SelectFrom, SelectionSet } from './selection-set.js';
|
|
1
|
+
import { type AnyObject, type Values } from '@augment-vir/core';
|
|
2
|
+
import { type ExcludeEmpty } from '../object/empty.js';
|
|
3
|
+
import { type KeyCount } from '../object/key-count.js';
|
|
4
|
+
import { type TsRecurse, type TsRecursionStart, type TsRecursionTracker, type TsTooMuchRecursion } from '../type/type-recursion.js';
|
|
5
|
+
import { type GenericSelectionSet, type SelectFrom, type SelectionSet } from './selection-set.js';
|
|
6
6
|
/**
|
|
7
7
|
* The same as {@link selectFrom} except that the final output is collapsed until the first nested
|
|
8
8
|
* value that has more than 1 key or that is not an object.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { SelectFrom, SelectionSet } from './selection-set.js';
|
|
1
|
+
import { type AnyObject } from '@augment-vir/core';
|
|
2
|
+
import { type SelectFrom, type SelectionSet } from './selection-set.js';
|
|
3
3
|
/**
|
|
4
4
|
* Determine if the given input should be preserved in the selection output, meaning it won't be
|
|
5
5
|
* recursed into.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PartialWithUndefined } from '@augment-vir/core';
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Collapse all consecutive white space into just one space and trim surrounding whitespace.
|
|
4
4
|
* Optionally, collapsed newlines can be preserved.
|
|
@@ -160,11 +160,11 @@ type TsRecursionArray = [
|
|
|
160
160
|
* @example
|
|
161
161
|
*
|
|
162
162
|
* ```ts
|
|
163
|
-
* import
|
|
164
|
-
* TsRecursionTracker,
|
|
165
|
-
* TsRecursionStart,
|
|
166
|
-
* TsRecurse,
|
|
167
|
-
* TsTooMuchRecursion,
|
|
163
|
+
* import {
|
|
164
|
+
* type TsRecursionTracker,
|
|
165
|
+
* type TsRecursionStart,
|
|
166
|
+
* type TsRecurse,
|
|
167
|
+
* type TsTooMuchRecursion,
|
|
168
168
|
* } from '@augment-vir/common';
|
|
169
169
|
*
|
|
170
170
|
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
@@ -185,11 +185,11 @@ export type TsRecursionTracker = keyof TsRecursionArray;
|
|
|
185
185
|
* @example
|
|
186
186
|
*
|
|
187
187
|
* ```ts
|
|
188
|
-
* import
|
|
189
|
-
* TsRecursionTracker,
|
|
190
|
-
* TsRecursionStart,
|
|
191
|
-
* TsRecurse,
|
|
192
|
-
* TsTooMuchRecursion,
|
|
188
|
+
* import {
|
|
189
|
+
* type TsRecursionTracker,
|
|
190
|
+
* type TsRecursionStart,
|
|
191
|
+
* type TsRecurse,
|
|
192
|
+
* type TsTooMuchRecursion,
|
|
193
193
|
* } from '@augment-vir/common';
|
|
194
194
|
*
|
|
195
195
|
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
@@ -210,11 +210,11 @@ export type TsTooMuchRecursion = 91;
|
|
|
210
210
|
* @example
|
|
211
211
|
*
|
|
212
212
|
* ```ts
|
|
213
|
-
* import
|
|
214
|
-
* TsRecursionTracker,
|
|
215
|
-
* TsRecursionStart,
|
|
216
|
-
* TsRecurse,
|
|
217
|
-
* TsTooMuchRecursion,
|
|
213
|
+
* import {
|
|
214
|
+
* type TsRecursionTracker,
|
|
215
|
+
* type TsRecursionStart,
|
|
216
|
+
* type TsRecurse,
|
|
217
|
+
* type TsTooMuchRecursion,
|
|
218
218
|
* } from '@augment-vir/common';
|
|
219
219
|
*
|
|
220
220
|
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
|
@@ -234,11 +234,11 @@ export type TsRecursionStart = 0;
|
|
|
234
234
|
* @example
|
|
235
235
|
*
|
|
236
236
|
* ```ts
|
|
237
|
-
* import
|
|
238
|
-
* TsRecursionTracker,
|
|
239
|
-
* TsRecursionStart,
|
|
240
|
-
* TsRecurse,
|
|
241
|
-
* TsTooMuchRecursion,
|
|
237
|
+
* import {
|
|
238
|
+
* type TsRecursionTracker,
|
|
239
|
+
* type TsRecursionStart,
|
|
240
|
+
* type TsRecurse,
|
|
241
|
+
* type TsTooMuchRecursion,
|
|
242
242
|
* } from '@augment-vir/common';
|
|
243
243
|
*
|
|
244
244
|
* export type SomeType<Depth extends TsRecursionTracker = TsRecursionStart> =
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export * from './augments/promise/timed-promise.js';
|
|
|
61
61
|
export * from './augments/random/random-boolean.js';
|
|
62
62
|
export * from './augments/random/random-integer.js';
|
|
63
63
|
export * from './augments/random/random-string.js';
|
|
64
|
+
export * from './augments/random/seeded-random.js';
|
|
64
65
|
export * from './augments/regexp/match.js';
|
|
65
66
|
export * from './augments/regexp/regexp-flags.js';
|
|
66
67
|
export * from './augments/regexp/regexp-string.js';
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ export * from './augments/promise/timed-promise.js';
|
|
|
61
61
|
export * from './augments/random/random-boolean.js';
|
|
62
62
|
export * from './augments/random/random-integer.js';
|
|
63
63
|
export * from './augments/random/random-string.js';
|
|
64
|
+
export * from './augments/random/seeded-random.js';
|
|
64
65
|
export * from './augments/regexp/match.js';
|
|
65
66
|
export * from './augments/regexp/regexp-flags.js';
|
|
66
67
|
export * from './augments/regexp/regexp-string.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.15.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.15.0",
|
|
44
|
+
"@augment-vir/core": "^31.15.0",
|
|
45
45
|
"@date-vir/duration": "^7.3.1",
|
|
46
46
|
"ansi-styles": "^6.2.1",
|
|
47
47
|
"json5": "^2.2.3",
|