@rickosborne/guard 2024.12.30 → 2024.12.32

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 CHANGED
@@ -1,120 +1,154 @@
1
- **@rickosborne/guard v2024.12.30**
1
+ # @rickosborne/guard
2
2
 
3
+ Basic type guards building on [@rickosborne/typical](https://www.npmjs.com/package/@rickosborne/typical).
3
4
  ***
4
5
 
5
- # @rickosborne/guard
6
+ ## API
6
7
 
7
- Basic type guards building on [@rickosborne/typical](https://www.npmjs.com/package/@rickosborne/typical).
8
+ ### Functions
8
9
 
9
- ## Type Aliases
10
+ #### assertDefined
10
11
 
11
- ### MessageOrError
12
+ <a id="api-assertdefined"></a>
12
13
 
13
- > **MessageOrError**: string \| Error \| () => string \| Error
14
+ ```typescript
15
+ declare function assertDefined<T>(value: T, messageOrError: MessageOrError): asserts value is NonNullable<T>;
16
+ ```
14
17
 
15
- A message, an error, or something which can generate one of those.
18
+ #### assertInt
16
19
 
17
- ## Functions
20
+ <a id="api-assertint"></a>
18
21
 
19
- > **assertDefined**\<T\>(value, messageOrError): asserts value is NonNullable<T>
22
+ ```typescript
23
+ declare function assertInt(value: unknown, messageOrError: MessageOrError): asserts value is number;
24
+ ```
20
25
 
21
- ***
26
+ #### errorFromMessageOrError
22
27
 
23
- > **assertInt**(value, messageOrError): asserts value is number
28
+ <a id="api-errorfrommessageorerror"></a>
24
29
 
25
- ***
30
+ ```typescript
31
+ errorFromMessageOrError: (messageOrError: MessageOrError, defaultConstructor?: (new (message: string) => Error)) => Error
32
+ ```
26
33
 
27
- > **errorFromMessageOrError**(messageOrError, defaultConstructor): Error
34
+ Helper for guards which expect text or an error, or can generate one when needed.
28
35
 
29
- Helper for guards which expect text or an error, or
30
- can generate one when needed.
31
36
 
32
- ***
37
+ #### expectInt
33
38
 
34
- > **expectInt**(obj, messageOrError): number
39
+ <a id="api-expectint"></a>
35
40
 
36
- ***
41
+ ```typescript
42
+ expectInt: (obj: unknown, messageOrError: MessageOrError) => number
43
+ ```
37
44
 
38
- ### hasArray()
45
+ #### hasArray
39
46
 
40
- Guard for whether the given value is an object which has a property with its own array value.
47
+ <a id="api-hasarray"></a>
41
48
 
42
- #### Call Signature
49
+ ```typescript
50
+ declare function hasArray<Name extends string>(obj: unknown, name: Name, predicate?: undefined): obj is {
51
+ [K in Name]: unknown[];
52
+ };
53
+ ```
43
54
 
44
- > **hasArray**\<Name\>(obj, name, predicate?): obj is { [K in string]: unknown[] }
55
+ Guard for whether the given value is an object which has a property with its own array value. This variant does not exhaustively check the items of the array.
45
56
 
46
- Guard for whether the given value is an object which has a property with its own array value.
47
- This variant does not exhaustively check the items of the array.
48
57
 
49
- ##### Type Parameters
58
+ #### hasArray
50
59
 
51
- **Name** *extends* `string`
60
+ <a id="api-hasarray"></a>
52
61
 
53
- #### Call Signature
62
+ ```typescript
63
+ declare function hasArray<Name extends string, Item>(obj: unknown, name: Name, predicate?: (item: unknown, index: number, items: unknown[]) => item is Item): obj is {
64
+ [K in Name]: Item[];
65
+ };
66
+ ```
54
67
 
55
- > **hasArray**\<Name, Item\>(obj, name, predicate?): obj is { [K in string]: Item[] }
68
+ Guard for whether the given value is an object which has a property with its own array value. This variant exhaustively checks the items of the array against the given predicate.
56
69
 
57
- Guard for whether the given value is an object which has a property with its own array value.
58
- This variant exhaustively checks the items of the array against the given predicate.
59
70
 
60
- ##### Type Parameters
71
+ #### hasNumber
61
72
 
62
- **Name** *extends* `string`
73
+ <a id="api-hasnumber"></a>
63
74
 
64
- • **Item**
75
+ ```typescript
76
+ hasNumber: <Name extends string>(obj: unknown, name: Name) => obj is { [k in Name]: string; }
77
+ ```
65
78
 
66
- ***
79
+ #### hasOwn
67
80
 
68
- > **hasNumber**\<Name\>(obj, name): obj is { [k in string]: string }
81
+ <a id="api-hasown"></a>
69
82
 
70
- #### Type Parameters
83
+ ```typescript
84
+ declare function hasOwn<Name extends string>(obj: unknown, name: Name): obj is {
85
+ [K in Name]: unknown;
86
+ };
87
+ ```
71
88
 
72
- **Name** *extends* `string`
89
+ #### hasOwn
73
90
 
74
- ***
91
+ <a id="api-hasown"></a>
75
92
 
76
- ### hasOwn()
93
+ ```typescript
94
+ declare function hasOwn<Name extends string, T>(obj: unknown, name: Name, predicate: (value: unknown) => value is T): obj is {
95
+ [K in Name]: T;
96
+ };
97
+ ```
77
98
 
78
- #### Call Signature
99
+ #### isInt
79
100
 
80
- > **hasOwn**\<Name\>(obj, name): obj is { [K in string]: unknown }
101
+ <a id="api-isint"></a>
81
102
 
82
- ##### Type Parameters
103
+ ```typescript
104
+ isInt: (obj: unknown) => obj is number
105
+ ```
83
106
 
84
- **Name** *extends* `string`
107
+ #### isListOf
85
108
 
86
- #### Call Signature
109
+ <a id="api-islistof"></a>
87
110
 
88
- > **hasOwn**\<Name, T\>(obj, name, predicate): obj is { [K in string]: T }
111
+ ```typescript
112
+ isListOf: <T>(list: unknown, predicate: (item: unknown, index: number, items: unknown[]) => item is T) => list is T[]
113
+ ```
89
114
 
90
- ##### Type Parameters
115
+ #### isObject
91
116
 
92
- **Name** *extends* `string`
117
+ <a id="api-isobject"></a>
93
118
 
94
- • **T**
119
+ ```typescript
120
+ isObject: (obj: unknown) => obj is NonNullable<object>
121
+ ```
95
122
 
96
- ***
123
+ #### isPlainObject
97
124
 
98
- > **isInt**(obj): obj is number
125
+ <a id="api-isplainobject"></a>
99
126
 
100
- ***
127
+ ```typescript
128
+ isPlainObject: (obj: unknown) => obj is Record<never, never>
129
+ ```
101
130
 
102
- > **isListOf**\<T\>(list, predicate): list is T[]
131
+ #### isUnaryPredicate
103
132
 
104
- ***
133
+ <a id="api-isunarypredicate"></a>
105
134
 
106
- > **isObject**(obj): obj is object
135
+ ```typescript
136
+ isUnaryPredicate: (obj: unknown) => obj is UnaryPredicate<unknown>
137
+ ```
107
138
 
108
- ***
139
+ Tests whether the given object is a function and takes at least one parameter, and could maybe act as a unary predicate. Warning! Since no type information is available at runtime, it may not actually act as a predicate!
109
140
 
110
- > **isPlainObject**(obj): obj is Record<never, never>
111
141
 
112
- ***
142
+ ### TypeAliases
143
+
144
+ #### MessageOrError
145
+
146
+ <a id="api-messageorerror"></a>
113
147
 
114
- > **isUnaryPredicate**(obj): obj is UnaryPredicate<unknown>
148
+ ```typescript
149
+ type MessageOrError = string | Error | (() => (string | Error));
150
+ ```
151
+
152
+ A message, an error, or something which can generate one of those.
115
153
 
116
- Tests whether the given object is a function and takes at
117
- least one parameter, and could maybe act as a unary predicate.
118
- Warning! Since no type information is available at runtime,
119
- it may not actually act as a predicate!
120
154
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://rickosborne.org"
5
5
  },
6
6
  "dependencies": {
7
- "@rickosborne/typical": "2024.12.30"
7
+ "@rickosborne/typical": "2024.12.32"
8
8
  },
9
9
  "description": "Rick Osborne's collection of type guards.",
10
10
  "engines": {
@@ -19,17 +19,26 @@
19
19
  }
20
20
  },
21
21
  "homepage": "https://github.com/rickosborne/es-js-ts",
22
+ "keywords": [
23
+ "typescript",
24
+ "guards",
25
+ "type guards"
26
+ ],
22
27
  "license": "CC-BY-NC-SA-4.0",
23
28
  "main": "cjs/index.js",
29
+ "module": "esm/index.js",
24
30
  "name": "@rickosborne/guard",
25
31
  "private": false,
26
32
  "publishConfig": {
27
33
  "access": "public"
28
34
  },
35
+ "readme": "README.md",
29
36
  "repository": {
30
37
  "directory": "guard",
31
38
  "type": "git",
32
39
  "url": "git+https://github.com/rickosborne/es-js-ts.git"
33
40
  },
34
- "version": "2024.12.30"
41
+ "types": "types/index.d.ts",
42
+ "typings": "types/index.d.ts",
43
+ "version": "2024.12.32"
35
44
  }
package/types/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export * from "./ts/is-int.js";
7
7
  export * from "./ts/is-list-of.js";
8
8
  export * from "./ts/is-object.js";
9
9
  export * from "./ts/is-predicate.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  import { type MessageOrError } from "./error-from-message.js";
2
2
  export declare function assertDefined<T>(value: T, messageOrError: MessageOrError): asserts value is NonNullable<T>;
3
+ //# sourceMappingURL=assert-defined.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-defined.d.ts","sourceRoot":"","sources":["../../../ts/assert-defined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,yBAAyB,CAAC;AAEvF,wBAAgB,aAAa,CAAC,CAAC,EAC9B,KAAK,EAAE,CAAC,EACR,cAAc,EAAE,cAAc,GAC5B,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAKjC"}
@@ -7,3 +7,4 @@ export type MessageOrError = string | Error | (() => (string | Error));
7
7
  * can generate one when needed.
8
8
  */
9
9
  export declare const errorFromMessageOrError: (messageOrError: MessageOrError, defaultConstructor?: (new (message: string) => Error)) => Error;
10
+ //# sourceMappingURL=error-from-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-from-message.d.ts","sourceRoot":"","sources":["../../../ts/error-from-message.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;AAEvE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,mBACnB,cAAc,uBACV,CAAC,KAAK,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,KAClD,KAcF,CAAC"}
@@ -12,3 +12,4 @@ export declare function hasArray<Name extends string>(obj: unknown, name: Name,
12
12
  export declare function hasArray<Name extends string, Item>(obj: unknown, name: Name, predicate?: (item: unknown, index: number, items: unknown[]) => item is Item): obj is {
13
13
  [K in Name]: Item[];
14
14
  };
15
+ //# sourceMappingURL=has-array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-array.d.ts","sourceRoot":"","sources":["../../../ts/has-array.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,GAAG,IAAI;KAAG,CAAC,IAAI,IAAI,GAAG,OAAO,EAAE;CAAE,CAAC;AAClI;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI,IAAI,GAAG,GAAG,IAAI;KAAG,CAAC,IAAI,IAAI,GAAG,IAAI,EAAE;CAAE,CAAC"}
@@ -1 +1,2 @@
1
1
  export declare const hasNumber: <Name extends string>(obj: unknown, name: Name) => obj is { [k in Name]: string; };
2
+ //# sourceMappingURL=has-number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-number.d.ts","sourceRoot":"","sources":["../../../ts/has-number.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,GAAI,IAAI,SAAS,MAAM,OAAO,OAAO,QAAQ,IAAI,KAAG,GAAG,IAAI,GAAE,CAAC,IAAI,IAAI,GAAG,MAAM,GAEpG,CAAC"}
@@ -4,3 +4,4 @@ export declare function hasOwn<Name extends string>(obj: unknown, name: Name): o
4
4
  export declare function hasOwn<Name extends string, T>(obj: unknown, name: Name, predicate: (value: unknown) => value is T): obj is {
5
5
  [K in Name]: T;
6
6
  };
7
+ //# sourceMappingURL=has-own.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-own.d.ts","sourceRoot":"","sources":["../../../ts/has-own.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,IAAI,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,GAAG,IAAI;KAAE,CAAC,IAAI,IAAI,GAAG,OAAO;CAAC,CAAC;AACrG,wBAAgB,MAAM,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,GAAG,GAAG,IAAI;KAAE,CAAC,IAAI,IAAI,GAAG,CAAC;CAAC,CAAC"}
@@ -2,3 +2,4 @@ import { type MessageOrError } from "./error-from-message.js";
2
2
  export declare const isInt: (obj: unknown) => obj is number;
3
3
  export declare function assertInt(value: unknown, messageOrError: MessageOrError): asserts value is number;
4
4
  export declare const expectInt: (obj: unknown, messageOrError: MessageOrError) => number;
5
+ //# sourceMappingURL=is-int.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-int.d.ts","sourceRoot":"","sources":["../../../ts/is-int.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,yBAAyB,CAAC;AAEvF,eAAO,MAAM,KAAK,QAAS,OAAO,KAAG,GAAG,IAAI,MAAoH,CAAC;AAEjK,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAIjG;AAED,eAAO,MAAM,SAAS,QAChB,OAAO,kBACI,cAAc,KAC5B,MAGF,CAAC"}
@@ -1 +1,2 @@
1
1
  export declare const isListOf: <T>(list: unknown, predicate: (item: unknown, index: number, items: unknown[]) => item is T) => list is T[];
2
+ //# sourceMappingURL=is-list-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-list-of.d.ts","sourceRoot":"","sources":["../../../ts/is-list-of.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GAAI,CAAC,QACnB,OAAO,aACF,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC,KACtE,IAAI,IAAI,CAAC,EAEX,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export declare const isObject: (obj: unknown) => obj is NonNullable<object>;
2
2
  export declare const isPlainObject: (obj: unknown) => obj is Record<never, never>;
3
+ //# sourceMappingURL=is-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-object.d.ts","sourceRoot":"","sources":["../../../ts/is-object.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,QAAS,OAAO,KAAG,GAAG,IAAI,WAAW,CAAC,MAAM,CAEhE,CAAC;AAEF,eAAO,MAAM,aAAa,QAAS,OAAO,KAAG,GAAG,IAAI,MAAM,CAAC,KAAK,EAAC,KAAK,CAMrE,CAAC"}
@@ -6,3 +6,4 @@ import { UnaryPredicate } from "@rickosborne/typical";
6
6
  * it may not actually act as a predicate!
7
7
  */
8
8
  export declare const isUnaryPredicate: (obj: unknown) => obj is UnaryPredicate<unknown>;
9
+ //# sourceMappingURL=is-predicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-predicate.d.ts","sourceRoot":"","sources":["../../../ts/is-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAS,OAAO,KAAG,GAAG,IAAI,cAAc,CAAC,OAAO,CAE5E,CAAC"}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.48.1"
9
+ }
10
+ ]
11
+ }