@rcompat/is 0.1.3 → 0.2.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/README.md +383 -0
- package/lib/private/array.d.ts +3 -0
- package/lib/private/array.js +2 -0
- package/lib/private/date.d.ts +2 -0
- package/lib/private/date.js +4 -0
- package/lib/private/dict.d.ts +3 -0
- package/lib/private/dict.js +7 -0
- package/lib/private/empty.js +0 -6
- package/lib/private/finite.js +2 -4
- package/lib/private/index.d.ts +48 -0
- package/lib/private/index.js +74 -0
- package/lib/private/int.d.ts +2 -0
- package/lib/private/{integer.js → int.js} +2 -2
- package/lib/private/numbers.d.ts +14 -0
- package/lib/private/numbers.js +37 -0
- package/lib/private/numeric.js +2 -4
- package/lib/private/object.d.ts +2 -0
- package/lib/private/object.js +4 -0
- package/lib/private/primitive.js +3 -3
- package/lib/private/promise.d.ts +2 -0
- package/lib/private/promise.js +4 -0
- package/lib/private/regexp.d.ts +2 -0
- package/lib/private/regexp.js +4 -0
- package/lib/private/safeint.d.ts +2 -0
- package/lib/private/{safe-integer.js → safeint.js} +2 -2
- package/lib/private/strings.d.ts +9 -0
- package/lib/private/strings.js +11 -0
- package/lib/private/uint.js +2 -2
- package/lib/private/url.d.ts +2 -0
- package/lib/private/url.js +4 -0
- package/lib/public/index.d.ts +2 -0
- package/lib/public/index.js +2 -0
- package/package.json +5 -5
- package/lib/private/integer.d.ts +0 -2
- package/lib/private/safe-integer.d.ts +0 -2
- package/lib/public/blank.d.ts +0 -2
- package/lib/public/blank.js +0 -2
- package/lib/public/boolish.d.ts +0 -2
- package/lib/public/boolish.js +0 -2
- package/lib/public/defined.d.ts +0 -2
- package/lib/public/defined.js +0 -2
- package/lib/public/empty.d.ts +0 -2
- package/lib/public/empty.js +0 -2
- package/lib/public/falsy.d.ts +0 -2
- package/lib/public/falsy.js +0 -2
- package/lib/public/finite.d.ts +0 -2
- package/lib/public/finite.js +0 -2
- package/lib/public/integer.d.ts +0 -2
- package/lib/public/integer.js +0 -2
- package/lib/public/nan.d.ts +0 -2
- package/lib/public/nan.js +0 -2
- package/lib/public/newable.d.ts +0 -2
- package/lib/public/newable.js +0 -2
- package/lib/public/nullish.d.ts +0 -2
- package/lib/public/nullish.js +0 -2
- package/lib/public/numeric.d.ts +0 -2
- package/lib/public/numeric.js +0 -2
- package/lib/public/primitive.d.ts +0 -2
- package/lib/public/primitive.js +0 -2
- package/lib/public/safe-integer.d.ts +0 -2
- package/lib/public/safe-integer.js +0 -2
- package/lib/public/truthy.d.ts +0 -2
- package/lib/public/truthy.js +0 -2
- package/lib/public/uint.d.ts +0 -2
- package/lib/public/uint.js +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# @rcompat/is
|
|
2
|
+
|
|
3
|
+
Type guard predicates for JavaScript runtimes.
|
|
4
|
+
|
|
5
|
+
## What is @rcompat/is?
|
|
6
|
+
|
|
7
|
+
A cross-runtime module providing type guard functions for common value checks.
|
|
8
|
+
All functions return boolean and include TypeScript type narrowing. Works
|
|
9
|
+
consistently across Node, Deno, and Bun.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @rcompat/is
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @rcompat/is
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @rcompat/is
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun add @rcompat/is
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### nullish
|
|
32
|
+
|
|
33
|
+
Checks if a value is `null` or `undefined`.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import is from "@rcompat/is";
|
|
37
|
+
|
|
38
|
+
is.nullish(null); // true
|
|
39
|
+
is.nullish(undefined); // true
|
|
40
|
+
is.nullish(0); // false
|
|
41
|
+
is.nullish(""); // false
|
|
42
|
+
is.nullish(false); // false
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### defined
|
|
46
|
+
|
|
47
|
+
Checks if a value is not `undefined`.
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import is from "@rcompat/is";
|
|
51
|
+
|
|
52
|
+
is.defined("hello"); // true
|
|
53
|
+
is.defined(0); // true
|
|
54
|
+
is.defined(null); // true
|
|
55
|
+
is.defined(undefined); // false
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### truthy
|
|
59
|
+
|
|
60
|
+
Checks if a value is truthy.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import is from "@rcompat/is";
|
|
64
|
+
|
|
65
|
+
is.truthy(1); // true
|
|
66
|
+
is.truthy("hello"); // true
|
|
67
|
+
is.truthy([]); // true
|
|
68
|
+
is.truthy(0); // false
|
|
69
|
+
is.truthy(""); // false
|
|
70
|
+
is.truthy(null); // false
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### falsy
|
|
74
|
+
|
|
75
|
+
Checks if a value is falsy.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import is from "@rcompat/is";
|
|
79
|
+
|
|
80
|
+
is.falsy(0); // true
|
|
81
|
+
is.falsy(""); // true
|
|
82
|
+
is.falsy(null); // true
|
|
83
|
+
is.falsy(undefined); // true
|
|
84
|
+
is.falsy(false); // true
|
|
85
|
+
is.falsy(NaN); // true
|
|
86
|
+
is.falsy(1); // false
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### empty
|
|
90
|
+
|
|
91
|
+
Checks if a value is empty (strings, arrays, Sets, Maps, objects).
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import is from "@rcompat/is";
|
|
95
|
+
|
|
96
|
+
is.empty(""); // true
|
|
97
|
+
is.empty([]); // true
|
|
98
|
+
is.empty({}); // true
|
|
99
|
+
is.empty(new Set()); // true
|
|
100
|
+
is.empty(new Map()); // true
|
|
101
|
+
is.empty("hello"); // false
|
|
102
|
+
is.empty([1, 2]); // false
|
|
103
|
+
is.empty({ a: 1 }); // false
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### blank
|
|
107
|
+
|
|
108
|
+
Checks if a string is empty or contains only whitespace.
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
import is from "@rcompat/is";
|
|
112
|
+
|
|
113
|
+
is.blank(""); // true
|
|
114
|
+
is.blank(" "); // true
|
|
115
|
+
is.blank("\t\n"); // true
|
|
116
|
+
is.blank("hello"); // false
|
|
117
|
+
is.blank(" hi "); // false
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### numeric
|
|
121
|
+
|
|
122
|
+
Checks if a string represents a valid number.
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import is from "@rcompat/is";
|
|
126
|
+
|
|
127
|
+
is.numeric("123"); // true
|
|
128
|
+
is.numeric("-45.67"); // true
|
|
129
|
+
is.numeric("1e10"); // true
|
|
130
|
+
is.numeric("+3.14"); // true
|
|
131
|
+
is.numeric("abc"); // false
|
|
132
|
+
is.numeric(""); // false
|
|
133
|
+
is.numeric("12px"); // false
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### int
|
|
137
|
+
|
|
138
|
+
Checks if a value is an integer number.
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import is from "@rcompat/is";
|
|
142
|
+
|
|
143
|
+
is.int(42); // true
|
|
144
|
+
is.int(-10); // true
|
|
145
|
+
is.int(0); // true
|
|
146
|
+
is.int(3.14); // false
|
|
147
|
+
is.int(NaN); // false
|
|
148
|
+
is.int("42"); // false
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### uint
|
|
152
|
+
|
|
153
|
+
Checks if a value is a positive integer (unsigned).
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
import is from "@rcompat/is";
|
|
157
|
+
|
|
158
|
+
is.uint(1); // true
|
|
159
|
+
is.uint(100); // true
|
|
160
|
+
is.uint(0); // false
|
|
161
|
+
is.uint(-1); // false
|
|
162
|
+
is.uint(3.14); // false
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### safeint
|
|
166
|
+
|
|
167
|
+
Checks if a value is a safe integer (within JavaScript's safe range).
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
import is from "@rcompat/is";
|
|
171
|
+
|
|
172
|
+
is.safeint(42); // true
|
|
173
|
+
is.safeint(Number.MAX_SAFE_INTEGER); // true
|
|
174
|
+
is.safeint(Number.MAX_SAFE_INTEGER + 1); // false
|
|
175
|
+
is.safeint(3.14); // false
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### finite
|
|
179
|
+
|
|
180
|
+
Checks if a number or bigint is finite.
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import is from "@rcompat/is";
|
|
184
|
+
|
|
185
|
+
is.finite(42); // true
|
|
186
|
+
is.finite(3.14); // true
|
|
187
|
+
is.finite(100n); // true (bigints are always finite)
|
|
188
|
+
is.finite(Infinity); // false
|
|
189
|
+
is.finite(-Infinity); // false
|
|
190
|
+
is.finite(NaN); // false
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### nan
|
|
194
|
+
|
|
195
|
+
Checks if a value is `NaN`.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import is from "@rcompat/is";
|
|
199
|
+
|
|
200
|
+
is.nan(NaN); // true
|
|
201
|
+
is.nan(Number.NaN); // true
|
|
202
|
+
is.nan(0 / 0); // true
|
|
203
|
+
is.nan(42); // false
|
|
204
|
+
is.nan("NaN"); // false
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### primitive
|
|
208
|
+
|
|
209
|
+
Checks if a value is a primitive type.
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
import is from "@rcompat/is";
|
|
213
|
+
|
|
214
|
+
is.primitive("hello"); // true
|
|
215
|
+
is.primitive(42); // true
|
|
216
|
+
is.primitive(true); // true
|
|
217
|
+
is.primitive(null); // true
|
|
218
|
+
is.primitive(undefined); // true
|
|
219
|
+
is.primitive(Symbol()); // true
|
|
220
|
+
is.primitive(100n); // true
|
|
221
|
+
is.primitive({}); // false
|
|
222
|
+
is.primitive([]); // false
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### dict
|
|
226
|
+
|
|
227
|
+
Checks if a value is a plain object (not array, Date, class instance, etc.).
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
import is from "@rcompat/is";
|
|
231
|
+
|
|
232
|
+
is.dict({}); // true
|
|
233
|
+
is.dict({ a: 1 }); // true
|
|
234
|
+
is.dict(Object.create(null)); // true
|
|
235
|
+
is.dict([]); // false
|
|
236
|
+
is.dict(new Date()); // false
|
|
237
|
+
is.dict(new Map()); // false
|
|
238
|
+
is.dict(null); // false
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### newable
|
|
242
|
+
|
|
243
|
+
Checks if a value is a constructor (can be called with `new`).
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
import is from "@rcompat/is";
|
|
247
|
+
|
|
248
|
+
is.newable(class {}); // true
|
|
249
|
+
is.newable(function() {}); // true
|
|
250
|
+
is.newable(Date); // true
|
|
251
|
+
is.newable(() => {}); // false (arrow functions)
|
|
252
|
+
is.newable({}); // false
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### boolish
|
|
256
|
+
|
|
257
|
+
Checks if a value is the string `"true"` or `"false"`.
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
import is from "@rcompat/is";
|
|
261
|
+
|
|
262
|
+
is.boolish("true"); // true
|
|
263
|
+
is.boolish("false"); // true
|
|
264
|
+
is.boolish(true); // false (not a string)
|
|
265
|
+
is.boolish("yes"); // false
|
|
266
|
+
is.boolish("1"); // false
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## API Reference
|
|
270
|
+
|
|
271
|
+
All functions follow the same pattern:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
declare function is<Name>(value: unknown): value is <Type>;
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
| Function | Type Guard | Description |
|
|
278
|
+
|---------------|---------------------|--------------------------------|
|
|
279
|
+
| `nullish` | `null \| undefined` | `null` or `undefined` |
|
|
280
|
+
| `defined` | `unknown` | not `undefined` |
|
|
281
|
+
| `truthy` | `unknown` | `true` in boolean contexts |
|
|
282
|
+
| `falsy` | `unknown` | `false` in boolean contexts |
|
|
283
|
+
| `empty` | `unknown` | empty collection/string/object |
|
|
284
|
+
| `blank` | `string` | empty/whitespace string |
|
|
285
|
+
| `numeric` | `string` | numeric string |
|
|
286
|
+
| `int` | `number` | integer number |
|
|
287
|
+
| `uint` | `number \| bigint` | unsigned (positive) integer |
|
|
288
|
+
| `safeint` | `number` | safe integer |
|
|
289
|
+
| `finite` | `number \| bigint` | finite number |
|
|
290
|
+
| `nan` | `number` | `NaN` |
|
|
291
|
+
| `primitive` | `Primitive` | primitive type |
|
|
292
|
+
| `dict` | `Dict` | plain object |
|
|
293
|
+
| `newable` | `Newable` | constructor |
|
|
294
|
+
| `boolish` | `"true" \| "false"` | boolean string |
|
|
295
|
+
|
|
296
|
+
## Examples
|
|
297
|
+
|
|
298
|
+
### Filter valid values
|
|
299
|
+
|
|
300
|
+
```js
|
|
301
|
+
import is from "@rcompat/is";
|
|
302
|
+
|
|
303
|
+
const values = [1, null, 2, undefined, 3];
|
|
304
|
+
|
|
305
|
+
values.filter(is.defined); // [1, null, 2, 3]
|
|
306
|
+
values.filter(v => !is.nullish(v)); // [1, 2, 3]
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Parse configuration
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
import is from "@rcompat/is";
|
|
313
|
+
|
|
314
|
+
function parseEnvVar(value) {
|
|
315
|
+
if (is.boolish(value)) return value === "true";
|
|
316
|
+
if (is.numeric(value)) return Number(value);
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
parseEnvVar("true"); // true
|
|
321
|
+
parseEnvVar("42"); // 42
|
|
322
|
+
parseEnvVar("hello"); // "hello"
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Validate input
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
import is from "@rcompat/is";
|
|
329
|
+
|
|
330
|
+
function validateForm(data) {
|
|
331
|
+
const errors = [];
|
|
332
|
+
|
|
333
|
+
if (is.blank(data.name)) {
|
|
334
|
+
errors.push("Name is required");
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!uint(data.age)) {
|
|
338
|
+
errors.push("Age must be a positive integer");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return errors;
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Type-safe guards
|
|
346
|
+
|
|
347
|
+
```js
|
|
348
|
+
import is from "@rcompat/is";
|
|
349
|
+
|
|
350
|
+
function process(value) {
|
|
351
|
+
if (is.primitive(value)) {
|
|
352
|
+
// TypeScript knows: value is:
|
|
353
|
+
// string | number | boolean | bigint | symbol | null | undefined
|
|
354
|
+
return String(value);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (is.dict(value)) {
|
|
358
|
+
// TypeScript knows: value is Record<string, unknown>
|
|
359
|
+
return JSON.stringify(value);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return "[complex object]";
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## Cross-Runtime Compatibility
|
|
367
|
+
|
|
368
|
+
| Runtime | Supported |
|
|
369
|
+
|---------|-----------|
|
|
370
|
+
| Node.js | ✓ |
|
|
371
|
+
| Deno | ✓ |
|
|
372
|
+
| Bun | ✓ |
|
|
373
|
+
|
|
374
|
+
No configuration required — just import and use.
|
|
375
|
+
|
|
376
|
+
## License
|
|
377
|
+
|
|
378
|
+
MIT
|
|
379
|
+
|
|
380
|
+
## Contributing
|
|
381
|
+
|
|
382
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) in the repository root.
|
|
383
|
+
|
package/lib/private/empty.js
CHANGED
|
@@ -5,12 +5,6 @@ export default function isEmpty(x) {
|
|
|
5
5
|
return x.size === 0;
|
|
6
6
|
if (typeof x === "object" && x !== null)
|
|
7
7
|
return Object.keys(x).length === 0;
|
|
8
|
-
if (x && typeof x === "object") {
|
|
9
|
-
const prototype = Object.getPrototypeOf(x);
|
|
10
|
-
if (prototype === Object.prototype || prototype === null) {
|
|
11
|
-
return Object.keys(x).length === 0;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
8
|
return false;
|
|
15
9
|
}
|
|
16
10
|
//# sourceMappingURL=empty.js.map
|
package/lib/private/finite.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export default function isFinite(x) {
|
|
2
|
-
if (typeof x === "bigint")
|
|
2
|
+
if (typeof x === "bigint")
|
|
3
3
|
return true;
|
|
4
|
-
|
|
5
|
-
if (typeof x === "number") {
|
|
4
|
+
if (typeof x === "number")
|
|
6
5
|
return Number.isFinite(x);
|
|
7
|
-
}
|
|
8
6
|
return false;
|
|
9
7
|
}
|
|
10
8
|
//# sourceMappingURL=finite.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import empty from "#empty";
|
|
2
|
+
import newable from "#newable";
|
|
3
|
+
import numeric from "#numeric";
|
|
4
|
+
import object from "#object";
|
|
5
|
+
import primitive from "#primitive";
|
|
6
|
+
import type Dict from "@rcompat/type/Dict";
|
|
7
|
+
import type Nullish from "@rcompat/type/Nullish";
|
|
8
|
+
declare function isDate(x: unknown): x is Date;
|
|
9
|
+
declare function isDefined(x: unknown): x is {} | null;
|
|
10
|
+
declare function isDict(x: unknown): x is Dict;
|
|
11
|
+
declare function isError(x: unknown): x is Error;
|
|
12
|
+
declare function isFalsy(x: unknown): boolean;
|
|
13
|
+
declare function isNullish(x: unknown): x is Nullish;
|
|
14
|
+
declare function isPromise(x: unknown): x is Promise<unknown>;
|
|
15
|
+
declare function isRegExp(x: unknown): x is RegExp;
|
|
16
|
+
declare function isTruthy(x: unknown): boolean;
|
|
17
|
+
declare function isURL(x: unknown): x is URL;
|
|
18
|
+
declare function isMap(x: unknown): x is Map<unknown, unknown>;
|
|
19
|
+
declare function isSet(x: unknown): x is Set<unknown>;
|
|
20
|
+
declare const _default: {
|
|
21
|
+
array: (arg: any) => arg is any[];
|
|
22
|
+
blank: (x: unknown) => x is string;
|
|
23
|
+
boolish: (x: unknown) => x is import("@rcompat/type/Boolish").default;
|
|
24
|
+
date: typeof isDate;
|
|
25
|
+
defined: typeof isDefined;
|
|
26
|
+
dict: typeof isDict;
|
|
27
|
+
empty: typeof empty;
|
|
28
|
+
error: typeof isError;
|
|
29
|
+
falsy: typeof isFalsy;
|
|
30
|
+
finite: (x: unknown) => x is bigint | number;
|
|
31
|
+
int: (x: unknown) => x is bigint | number;
|
|
32
|
+
map: typeof isMap;
|
|
33
|
+
nan: (x: unknown) => x is number;
|
|
34
|
+
newable: typeof newable;
|
|
35
|
+
nullish: typeof isNullish;
|
|
36
|
+
numeric: typeof numeric;
|
|
37
|
+
object: typeof object;
|
|
38
|
+
primitive: typeof primitive;
|
|
39
|
+
promise: typeof isPromise;
|
|
40
|
+
regexp: typeof isRegExp;
|
|
41
|
+
safeint: (x: unknown) => x is number;
|
|
42
|
+
set: typeof isSet;
|
|
43
|
+
truthy: typeof isTruthy;
|
|
44
|
+
uint: (x: unknown) => x is bigint | number;
|
|
45
|
+
url: typeof isURL;
|
|
46
|
+
};
|
|
47
|
+
export default _default;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import empty from "#empty";
|
|
2
|
+
import newable from "#newable";
|
|
3
|
+
import numbers from "#numbers";
|
|
4
|
+
import numeric from "#numeric";
|
|
5
|
+
import object from "#object";
|
|
6
|
+
import primitive from "#primitive";
|
|
7
|
+
import strings from "#strings";
|
|
8
|
+
function isDate(x) {
|
|
9
|
+
return x instanceof Date;
|
|
10
|
+
}
|
|
11
|
+
function isDefined(x) {
|
|
12
|
+
return x !== undefined;
|
|
13
|
+
}
|
|
14
|
+
function isDict(x) {
|
|
15
|
+
if (typeof x !== "object" || x === null)
|
|
16
|
+
return false;
|
|
17
|
+
const prototype = Object.getPrototypeOf(x);
|
|
18
|
+
return prototype === Object.prototype || prototype === null;
|
|
19
|
+
}
|
|
20
|
+
function isError(x) {
|
|
21
|
+
return x instanceof Error;
|
|
22
|
+
}
|
|
23
|
+
function isFalsy(x) {
|
|
24
|
+
return !x;
|
|
25
|
+
}
|
|
26
|
+
function isNullish(x) {
|
|
27
|
+
return x === null || x === undefined;
|
|
28
|
+
}
|
|
29
|
+
function isPromise(x) {
|
|
30
|
+
return x instanceof Promise;
|
|
31
|
+
}
|
|
32
|
+
function isRegExp(x) {
|
|
33
|
+
return x instanceof RegExp;
|
|
34
|
+
}
|
|
35
|
+
function isTruthy(x) {
|
|
36
|
+
return !!x;
|
|
37
|
+
}
|
|
38
|
+
function isURL(x) {
|
|
39
|
+
return x instanceof URL;
|
|
40
|
+
}
|
|
41
|
+
function isMap(x) {
|
|
42
|
+
return x instanceof Map;
|
|
43
|
+
}
|
|
44
|
+
function isSet(x) {
|
|
45
|
+
return x instanceof Set;
|
|
46
|
+
}
|
|
47
|
+
export default {
|
|
48
|
+
array: Array.isArray,
|
|
49
|
+
blank: strings.isBlank,
|
|
50
|
+
boolish: strings.isBoolish,
|
|
51
|
+
date: isDate,
|
|
52
|
+
defined: isDefined,
|
|
53
|
+
dict: isDict,
|
|
54
|
+
empty,
|
|
55
|
+
error: isError,
|
|
56
|
+
falsy: isFalsy,
|
|
57
|
+
finite: numbers.isFinite,
|
|
58
|
+
int: numbers.isInt,
|
|
59
|
+
map: isMap,
|
|
60
|
+
nan: numbers.isNaN,
|
|
61
|
+
newable,
|
|
62
|
+
nullish: isNullish,
|
|
63
|
+
numeric,
|
|
64
|
+
object,
|
|
65
|
+
primitive,
|
|
66
|
+
promise: isPromise,
|
|
67
|
+
regexp: isRegExp,
|
|
68
|
+
safeint: numbers.isSafeint,
|
|
69
|
+
set: isSet,
|
|
70
|
+
truthy: isTruthy,
|
|
71
|
+
uint: numbers.isUint,
|
|
72
|
+
url: isURL,
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare function isFinite(x: unknown): x is bigint | number;
|
|
2
|
+
declare function isInt(x: unknown): x is bigint | number;
|
|
3
|
+
declare function isNaN(x: unknown): x is number;
|
|
4
|
+
declare function isSafeint(x: unknown): x is number;
|
|
5
|
+
declare function isUint(x: unknown): x is bigint | number;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
isFinite: typeof isFinite;
|
|
8
|
+
isInt: typeof isInt;
|
|
9
|
+
isNaN: typeof isNaN;
|
|
10
|
+
isSafeint: typeof isSafeint;
|
|
11
|
+
isUint: typeof isUint;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function isFinite(x) {
|
|
2
|
+
if (typeof x === "bigint")
|
|
3
|
+
return true;
|
|
4
|
+
if (typeof x === "number")
|
|
5
|
+
return Number.isFinite(x);
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
function isInt(x) {
|
|
9
|
+
if (typeof x === "number")
|
|
10
|
+
return Number.isInteger(x);
|
|
11
|
+
if (typeof x === "bigint")
|
|
12
|
+
return true;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
function isNaN(x) {
|
|
16
|
+
return typeof x === "number" && Number.isNaN(x);
|
|
17
|
+
}
|
|
18
|
+
function isSafeint(x) {
|
|
19
|
+
if (typeof x === "number")
|
|
20
|
+
return Number.isSafeInteger(x);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
function isUint(x) {
|
|
24
|
+
if (typeof x === "bigint")
|
|
25
|
+
return x >= 0n;
|
|
26
|
+
if (typeof x === "number")
|
|
27
|
+
return Number.isInteger(x) && x >= 0;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
export default {
|
|
31
|
+
isFinite,
|
|
32
|
+
isInt,
|
|
33
|
+
isNaN,
|
|
34
|
+
isSafeint,
|
|
35
|
+
isUint,
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=numbers.js.map
|
package/lib/private/numeric.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
const DECIMAL = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
2
2
|
export default function isNumeric(x) {
|
|
3
|
-
if (typeof x !== "string")
|
|
3
|
+
if (typeof x !== "string")
|
|
4
4
|
return false;
|
|
5
|
-
}
|
|
6
5
|
const trimmed = x.trim();
|
|
7
|
-
if (trimmed === "")
|
|
6
|
+
if (trimmed === "")
|
|
8
7
|
return false;
|
|
9
|
-
}
|
|
10
8
|
return DECIMAL.test(trimmed);
|
|
11
9
|
}
|
|
12
10
|
//# sourceMappingURL=numeric.js.map
|
package/lib/private/primitive.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type Boolish from "@rcompat/type/Boolish";
|
|
2
|
+
declare function isBlank(x: unknown): x is string;
|
|
3
|
+
declare function isBoolish(x: unknown): x is Boolish;
|
|
4
|
+
declare const _default: {
|
|
5
|
+
isBlank: typeof isBlank;
|
|
6
|
+
isBoolish: typeof isBoolish;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=strings.d.ts.map
|
package/lib/private/uint.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rcompat/is",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Standard library
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Standard library identity checks",
|
|
5
5
|
"bugs": "https://github.com/rcompat/rcompat/issues",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
|
-
"
|
|
26
|
-
"apekit": "./src/public
|
|
27
|
-
"default": "./lib/public
|
|
25
|
+
".": {
|
|
26
|
+
"apekit": "./src/public/index.ts",
|
|
27
|
+
"default": "./lib/public/index.js"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
package/lib/private/integer.d.ts
DELETED
package/lib/public/blank.d.ts
DELETED
package/lib/public/blank.js
DELETED
package/lib/public/boolish.d.ts
DELETED
package/lib/public/boolish.js
DELETED
package/lib/public/defined.d.ts
DELETED
package/lib/public/defined.js
DELETED
package/lib/public/empty.d.ts
DELETED
package/lib/public/empty.js
DELETED
package/lib/public/falsy.d.ts
DELETED
package/lib/public/falsy.js
DELETED
package/lib/public/finite.d.ts
DELETED
package/lib/public/finite.js
DELETED
package/lib/public/integer.d.ts
DELETED
package/lib/public/integer.js
DELETED
package/lib/public/nan.d.ts
DELETED
package/lib/public/nan.js
DELETED
package/lib/public/newable.d.ts
DELETED
package/lib/public/newable.js
DELETED
package/lib/public/nullish.d.ts
DELETED
package/lib/public/nullish.js
DELETED
package/lib/public/numeric.d.ts
DELETED
package/lib/public/numeric.js
DELETED
package/lib/public/primitive.js
DELETED
package/lib/public/truthy.d.ts
DELETED
package/lib/public/truthy.js
DELETED
package/lib/public/uint.d.ts
DELETED
package/lib/public/uint.js
DELETED