@xylabs/assert 4.2.1 → 4.3.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/neutral/index.d.ts +12 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -1
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
export type AssertExMessageFunc<T> = (value?: T | null) => string;
|
|
2
2
|
export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Intended for simple null/undefined checks for variables
|
|
6
|
+
*
|
|
7
|
+
* @param expr - Expression to be evaluated for truthiness
|
|
8
|
+
* @param message - Message in Error if expression is false, may be a function that returns a string
|
|
9
|
+
* @throws AssertExError
|
|
10
|
+
* @returns Value of expression
|
|
11
|
+
*/
|
|
3
12
|
declare function assertEx<T>(expr: T | null | undefined): T;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated - replace string with () => string
|
|
15
|
+
*/
|
|
4
16
|
declare function assertEx<T>(expr: T | null | undefined, message?: string): T;
|
|
5
17
|
declare function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T;
|
|
6
18
|
declare function assertEx<T, R extends Error>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,MAAM,CAAA;AACjE,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,MAAM,CAAA;AACjE,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAA;AAE3E;;;;;;;;GAQG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,CAAA;AACnD;;GAEG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;AACrE,iBAAS,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AACzF,iBAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAczG,OAAO,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type AssertExMessageFunc<T> = (value?: T | null) => string\nexport type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R\n\n/**\n *\n * Intended for simple null/undefined checks for variables\n *\n * @param expr - Expression to be evaluated for truthiness\n * @param message - Message in Error if expression is false, may be a function that returns a string\n * @throws AssertExError\n * @returns Value of expression\n */\nfunction assertEx<T>(expr: T | null | undefined): T\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type AssertExMessageFunc<T> = (value?: T | null) => string\nexport type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R\n\n/**\n *\n * Intended for simple null/undefined checks for variables\n *\n * @param expr - Expression to be evaluated for truthiness\n * @param message - Message in Error if expression is false, may be a function that returns a string\n * @throws AssertExError\n * @returns Value of expression\n */\nfunction assertEx<T>(expr: T | null | undefined): T\n/**\n * @deprecated - replace string with () => string\n */\nfunction assertEx<T>(expr: T | null | undefined, message?: string): T\nfunction assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T\nfunction assertEx<T, R extends Error>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T\nfunction assertEx<T, R extends Error, P extends string | AssertExMessageFunc<T> | AssertExErrorFunc<T, R>>(\n expr: T | null | undefined,\n messageOrFunc?: P,\n): T {\n if (expr) return expr\n if (typeof messageOrFunc === 'function') {\n const errorOrMessage = messageOrFunc(expr)\n throw typeof errorOrMessage === 'string' ? new Error(errorOrMessage) : errorOrMessage\n }\n // a string was sent\n throw new Error(messageOrFunc)\n}\n\nexport { assertEx }\n"],"mappings":";AAmBA,SAAS,SACP,MACA,eACG;AACH,MAAI,KAAM,QAAO;AACjB,MAAI,OAAO,kBAAkB,YAAY;AACvC,UAAM,iBAAiB,cAAc,IAAI;AACzC,UAAM,OAAO,mBAAmB,WAAW,IAAI,MAAM,cAAc,IAAI;AAAA,EACzE;AAEA,QAAM,IAAI,MAAM,aAAa;AAC/B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/assert",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"module": "./dist/neutral/index.mjs",
|
|
36
36
|
"types": "./dist/neutral/index.d.ts",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@xylabs/ts-scripts-yarn3": "^4.2.
|
|
39
|
-
"@xylabs/tsconfig": "^4.2.
|
|
38
|
+
"@xylabs/ts-scripts-yarn3": "^4.2.3",
|
|
39
|
+
"@xylabs/tsconfig": "^4.2.3",
|
|
40
40
|
"typescript": "^5.6.3"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,9 @@ export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R
|
|
|
11
11
|
* @returns Value of expression
|
|
12
12
|
*/
|
|
13
13
|
function assertEx<T>(expr: T | null | undefined): T
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated - replace string with () => string
|
|
16
|
+
*/
|
|
15
17
|
function assertEx<T>(expr: T | null | undefined, message?: string): T
|
|
16
18
|
function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T
|
|
17
19
|
function assertEx<T, R extends Error>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T
|