assertron 11.5.2 → 11.5.4
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/README.md +7 -7
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/defineProperty.js +12 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/toPrimitive.js +14 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/toPropertyKey.js +9 -0
- package/cjs/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/typeof.js +16 -0
- package/cjs/_virtual/_rolldown/runtime.js +23 -0
- package/cjs/assert-order/AssertOrder.d.ts +42 -39
- package/cjs/assert-order/AssertOrder.d.ts.map +1 -1
- package/cjs/assert-order/AssertOrder.js +118 -146
- package/cjs/assert-order/AssertOrder.js.map +1 -1
- package/cjs/assert-order/InvalidOrder.d.ts +10 -7
- package/cjs/assert-order/InvalidOrder.d.ts.map +1 -1
- package/cjs/assert-order/InvalidOrder.js +24 -43
- package/cjs/assert-order/InvalidOrder.js.map +1 -1
- package/cjs/assert-order/StateMachine.js +101 -156
- package/cjs/assert-order/StateMachine.js.map +1 -1
- package/cjs/assert-order/index.d.ts +4 -4
- package/cjs/assert-order/types.d.ts +9 -6
- package/cjs/assert-order/types.d.ts.map +1 -1
- package/cjs/assertron/assertron.d.ts +23 -20
- package/cjs/assertron/assertron.d.ts.map +1 -1
- package/cjs/assertron/assertron.js +36 -39
- package/cjs/assertron/assertron.js.map +1 -1
- package/cjs/assertron/falsy.js +5 -6
- package/cjs/assertron/falsy.js.map +1 -1
- package/cjs/assertron/index.d.ts +3 -3
- package/cjs/assertron/isInstanceof.js +6 -7
- package/cjs/assertron/isInstanceof.js.map +1 -1
- package/cjs/assertron/pathEqual.js +7 -8
- package/cjs/assertron/pathEqual.js.map +1 -1
- package/cjs/assertron/rejects.js +8 -8
- package/cjs/assertron/rejects.js.map +1 -1
- package/cjs/assertron/repeat.js +23 -31
- package/cjs/assertron/repeat.js.map +1 -1
- package/cjs/assertron/resolves.js +8 -8
- package/cjs/assertron/resolves.js.map +1 -1
- package/cjs/assertron/satisfies.d.ts +5 -10
- package/cjs/assertron/satisfies.d.ts.map +1 -1
- package/cjs/assertron/satisfies.js +12 -14
- package/cjs/assertron/satisfies.js.map +1 -1
- package/cjs/assertron/throws.js +48 -55
- package/cjs/assertron/throws.js.map +1 -1
- package/cjs/assertron/truthy.js +5 -6
- package/cjs/assertron/truthy.js.map +1 -1
- package/cjs/errors.d.ts +13 -10
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js +19 -29
- package/cjs/errors.js.map +1 -1
- package/cjs/index.d.ts +10 -8
- package/cjs/index.js +98 -37
- package/cjs/index.js.map +1 -1
- package/cjs/package.json +3 -1
- package/cjs/types.d.ts +5 -2
- package/cjs/types.d.ts.map +1 -1
- package/cjs/utils/index.js +18 -25
- package/cjs/utils/index.js.map +1 -1
- package/cjs/utils/isErrorConstructor.js +4 -4
- package/cjs/utils/isErrorConstructor.js.map +1 -1
- package/cjs/utils/notEqualMessage.js +4 -4
- package/cjs/utils/notEqualMessage.js.map +1 -1
- package/cjs/utils/notSatisfiedMessage.js +14 -23
- package/cjs/utils/notSatisfiedMessage.js.map +1 -1
- package/cjs/utils/notThrownMessage.js +5 -5
- package/cjs/utils/notThrownMessage.js.map +1 -1
- package/cjs/utils/promiseMessages.js +7 -13
- package/cjs/utils/promiseMessages.js.map +1 -1
- package/cjs/utils/unexpectedErrorMessage.js +6 -6
- package/cjs/utils/unexpectedErrorMessage.js.map +1 -1
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/defineProperty.js +12 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/toPrimitive.js +14 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/toPropertyKey.js +9 -0
- package/esm/_virtual/_@oxc-project_runtime@0.147.0/helpers/esm/typeof.js +11 -0
- package/esm/assert-order/AssertOrder.d.ts +42 -39
- package/esm/assert-order/AssertOrder.d.ts.map +1 -1
- package/esm/assert-order/AssertOrder.js +119 -143
- package/esm/assert-order/AssertOrder.js.map +1 -1
- package/esm/assert-order/InvalidOrder.d.ts +10 -7
- package/esm/assert-order/InvalidOrder.d.ts.map +1 -1
- package/esm/assert-order/InvalidOrder.js +24 -39
- package/esm/assert-order/InvalidOrder.js.map +1 -1
- package/esm/assert-order/StateMachine.js +99 -129
- package/esm/assert-order/StateMachine.js.map +1 -1
- package/esm/assert-order/index.d.ts +4 -4
- package/esm/assert-order/types.d.ts +9 -6
- package/esm/assert-order/types.d.ts.map +1 -1
- package/esm/assertron/assertron.d.ts +23 -20
- package/esm/assertron/assertron.d.ts.map +1 -1
- package/esm/assertron/assertron.js +36 -36
- package/esm/assertron/assertron.js.map +1 -1
- package/esm/assertron/falsy.js +7 -4
- package/esm/assertron/falsy.js.map +1 -1
- package/esm/assertron/index.d.ts +3 -3
- package/esm/assertron/isInstanceof.js +8 -5
- package/esm/assertron/isInstanceof.js.map +1 -1
- package/esm/assertron/pathEqual.js +9 -6
- package/esm/assertron/pathEqual.js.map +1 -1
- package/esm/assertron/rejects.js +10 -6
- package/esm/assertron/rejects.js.map +1 -1
- package/esm/assertron/repeat.js +22 -25
- package/esm/assertron/repeat.js.map +1 -1
- package/esm/assertron/resolves.js +10 -6
- package/esm/assertron/resolves.js.map +1 -1
- package/esm/assertron/satisfies.d.ts +5 -10
- package/esm/assertron/satisfies.d.ts.map +1 -1
- package/esm/assertron/satisfies.js +14 -12
- package/esm/assertron/satisfies.js.map +1 -1
- package/esm/assertron/throws.js +47 -49
- package/esm/assertron/throws.js.map +1 -1
- package/esm/assertron/truthy.js +7 -4
- package/esm/assertron/truthy.js.map +1 -1
- package/esm/errors.d.ts +13 -10
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +20 -26
- package/esm/errors.js.map +1 -1
- package/esm/index.d.ts +10 -8
- package/esm/index.js +10 -7
- package/esm/index.js.map +1 -1
- package/esm/types.d.ts +5 -2
- package/esm/types.d.ts.map +1 -1
- package/esm/utils/index.js +13 -9
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/isErrorConstructor.js +6 -2
- package/esm/utils/isErrorConstructor.js.map +1 -1
- package/esm/utils/notEqualMessage.js +6 -2
- package/esm/utils/notEqualMessage.js.map +1 -1
- package/esm/utils/notSatisfiedMessage.js +15 -20
- package/esm/utils/notSatisfiedMessage.js.map +1 -1
- package/esm/utils/notThrownMessage.js +7 -3
- package/esm/utils/notThrownMessage.js.map +1 -1
- package/esm/utils/promiseMessages.js +9 -11
- package/esm/utils/promiseMessages.js.map +1 -1
- package/esm/utils/unexpectedErrorMessage.js +8 -4
- package/esm/utils/unexpectedErrorMessage.js.map +1 -1
- package/package.json +43 -68
- package/ts/assert-order/AssertOrder.ts +8 -6
- package/ts/assert-order/InvalidOrder.ts +4 -6
- package/ts/assert-order/StateMachine.ts +11 -7
- package/ts/assertron/assertron.ts +9 -19
- package/ts/assertron/falsy.ts +1 -2
- package/ts/assertron/isInstanceof.ts +1 -4
- package/ts/assertron/pathEqual.ts +1 -2
- package/ts/assertron/rejects.ts +2 -2
- package/ts/assertron/repeat.ts +5 -6
- package/ts/assertron/resolves.ts +3 -3
- package/ts/assertron/satisfies.ts +2 -4
- package/ts/assertron/throws.ts +14 -20
- package/ts/assertron/truthy.ts +1 -2
- package/ts/errors.ts +5 -1
- package/ts/index.ts +2 -2
- package/ts/utils/index.ts +1 -1
- package/ts/utils/notSatisfiedMessage.ts +2 -2
- package/ts/utils/promiseMessages.ts +5 -5
- package/cjs/assert-order/StateMachine.d.ts +0 -22
- package/cjs/assert-order/StateMachine.d.ts.map +0 -1
- package/cjs/assert-order/index.d.ts.map +0 -1
- package/cjs/assert-order/index.js +0 -20
- package/cjs/assert-order/index.js.map +0 -1
- package/cjs/assert-order/types.js +0 -3
- package/cjs/assert-order/types.js.map +0 -1
- package/cjs/assertron/falsy.d.ts +0 -2
- package/cjs/assertron/falsy.d.ts.map +0 -1
- package/cjs/assertron/index.d.ts.map +0 -1
- package/cjs/assertron/index.js +0 -18
- package/cjs/assertron/index.js.map +0 -1
- package/cjs/assertron/isInstanceof.d.ts +0 -3
- package/cjs/assertron/isInstanceof.d.ts.map +0 -1
- package/cjs/assertron/pathEqual.d.ts +0 -2
- package/cjs/assertron/pathEqual.d.ts.map +0 -1
- package/cjs/assertron/rejects.d.ts +0 -2
- package/cjs/assertron/rejects.d.ts.map +0 -1
- package/cjs/assertron/repeat.d.ts +0 -6
- package/cjs/assertron/repeat.d.ts.map +0 -1
- package/cjs/assertron/resolves.d.ts +0 -2
- package/cjs/assertron/resolves.d.ts.map +0 -1
- package/cjs/assertron/throws.d.ts +0 -6
- package/cjs/assertron/throws.d.ts.map +0 -1
- package/cjs/assertron/truthy.d.ts +0 -2
- package/cjs/assertron/truthy.d.ts.map +0 -1
- package/cjs/index.d.ts.map +0 -1
- package/cjs/types.js +0 -3
- package/cjs/types.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -8
- package/cjs/utils/index.d.ts.map +0 -1
- package/cjs/utils/isErrorConstructor.d.ts +0 -3
- package/cjs/utils/isErrorConstructor.d.ts.map +0 -1
- package/cjs/utils/notEqualMessage.d.ts +0 -2
- package/cjs/utils/notEqualMessage.d.ts.map +0 -1
- package/cjs/utils/notSatisfiedMessage.d.ts +0 -3
- package/cjs/utils/notSatisfiedMessage.d.ts.map +0 -1
- package/cjs/utils/notThrownMessage.d.ts +0 -2
- package/cjs/utils/notThrownMessage.d.ts.map +0 -1
- package/cjs/utils/promiseMessages.d.ts +0 -3
- package/cjs/utils/promiseMessages.d.ts.map +0 -1
- package/cjs/utils/unexpectedErrorMessage.d.ts +0 -3
- package/cjs/utils/unexpectedErrorMessage.d.ts.map +0 -1
- package/esm/assert-order/StateMachine.d.ts +0 -22
- package/esm/assert-order/StateMachine.d.ts.map +0 -1
- package/esm/assert-order/index.d.ts.map +0 -1
- package/esm/assert-order/index.js +0 -4
- package/esm/assert-order/index.js.map +0 -1
- package/esm/assert-order/types.js +0 -2
- package/esm/assert-order/types.js.map +0 -1
- package/esm/assertron/falsy.d.ts +0 -2
- package/esm/assertron/falsy.d.ts.map +0 -1
- package/esm/assertron/index.d.ts.map +0 -1
- package/esm/assertron/index.js +0 -2
- package/esm/assertron/index.js.map +0 -1
- package/esm/assertron/isInstanceof.d.ts +0 -3
- package/esm/assertron/isInstanceof.d.ts.map +0 -1
- package/esm/assertron/pathEqual.d.ts +0 -2
- package/esm/assertron/pathEqual.d.ts.map +0 -1
- package/esm/assertron/rejects.d.ts +0 -2
- package/esm/assertron/rejects.d.ts.map +0 -1
- package/esm/assertron/repeat.d.ts +0 -6
- package/esm/assertron/repeat.d.ts.map +0 -1
- package/esm/assertron/resolves.d.ts +0 -2
- package/esm/assertron/resolves.d.ts.map +0 -1
- package/esm/assertron/throws.d.ts +0 -6
- package/esm/assertron/throws.d.ts.map +0 -1
- package/esm/assertron/truthy.d.ts +0 -2
- package/esm/assertron/truthy.d.ts.map +0 -1
- package/esm/index.d.ts.map +0 -1
- package/esm/types.js +0 -2
- package/esm/types.js.map +0 -1
- package/esm/utils/index.d.ts +0 -8
- package/esm/utils/index.d.ts.map +0 -1
- package/esm/utils/isErrorConstructor.d.ts +0 -3
- package/esm/utils/isErrorConstructor.d.ts.map +0 -1
- package/esm/utils/notEqualMessage.d.ts +0 -2
- package/esm/utils/notEqualMessage.d.ts.map +0 -1
- package/esm/utils/notSatisfiedMessage.d.ts +0 -3
- package/esm/utils/notSatisfiedMessage.d.ts.map +0 -1
- package/esm/utils/notThrownMessage.d.ts +0 -2
- package/esm/utils/notThrownMessage.d.ts.map +0 -1
- package/esm/utils/promiseMessages.d.ts +0 -3
- package/esm/utils/promiseMessages.d.ts.map +0 -1
- package/esm/utils/unexpectedErrorMessage.d.ts +0 -3
- package/esm/utils/unexpectedErrorMessage.d.ts.map +0 -1
- package/ts/assert-order/internalInterfaces.ts +0 -5
- package/ts/testUtils.ts +0 -81
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateMachine.js","
|
|
1
|
+
{"version":3,"file":"StateMachine.js","names":[],"sources":["../../ts/assert-order/StateMachine.ts"],"sourcesContent":["// Deliberately the bare specifier, not `node:perf_hooks`: package.json's `browser`\n// field maps `perf_hooks` to `false` for bundlers, and that mapping does not apply to\n// the `node:` prefixed form.\n// biome-ignore lint/style/useNodejsImportProtocol: see above\nimport * as perf from 'perf_hooks'\nimport type { State } from './types.js'\n\nlet timeTracker: { start(): void; taken(): number }\n\nif (typeof globalThis.process?.hrtime === 'function') {\n\tlet tick: [number, number]\n\ttimeTracker = {\n\t\tstart() {\n\t\t\ttick = globalThis.process.hrtime()\n\t\t},\n\t\ttaken() {\n\t\t\tconst [second, nanoSecond] = globalThis.process.hrtime(tick)\n\t\t\treturn second * 1000 + nanoSecond / 1e6\n\t\t},\n\t}\n} else if (perf.performance && typeof perf.performance.now === 'function') {\n\tconst now = perf.performance.now\n\tlet tick: number\n\ttimeTracker = {\n\t\tstart() {\n\t\t\ttick = now()\n\t\t},\n\t\ttaken() {\n\t\t\treturn now() - tick\n\t\t},\n\t}\n} else {\n\tlet tick: number\n\ttimeTracker = {\n\t\tstart() {\n\t\t\ttick = Date.now()\n\t\t},\n\t\ttaken() {\n\t\t\treturn Date.now() - tick\n\t\t},\n\t}\n}\n\nexport class StateMachine {\n\tlisteners: Record<number, Array<() => void>> = {}\n\tstep = 1\n\tmaxStep?: number\n\n\tsubStep = 0\n\tminSubStep?: number\n\tmaxSubStep?: number\n\tconstructor(maxStep?: number) {\n\t\tthis.maxStep = maxStep\n\t\ttimeTracker.start()\n\t}\n\tjump(step: number) {\n\t\tthis.step = step\n\t\tthis.subStep = 0\n\t\treturn this.step\n\t}\n\tmove() {\n\t\tconst listeners = this.listeners[this.step]\n\t\tthis.step = this.step + 1\n\t\tthis.subStep = 0\n\t\tif (listeners) {\n\t\t\tfor (const l of listeners) l()\n\t\t}\n\t\treturn this.step\n\t}\n\tmoveSubStep() {\n\t\tconst subStep = ++this.subStep\n\t\tif (this.maxSubStep === this.subStep) this.move()\n\t\treturn subStep\n\t}\n\tget(): State {\n\t\tconst { step, subStep, maxStep, minSubStep, maxSubStep } = this\n\t\treturn {\n\t\t\tstep,\n\t\t\tmaxStep,\n\t\t\tsubStep,\n\t\t\tminSubStep,\n\t\t\tmaxSubStep,\n\t\t}\n\t}\n\ton(step: number, listener: () => void) {\n\t\tthis.listeners[step] = [listener]\n\t}\n\tisNotValid(step: number) {\n\t\treturn step !== this.step || (this.maxStep !== undefined && this.maxStep < step)\n\t}\n\tisValid(step: number) {\n\t\treturn step === this.step\n\t}\n\tisMaxStepDefined() {\n\t\treturn this.maxStep !== undefined\n\t}\n\tstopAccepting() {\n\t\tthis.maxStep = this.step - 1\n\t}\n\tisAccepting() {\n\t\t// istanbul ignore next\n\t\treturn this.maxStep ? this.maxStep >= this.step : true\n\t}\n\tgetTimeTaken() {\n\t\treturn timeTracker.taken()\n\t}\n}\n"],"mappings":";;;AAOA,IAAI;AAEJ,IAAI,OAAO,WAAW,SAAS,WAAW,YAAY;CACrD,IAAI;CACJ,cAAc;EACb,QAAQ;GACP,OAAO,WAAW,QAAQ,OAAO;EAClC;EACA,QAAQ;GACP,MAAM,CAAC,QAAQ,cAAc,WAAW,QAAQ,OAAO,IAAI;GAC3D,OAAO,SAAS,MAAO,aAAa;EACrC;CACD;AACD,OAAO,IAAI,KAAK,eAAe,OAAO,KAAK,YAAY,QAAQ,YAAY;CAC1E,MAAM,MAAM,KAAK,YAAY;CAC7B,IAAI;CACJ,cAAc;EACb,QAAQ;GACP,OAAO,IAAI;EACZ;EACA,QAAQ;GACP,OAAO,IAAI,IAAI;EAChB;CACD;AACD,OAAO;CACN,IAAI;CACJ,cAAc;EACb,QAAQ;GACP,OAAO,KAAK,IAAI;EACjB;EACA,QAAQ;GACP,OAAO,KAAK,IAAI,IAAI;EACrB;CACD;AACD;AAEA,IAAa,eAAb,MAA0B;CAQzB,YAAY,SAAkB;EAP9B,gBAAA,MAAA,aAA+C,CAAC,CAAA;EAChD,gBAAA,MAAA,QAAO,CAAA;EACP,gBAAA,MAAA,WAAA,KAAA,CAAA;EAEA,gBAAA,MAAA,WAAU,CAAA;EACV,gBAAA,MAAA,cAAA,KAAA,CAAA;EACA,gBAAA,MAAA,cAAA,KAAA,CAAA;EAEC,KAAK,UAAU;EACf,YAAY,MAAM;CACnB;CACA,KAAK,MAAc;EAClB,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,OAAO,KAAK;CACb;CACA,OAAO;EACN,MAAM,YAAY,KAAK,UAAU,KAAK;EACtC,KAAK,OAAO,KAAK,OAAO;EACxB,KAAK,UAAU;EACf,IAAI,WACH,KAAK,MAAM,KAAK,WAAW,EAAE;EAE9B,OAAO,KAAK;CACb;CACA,cAAc;EACb,MAAM,UAAU,EAAE,KAAK;EACvB,IAAI,KAAK,eAAe,KAAK,SAAS,KAAK,KAAK;EAChD,OAAO;CACR;CACA,MAAa;EACZ,MAAM,EAAE,MAAM,SAAS,SAAS,YAAY,eAAe;EAC3D,OAAO;GACN;GACA;GACA;GACA;GACA;EACD;CACD;CACA,GAAG,MAAc,UAAsB;EACtC,KAAK,UAAU,QAAQ,CAAC,QAAQ;CACjC;CACA,WAAW,MAAc;EACxB,OAAO,SAAS,KAAK,QAAS,KAAK,YAAY,KAAA,KAAa,KAAK,UAAU;CAC5E;CACA,QAAQ,MAAc;EACrB,OAAO,SAAS,KAAK;CACtB;CACA,mBAAmB;EAClB,OAAO,KAAK,YAAY,KAAA;CACzB;CACA,gBAAgB;EACf,KAAK,UAAU,KAAK,OAAO;CAC5B;CACA,cAAc;;EAEb,OAAO,KAAK,UAAU,KAAK,WAAW,KAAK,OAAO;CACnD;CACA,eAAe;EACd,OAAO,YAAY,MAAM;CAC1B;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AssertOrder } from "./AssertOrder.js";
|
|
2
|
+
import { State } from "./types.js";
|
|
3
|
+
import { InvalidOrder } from "./InvalidOrder.js";
|
|
4
|
+
export { AssertOrder, InvalidOrder, State };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region ts/assert-order/types.d.ts
|
|
2
|
+
interface State {
|
|
3
|
+
step: number;
|
|
4
|
+
maxStep?: number;
|
|
5
|
+
subStep: number;
|
|
6
|
+
minSubStep?: number;
|
|
7
|
+
maxSubStep?: number;
|
|
7
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { State };
|
|
8
11
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../ts/assert-order/types.ts"],"mappings":";UAAiB;EAChB;EACA;EACA;EACA;EACA"}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { ErrorConstructor, ErrorValidator } from "../types.js";
|
|
2
|
+
import { SatisfyExpectation } from "./satisfies.js";
|
|
3
|
+
import { AnyConstructor } from "type-plus";
|
|
4
|
+
//#region ts/assertron/assertron.d.ts
|
|
5
|
+
type Assertron = {
|
|
6
|
+
false(value: unknown, message?: string | undefined): asserts value is false;
|
|
7
|
+
falsy(value: any, message?: string | undefined): asserts value is false | 0 | '' | null | undefined;
|
|
8
|
+
isInstanceof<T extends AnyConstructor>(value: unknown, type: T): asserts value is InstanceType<T>;
|
|
9
|
+
pathEqual(actual: string, expected: string): void;
|
|
10
|
+
rejects<R = any>(promise: Promise<any>): Promise<R>;
|
|
11
|
+
repeat<R>(fn: () => R | (() => Promise<R>), times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R;
|
|
12
|
+
resolves(promise: Promise<any>): Promise<void>;
|
|
13
|
+
satisfies<Actual, Expected extends Actual>(actual: Actual, expected: SatisfyExpectation<Expected>): void;
|
|
14
|
+
throws<E extends Error>(value: PromiseLike<any>, error?: ErrorValidator | ErrorConstructor<E>): Promise<E>;
|
|
15
|
+
throws<E extends Error>(value: (...args: any[]) => never, error?: ErrorValidator | ErrorConstructor<E>): E;
|
|
16
|
+
throws<E extends Error, R = any>(value: (...args: any[]) => R, error?: ErrorValidator | ErrorConstructor<E>): R extends Promise<any> ? Promise<E> : E;
|
|
17
|
+
throws<T, R = any>(value: (...args: any[]) => R, validator?: ErrorValidator): R extends Promise<any> ? Promise<T> : T;
|
|
18
|
+
true(value: unknown, message?: string | undefined): asserts value is true;
|
|
19
|
+
truthy(value: unknown, message?: string | undefined): void;
|
|
20
|
+
uuid(value: unknown): void;
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
+
declare const assertron: Assertron;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Assertron, assertron };
|
|
22
25
|
//# sourceMappingURL=assertron.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertron.d.ts","
|
|
1
|
+
{"version":3,"file":"assertron.d.ts","names":[],"sources":["../../ts/assertron/assertron.ts"],"mappings":";;;;KAcY;EACX,MAAM,gBAAgB,uCAAuC;EAC7D,MAAM,YAAY,uCAAuC;EACzD,aAAa,UAAU,gBAAgB,gBAAgB,MAAM,YAAY,SAAS,aAAa;EAC/F,UAAU,gBAAgB;EAC1B,QAAQ,SAAS,SAAS,eAAe,QAAQ;EACjD,OAAO,GAAG,UAAU,WAAW,QAAQ,KAAK,gBAAgB,kBAAkB,YAAY,QAAQ,KAAK,QAAQ,KAAK;EACpH,SAAS,SAAS,eAAe;EACjC,UAAU,QAAQ,iBAAiB,QAAQ,QAAQ,QAAQ,UAAU,mBAAmB;EACxF,OAAO,UAAU,OAAO,OAAO,kBAAkB,QAAQ,iBAAiB,iBAAiB,KAAK,QAAQ;EACxG,OAAO,UAAU,OAAO,WAAW,uBAAuB,QAAQ,iBAAiB,iBAAiB,KAAK;EACzG,OAAO,UAAU,OAAO,SACvB,WAAW,gBAAgB,GAC3B,QAAQ,iBAAiB,iBAAiB,KACxC,UAAU,eAAe,QAAQ,KAAK;EACzC,OAAO,GAAG,SAAS,WAAW,gBAAgB,GAAG,YAAY,iBAAiB,UAAU,eAAe,QAAQ,KAAK;EACpH,KAAK,gBAAgB,uCAAuC;EAC5D,OAAO,gBAAgB;EACvB,KAAK;;cAGO,WAAW"}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { falsy } from
|
|
4
|
-
import { isInstanceof } from
|
|
5
|
-
import { pathEqual } from
|
|
6
|
-
import { rejects } from
|
|
7
|
-
import { repeat } from
|
|
8
|
-
import { resolves } from
|
|
9
|
-
import { satisfies } from
|
|
10
|
-
import { throws } from
|
|
11
|
-
import { truthy } from
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return;
|
|
35
|
-
throw new AssertionError(`Expected ${value} to be a valid UUID`, { ssf: assertron.uuid });
|
|
36
|
-
}
|
|
1
|
+
import { notEqualMessage } from "../utils/notEqualMessage.js";
|
|
2
|
+
import { AssertionError } from "../errors.js";
|
|
3
|
+
import { falsy } from "./falsy.js";
|
|
4
|
+
import { isInstanceof } from "./isInstanceof.js";
|
|
5
|
+
import { pathEqual } from "./pathEqual.js";
|
|
6
|
+
import { rejects } from "./rejects.js";
|
|
7
|
+
import { repeat } from "./repeat.js";
|
|
8
|
+
import { resolves } from "./resolves.js";
|
|
9
|
+
import { satisfies } from "./satisfies.js";
|
|
10
|
+
import { throws } from "./throws.js";
|
|
11
|
+
import { truthy } from "./truthy.js";
|
|
12
|
+
//#region ts/assertron/assertron.ts
|
|
13
|
+
const assertron = {
|
|
14
|
+
false(value, message) {
|
|
15
|
+
if (value !== false) throw new AssertionError(message ?? notEqualMessage(value, false), { ssf: assertron.false });
|
|
16
|
+
},
|
|
17
|
+
falsy,
|
|
18
|
+
isInstanceof,
|
|
19
|
+
pathEqual,
|
|
20
|
+
rejects,
|
|
21
|
+
repeat,
|
|
22
|
+
resolves,
|
|
23
|
+
satisfies,
|
|
24
|
+
throws,
|
|
25
|
+
true(value, message) {
|
|
26
|
+
if (value !== true) throw new AssertionError(message ?? notEqualMessage(value, true), { ssf: assertron.true });
|
|
27
|
+
},
|
|
28
|
+
truthy,
|
|
29
|
+
uuid(value) {
|
|
30
|
+
if (typeof value !== "string") throw new AssertionError(`Expected ${value} to be a string`, { ssf: assertron.uuid });
|
|
31
|
+
if (/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/.test(value)) return;
|
|
32
|
+
throw new AssertionError(`Expected ${value} to be a valid UUID`, { ssf: assertron.uuid });
|
|
33
|
+
}
|
|
37
34
|
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { assertron };
|
|
37
|
+
|
|
38
38
|
//# sourceMappingURL=assertron.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertron.js","
|
|
1
|
+
{"version":3,"file":"assertron.js","names":[],"sources":["../../ts/assertron/assertron.ts"],"sourcesContent":["import type { AnyConstructor } from 'type-plus'\nimport { AssertionError } from '../errors.js'\nimport type { ErrorConstructor, ErrorValidator } from '../types.js'\nimport { notEqualMessage } from '../utils/index.js'\nimport { falsy } from './falsy.js'\nimport { isInstanceof } from './isInstanceof.js'\nimport { pathEqual } from './pathEqual.js'\nimport { rejects } from './rejects.js'\nimport { repeat } from './repeat.js'\nimport { resolves } from './resolves.js'\nimport { type SatisfyExpectation, satisfies } from './satisfies.js'\nimport { throws } from './throws.js'\nimport { truthy } from './truthy.js'\n\nexport type Assertron = {\n\tfalse(value: unknown, message?: string | undefined): asserts value is false\n\tfalsy(value: any, message?: string | undefined): asserts value is false | 0 | '' | null | undefined\n\tisInstanceof<T extends AnyConstructor>(value: unknown, type: T): asserts value is InstanceType<T>\n\tpathEqual(actual: string, expected: string): void\n\trejects<R = any>(promise: Promise<any>): Promise<R>\n\trepeat<R>(fn: () => R | (() => Promise<R>), times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R\n\tresolves(promise: Promise<any>): Promise<void>\n\tsatisfies<Actual, Expected extends Actual>(actual: Actual, expected: SatisfyExpectation<Expected>): void\n\tthrows<E extends Error>(value: PromiseLike<any>, error?: ErrorValidator | ErrorConstructor<E>): Promise<E>\n\tthrows<E extends Error>(value: (...args: any[]) => never, error?: ErrorValidator | ErrorConstructor<E>): E\n\tthrows<E extends Error, R = any>(\n\t\tvalue: (...args: any[]) => R,\n\t\terror?: ErrorValidator | ErrorConstructor<E>,\n\t): R extends Promise<any> ? Promise<E> : E\n\tthrows<T, R = any>(value: (...args: any[]) => R, validator?: ErrorValidator): R extends Promise<any> ? Promise<T> : T\n\ttrue(value: unknown, message?: string | undefined): asserts value is true\n\ttruthy(value: unknown, message?: string | undefined): void\n\tuuid(value: unknown): void\n}\n\nexport const assertron: Assertron = {\n\tfalse(value: unknown, message?: string): void {\n\t\tif (value !== false) throw new AssertionError(message ?? notEqualMessage(value, false), { ssf: assertron.false })\n\t},\n\tfalsy,\n\tisInstanceof,\n\tpathEqual,\n\trejects,\n\trepeat,\n\tresolves,\n\tsatisfies,\n\tthrows,\n\ttrue(value: unknown, message?: string): void {\n\t\tif (value !== true) throw new AssertionError(message ?? notEqualMessage(value, true), { ssf: assertron.true })\n\t},\n\ttruthy,\n\tuuid(value: unknown) {\n\t\tif (typeof value !== 'string') throw new AssertionError(`Expected ${value} to be a string`, { ssf: assertron.uuid })\n\n\t\tif (/^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/.test(value)) return\n\n\t\tthrow new AssertionError(`Expected ${value} to be a valid UUID`, { ssf: assertron.uuid })\n\t},\n}\n"],"mappings":";;;;;;;;;;;;AAmCA,MAAa,YAAuB;CACnC,MAAM,OAAgB,SAAwB;EAC7C,IAAI,UAAU,OAAO,MAAM,IAAI,eAAe,WAAW,gBAAgB,OAAO,KAAK,GAAG,EAAE,KAAK,UAAU,MAAM,CAAC;CACjH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK,OAAgB,SAAwB;EAC5C,IAAI,UAAU,MAAM,MAAM,IAAI,eAAe,WAAW,gBAAgB,OAAO,IAAI,GAAG,EAAE,KAAK,UAAU,KAAK,CAAC;CAC9G;CACA;CACA,KAAK,OAAgB;EACpB,IAAI,OAAO,UAAU,UAAU,MAAM,IAAI,eAAe,YAAY,MAAM,kBAAkB,EAAE,KAAK,UAAU,KAAK,CAAC;EAEnH,IAAI,wFAAwF,KAAK,KAAK,GAAG;EAEzG,MAAM,IAAI,eAAe,YAAY,MAAM,sBAAsB,EAAE,KAAK,UAAU,KAAK,CAAC;CACzF;AACD"}
|
package/esm/assertron/falsy.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { AssertionError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AssertionError } from "../errors.js";
|
|
2
|
+
//#region ts/assertron/falsy.ts
|
|
3
|
+
function falsy(value, message) {
|
|
4
|
+
if (value) throw new AssertionError(message ?? `Expected value to be falsy, but received ${value}`, { ssf: falsy });
|
|
5
5
|
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { falsy };
|
|
8
|
+
|
|
6
9
|
//# sourceMappingURL=falsy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"falsy.js","
|
|
1
|
+
{"version":3,"file":"falsy.js","names":[],"sources":["../../ts/assertron/falsy.ts"],"sourcesContent":["import { AssertionError } from '../errors.js'\n\nexport function falsy(value: unknown, message?: string): void {\n\tif (value) throw new AssertionError(message ?? `Expected value to be falsy, but received ${value}`, { ssf: falsy })\n}\n"],"mappings":";;AAEA,SAAgB,MAAM,OAAgB,SAAwB;CAC7D,IAAI,OAAO,MAAM,IAAI,eAAe,WAAW,4CAA4C,SAAS,EAAE,KAAK,MAAM,CAAC;AACnH"}
|
package/esm/assertron/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { SatisfyExpectation } from "./satisfies.js";
|
|
2
|
+
import { Assertron, assertron } from "./assertron.js";
|
|
3
|
+
export { Assertron, type SatisfyExpectation, assertron };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { AssertionError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { AssertionError } from "../errors.js";
|
|
2
|
+
//#region ts/assertron/isInstanceof.ts
|
|
3
|
+
function isInstanceof(value, type) {
|
|
4
|
+
if (value instanceof type) return;
|
|
5
|
+
throw new AssertionError(`Expected ${value} to be an instance of ${type.name}`, { ssf: isInstanceof });
|
|
6
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isInstanceof };
|
|
9
|
+
|
|
7
10
|
//# sourceMappingURL=isInstanceof.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isInstanceof.js","
|
|
1
|
+
{"version":3,"file":"isInstanceof.js","names":[],"sources":["../../ts/assertron/isInstanceof.ts"],"sourcesContent":["import type { AnyConstructor } from 'type-plus'\nimport { AssertionError } from '../errors.js'\n\nexport function isInstanceof<T extends AnyConstructor>(value: unknown, type: T): asserts value is InstanceType<T> {\n\tif (value instanceof type) return\n\n\tthrow new AssertionError(`Expected ${value} to be an instance of ${type.name}`, { ssf: isInstanceof })\n}\n"],"mappings":";;AAGA,SAAgB,aAAuC,OAAgB,MAA2C;CACjH,IAAI,iBAAiB,MAAM;CAE3B,MAAM,IAAI,eAAe,YAAY,MAAM,wBAAwB,KAAK,QAAQ,EAAE,KAAK,aAAa,CAAC;AACtG"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AssertionError } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { notEqualMessage } from "../utils/notEqualMessage.js";
|
|
2
|
+
import { AssertionError } from "../errors.js";
|
|
3
|
+
import { pathEqual } from "path-equal";
|
|
4
|
+
//#region ts/assertron/pathEqual.ts
|
|
5
|
+
function pathEqual$1(actual, expected) {
|
|
6
|
+
if (!pathEqual(actual, expected)) throw new AssertionError(notEqualMessage(actual, expected), { ssf: pathEqual$1 });
|
|
7
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { pathEqual$1 as pathEqual };
|
|
10
|
+
|
|
8
11
|
//# sourceMappingURL=pathEqual.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathEqual.js","
|
|
1
|
+
{"version":3,"file":"pathEqual.js","names":["pathEqual","isPathEqual"],"sources":["../../ts/assertron/pathEqual.ts"],"sourcesContent":["import { pathEqual as isPathEqual } from 'path-equal'\nimport { AssertionError } from '../errors.js'\nimport { notEqualMessage } from '../utils/index.js'\n\nexport function pathEqual(actual: string, expected: string): void {\n\tif (!isPathEqual(actual, expected)) throw new AssertionError(notEqualMessage(actual, expected), { ssf: pathEqual })\n}\n"],"mappings":";;;;AAIA,SAAgBA,YAAU,QAAgB,UAAwB;CACjE,IAAI,CAACC,UAAY,QAAQ,QAAQ,GAAG,MAAM,IAAI,eAAe,gBAAgB,QAAQ,QAAQ,GAAG,EAAE,KAAKD,YAAU,CAAC;AACnH"}
|
package/esm/assertron/rejects.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { notRejectedMessage } from "../utils/promiseMessages.js";
|
|
2
|
+
import { AssertionError } from "../errors.js";
|
|
3
|
+
//#region ts/assertron/rejects.ts
|
|
4
|
+
function rejects(promise) {
|
|
5
|
+
return promise.then((value) => {
|
|
6
|
+
throw new AssertionError(notRejectedMessage(value), { ssf: rejects });
|
|
7
|
+
}, (err) => err);
|
|
7
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { rejects };
|
|
11
|
+
|
|
8
12
|
//# sourceMappingURL=rejects.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rejects.js","
|
|
1
|
+
{"version":3,"file":"rejects.js","names":[],"sources":["../../ts/assertron/rejects.ts"],"sourcesContent":["import { AssertionError } from '../errors.js'\nimport { notRejectedMessage } from '../utils/index.js'\n\nexport function rejects<R = any>(promise: Promise<unknown>): Promise<R> {\n\treturn promise.then(\n\t\t(value) => {\n\t\t\tthrow new AssertionError(notRejectedMessage(value), { ssf: rejects })\n\t\t},\n\t\t(err) => err,\n\t)\n}\n"],"mappings":";;;AAGA,SAAgB,QAAiB,SAAuC;CACvE,OAAO,QAAQ,MACb,UAAU;EACV,MAAM,IAAI,eAAe,mBAAmB,KAAK,GAAG,EAAE,KAAK,QAAQ,CAAC;CACrE,IACC,QAAQ,GACV;AACD"}
|
package/esm/assertron/repeat.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { FailOnOccurrence } from "../errors.js";
|
|
2
|
+
import isPromise from "is-promise";
|
|
3
|
+
//#region ts/assertron/repeat.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
* Repeat the specified function n times and return the last result.
|
|
6
|
+
* If the result is a promise, it will run the function sequentially.
|
|
7
|
+
*/
|
|
8
|
+
function repeat(fn, times) {
|
|
9
|
+
return repeatRecur(fn, 1, times);
|
|
9
10
|
}
|
|
10
11
|
function repeatRecur(fn, i, times) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
if (e instanceof FailOnOccurrence)
|
|
26
|
-
throw e;
|
|
27
|
-
throw new FailOnOccurrence(i, e, { ssf: repeat });
|
|
28
|
-
}
|
|
12
|
+
try {
|
|
13
|
+
const result = fn();
|
|
14
|
+
if (i === times) return result;
|
|
15
|
+
if (isPromise(result)) return result.then(() => repeatRecur(fn, i + 1, times), (e) => {
|
|
16
|
+
throw new FailOnOccurrence(i, e, { ssf: repeat });
|
|
17
|
+
});
|
|
18
|
+
return repeatRecur(fn, i + 1, times);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e instanceof FailOnOccurrence) throw e;
|
|
21
|
+
throw new FailOnOccurrence(i, e, { ssf: repeat });
|
|
22
|
+
}
|
|
29
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { repeat };
|
|
26
|
+
|
|
30
27
|
//# sourceMappingURL=repeat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.js","
|
|
1
|
+
{"version":3,"file":"repeat.js","names":[],"sources":["../../ts/assertron/repeat.ts"],"sourcesContent":["import isPromise from 'is-promise'\nimport { FailOnOccurrence } from '../errors.js'\n\n/**\n * Repeat the specified function n times and return the last result.\n * If the result is a promise, it will run the function sequentially.\n */\nexport function repeat<R>(\n\tfn: () => R | (() => Promise<R>),\n\ttimes: number,\n): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R {\n\treturn repeatRecur(fn, 1, times)\n}\n\nfunction repeatRecur<R>(\n\tfn: () => R | (() => Promise<R>),\n\ti: number,\n\ttimes: number,\n): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R {\n\ttry {\n\t\tconst result = fn()\n\t\tif (i === times) return result as any\n\n\t\tif (isPromise(result)) {\n\t\t\treturn result.then(\n\t\t\t\t() => repeatRecur(fn, i + 1, times),\n\t\t\t\t(e) => {\n\t\t\t\t\tthrow new FailOnOccurrence(i, e, { ssf: repeat })\n\t\t\t\t},\n\t\t\t) as any\n\t\t}\n\t\treturn repeatRecur(fn, i + 1, times)\n\t} catch (e) {\n\t\tif (e instanceof FailOnOccurrence) throw e\n\t\tthrow new FailOnOccurrence(i, e, { ssf: repeat })\n\t}\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,OACf,IACA,OAC4D;CAC5D,OAAO,YAAY,IAAI,GAAG,KAAK;AAChC;AAEA,SAAS,YACR,IACA,GACA,OAC4D;CAC5D,IAAI;EACH,MAAM,SAAS,GAAG;EAClB,IAAI,MAAM,OAAO,OAAO;EAExB,IAAI,UAAU,MAAM,GACnB,OAAO,OAAO,WACP,YAAY,IAAI,IAAI,GAAG,KAAK,IACjC,MAAM;GACN,MAAM,IAAI,iBAAiB,GAAG,GAAG,EAAE,KAAK,OAAO,CAAC;EACjD,CACD;EAED,OAAO,YAAY,IAAI,IAAI,GAAG,KAAK;CACpC,SAAS,GAAG;EACX,IAAI,aAAa,kBAAkB,MAAM;EACzC,MAAM,IAAI,iBAAiB,GAAG,GAAG,EAAE,KAAK,OAAO,CAAC;CACjD;AACD"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { notResolvedMessage } from "../utils/promiseMessages.js";
|
|
2
|
+
import { AssertionError } from "../errors.js";
|
|
3
|
+
//#region ts/assertron/resolves.ts
|
|
4
|
+
function resolves(promise) {
|
|
5
|
+
return promise.then((v) => v, (error) => {
|
|
6
|
+
throw new AssertionError(notResolvedMessage(error), { ssf: resolves });
|
|
7
|
+
});
|
|
7
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { resolves };
|
|
11
|
+
|
|
8
12
|
//# sourceMappingURL=resolves.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolves.js","
|
|
1
|
+
{"version":3,"file":"resolves.js","names":[],"sources":["../../ts/assertron/resolves.ts"],"sourcesContent":["import { AssertionError } from '../errors.js'\nimport { notResolvedMessage } from '../utils/index.js'\n\nexport function resolves(promise: Promise<any>): Promise<void> {\n\treturn promise.then(\n\t\t(v) => v,\n\t\t(error) => {\n\t\t\tthrow new AssertionError(notResolvedMessage(error), { ssf: resolves })\n\t\t},\n\t)\n}\n"],"mappings":";;;AAGA,SAAgB,SAAS,SAAsC;CAC9D,OAAO,QAAQ,MACb,MAAM,IACN,UAAU;EACV,MAAM,IAAI,eAAe,mBAAmB,KAAK,GAAG,EAAE,KAAK,SAAS,CAAC;CACtE,CACD;AACD"}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Check if `actual` satisfies criteria in `expected`.
|
|
7
|
-
* @param expected All properties can be a value which will be compared to the same property in `actual`,
|
|
8
|
-
* RegExp, or a predicate function that will be used to check against the property.
|
|
9
|
-
*/
|
|
10
|
-
export declare function satisfies<Actual, Expected extends Actual>(actual: Actual, expected: SatisfyExpectation<Expected>): void;
|
|
1
|
+
import { If, IsExtend, NonComposableTypes } from "type-plus";
|
|
2
|
+
//#region ts/assertron/satisfies.d.ts
|
|
3
|
+
type SatisfyExpectation<T> = If<IsExtend<T, string>, T | RegExp, If<IsExtend<T, NonComposableTypes>, T, If<IsExtend<T, Array<any>>, T extends Array<infer E> ? Array<SatisfyExpectation<E>> : never, { [P in keyof T]?: T[P] extends string ? SatisfyExpectation<T[P]> | RegExp : SatisfyExpectation<T[P]>; }>>> | ((v: T) => boolean);
|
|
4
|
+
//#endregion
|
|
5
|
+
export { SatisfyExpectation };
|
|
11
6
|
//# sourceMappingURL=satisfies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satisfies.d.ts","
|
|
1
|
+
{"version":3,"file":"satisfies.d.ts","names":[],"sources":["../../ts/assertron/satisfies.ts"],"mappings":";;KAKY,mBAAmB,KAC5B,GACA,SAAS,YACT,IAAI,QACJ,GACC,SAAS,GAAG,qBACZ,GACA,GACC,SAAS,GAAG,aACZ,UAAU,YAAY,KAAK,MAAM,mBAAmB,gBAElD,WAAW,KAAK,EAAE,oBAAoB,mBAAmB,EAAE,MAAM,SAAS,mBAAmB,EAAE,cAKjG,GAAG"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AssertionError } from
|
|
3
|
-
import {
|
|
1
|
+
import { notSatisfiedMessage } from "../utils/notSatisfiedMessage.js";
|
|
2
|
+
import { AssertionError } from "../errors.js";
|
|
3
|
+
import { createSatisfier } from "satisfier";
|
|
4
|
+
//#region ts/assertron/satisfies.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new AssertionError(notSatisfiedMessage(diff), { ssf: satisfies });
|
|
13
|
-
}
|
|
6
|
+
* Check if `actual` satisfies criteria in `expected`.
|
|
7
|
+
* @param expected All properties can be a value which will be compared to the same property in `actual`,
|
|
8
|
+
* RegExp, or a predicate function that will be used to check against the property.
|
|
9
|
+
*/
|
|
10
|
+
function satisfies(actual, expected) {
|
|
11
|
+
const diff = createSatisfier(expected).exec(actual);
|
|
12
|
+
if (diff) throw new AssertionError(notSatisfiedMessage(diff), { ssf: satisfies });
|
|
14
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { satisfies };
|
|
16
|
+
|
|
15
17
|
//# sourceMappingURL=satisfies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satisfies.js","
|
|
1
|
+
{"version":3,"file":"satisfies.js","names":[],"sources":["../../ts/assertron/satisfies.ts"],"sourcesContent":["import { createSatisfier } from 'satisfier'\nimport type { If, IsExtend, NonComposableTypes } from 'type-plus'\nimport { AssertionError } from '../errors.js'\nimport { notSatisfiedMessage } from '../utils/index.js'\n\nexport type SatisfyExpectation<T> =\n\t| If<\n\t\t\tIsExtend<T, string>,\n\t\t\tT | RegExp,\n\t\t\tIf<\n\t\t\t\tIsExtend<T, NonComposableTypes>,\n\t\t\t\tT,\n\t\t\t\tIf<\n\t\t\t\t\tIsExtend<T, Array<any>>,\n\t\t\t\t\tT extends Array<infer E> ? Array<SatisfyExpectation<E>> : never,\n\t\t\t\t\t{\n\t\t\t\t\t\t[P in keyof T]?: T[P] extends string ? SatisfyExpectation<T[P]> | RegExp : SatisfyExpectation<T[P]>\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t>\n\t >\n\t| ((v: T) => boolean)\n\n/**\n * Check if `actual` satisfies criteria in `expected`.\n * @param expected All properties can be a value which will be compared to the same property in `actual`,\n * RegExp, or a predicate function that will be used to check against the property.\n */\nexport function satisfies<Actual, Expected extends Actual>(\n\tactual: Actual,\n\texpected: SatisfyExpectation<Expected>,\n): void {\n\tconst diff = createSatisfier(expected as any).exec(actual)\n\tif (diff) {\n\t\tthrow new AssertionError(notSatisfiedMessage(diff), { ssf: satisfies })\n\t}\n}\n"],"mappings":";;;;;;;;;AA4BA,SAAgB,UACf,QACA,UACO;CACP,MAAM,OAAO,gBAAgB,QAAe,CAAC,CAAC,KAAK,MAAM;CACzD,IAAI,MACH,MAAM,IAAI,eAAe,oBAAoB,IAAI,GAAG,EAAE,KAAK,UAAU,CAAC;AAExE"}
|
package/esm/assertron/throws.js
CHANGED
|
@@ -1,55 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
throw new AssertionError(notThrownMessage(value), { ssf: throws });
|
|
1
|
+
import { isErrorConstructor } from "../utils/isErrorConstructor.js";
|
|
2
|
+
import { notThrownMessage } from "../utils/notThrownMessage.js";
|
|
3
|
+
import { notRejectedMessage } from "../utils/promiseMessages.js";
|
|
4
|
+
import { unexpectedErrorMessage } from "../utils/unexpectedErrorMessage.js";
|
|
5
|
+
import { AssertionError } from "../errors.js";
|
|
6
|
+
import isPromise from "is-promise";
|
|
7
|
+
//#region ts/assertron/throws.ts
|
|
8
|
+
function throws(value, validator) {
|
|
9
|
+
if (typeof value !== "function" && !isPromise(value)) throw new AssertionError("`assertron.throws()` must be called with a function or promise.", { ssf: throws });
|
|
10
|
+
if (!isPromise(value)) {
|
|
11
|
+
const { threw, err, result } = tryCatch(value);
|
|
12
|
+
if (threw) {
|
|
13
|
+
if (failValidation(validator, err)) throw new AssertionError(unexpectedErrorMessage(err, validator), { ssf: throws });
|
|
14
|
+
return err;
|
|
15
|
+
}
|
|
16
|
+
value = result;
|
|
17
|
+
}
|
|
18
|
+
if (isPromise(value)) return value.then((value) => {
|
|
19
|
+
throw new AssertionError(notRejectedMessage(value), { ssf: throws });
|
|
20
|
+
}, (err) => {
|
|
21
|
+
if (failValidation(validator, err)) throw new AssertionError(unexpectedErrorMessage(err, validator), {
|
|
22
|
+
ssf: throws,
|
|
23
|
+
cause: err
|
|
24
|
+
});
|
|
25
|
+
return err;
|
|
26
|
+
});
|
|
27
|
+
throw new AssertionError(notThrownMessage(value), { ssf: throws });
|
|
31
28
|
}
|
|
32
29
|
function tryCatch(fn) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
let result;
|
|
31
|
+
let err;
|
|
32
|
+
let threw = false;
|
|
33
|
+
try {
|
|
34
|
+
result = fn();
|
|
35
|
+
} catch (e) {
|
|
36
|
+
err = e;
|
|
37
|
+
threw = true;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
threw,
|
|
41
|
+
err,
|
|
42
|
+
result
|
|
43
|
+
};
|
|
44
44
|
}
|
|
45
45
|
function failValidation(validator, error) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return !(error instanceof validator);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return !validator(error);
|
|
53
|
-
}
|
|
46
|
+
if (!validator) return false;
|
|
47
|
+
if (isErrorConstructor(validator)) return !(error instanceof validator);
|
|
48
|
+
return !validator(error);
|
|
54
49
|
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { throws };
|
|
52
|
+
|
|
55
53
|
//# sourceMappingURL=throws.js.map
|