@guillaume-docquier/tools-ts 2.0.0 → 2.1.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/Assert.d.ts +6 -0
- package/dist/Assert.js +14 -0
- package/dist/Assert.js.map +1 -1
- package/package.json +1 -1
package/dist/Assert.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EnumType, ConstructorType } from "./utility-types.js";
|
|
2
|
+
import { Result, Success } from "./Result.js";
|
|
2
3
|
/**
|
|
3
4
|
* From Wikipedia
|
|
4
5
|
* In computer programming, [...] an assertion is a predicate connected to a point in the program, that always should evaluate to true at that point in code execution.
|
|
@@ -127,4 +128,9 @@ export declare class Assert {
|
|
|
127
128
|
* ```
|
|
128
129
|
*/
|
|
129
130
|
static isExhausted(this: void, value: never): asserts value is never;
|
|
131
|
+
/**
|
|
132
|
+
* Asserts that the Result is a success.
|
|
133
|
+
* This is mostly useful in tests, as real code should handle Failures.
|
|
134
|
+
*/
|
|
135
|
+
static isSuccess<T>(this: void, result: Result<T, unknown>, paramName?: string): asserts result is Success<T>;
|
|
130
136
|
}
|
package/dist/Assert.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AssertionError } from "./errors/AssertionError.js";
|
|
2
2
|
import { TypeGuard } from "./TypeGuard.js";
|
|
3
|
+
import { Result } from "./Result.js";
|
|
3
4
|
/**
|
|
4
5
|
* From Wikipedia
|
|
5
6
|
* In computer programming, [...] an assertion is a predicate connected to a point in the program, that always should evaluate to true at that point in code execution.
|
|
@@ -175,6 +176,19 @@ export class Assert {
|
|
|
175
176
|
received: value,
|
|
176
177
|
}, Assert.isExhausted);
|
|
177
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Asserts that the Result is a success.
|
|
181
|
+
* This is mostly useful in tests, as real code should handle Failures.
|
|
182
|
+
*/
|
|
183
|
+
static isSuccess(result, paramName) {
|
|
184
|
+
if (Result.isFailure(result)) {
|
|
185
|
+
throw new AssertionError("Expected result to be Success", {
|
|
186
|
+
paramName,
|
|
187
|
+
expected: "a Success",
|
|
188
|
+
received: `a Failure: ${formatPrimitiveValue(result.error)}`,
|
|
189
|
+
}, Assert.isSuccess);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
178
192
|
}
|
|
179
193
|
/**
|
|
180
194
|
* `quoteStrings` will put strings inside single quote for nicer output when you know the string will be nested inside a double quoted string
|
package/dist/Assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Assert.js","sourceRoot":"","sources":["../src/Assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"Assert.js","sourceRoot":"","sources":["../src/Assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAW,MAAM,aAAa,CAAA;AAE7C;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,MAAM;IACjB;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,YAAY,CAExB,aAAqC,EACrC,eAAwB,EACxB,SAAkB;QAElB,IAAI,CAAC,CAAC,eAAe,YAAY,aAAa,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,cAAc,CACtB,wCAAwC,EACxC;gBACE,SAAS;gBACT,QAAQ,EAAE,aAAa,CAAC,IAAI;gBAC5B,QAAQ,EAAE,eAAe,EAAE,WAAW,CAAC,IAAI,IAAI,OAAO,eAAe;aACtE,EACD,MAAM,CAAC,YAAY,CACpB,CAAA;QACH,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,MAAM,CAAC,SAAS,CAAoB,YAAsC,EAAE,SAAkB;QACnG,IA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