Micro check library providing comprehensive type checking and validation operations across different JavaScript environments
npx @tessl/cli install tessl/npm-is-js@0.9.00
# is.js
1
2
is.js is a comprehensive micro check library for JavaScript that provides type checking and validation operations across different JavaScript environments. It offers a wide range of utility functions for checking data types, values, and conditions with support for AMD, Node.js, and browser environments through a universal module definition pattern.
3
4
## Package Information
5
6
- **Package Name**: is_js
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install is_js`
10
11
## Core Imports
12
13
```javascript
14
const is = require('is_js');
15
```
16
17
For AMD:
18
19
```javascript
20
define(['is_js'], function(is) {
21
// Use is object
22
});
23
```
24
25
For browsers (global):
26
27
```html
28
<script src="is.js"></script>
29
<script>
30
// is is available globally
31
</script>
32
```
33
34
## Basic Usage
35
36
```javascript
37
const is = require('is_js');
38
39
// Basic type checking
40
console.log(is.string('hello')); // true
41
console.log(is.number(42)); // true
42
console.log(is.array([1, 2, 3])); // true
43
44
// Using modifiers
45
console.log(is.not.string(123)); // true
46
console.log(is.all.number(1, 2, 3)); // true
47
console.log(is.any.string('a', 123)); // true
48
49
// Complex validation
50
console.log(is.email('test@example.com')); // true
51
console.log(is.url('https://example.com')); // true
52
console.log(is.even(4)); // true
53
```
54
55
## Architecture
56
57
is.js is built around several key components:
58
59
- **Core Interface**: Main `is` object containing all checking functions
60
- **Modifier System**: `not`, `all`, and `any` interfaces providing function variants
61
- **Universal Module**: UMD pattern supporting AMD, CommonJS, and browser globals
62
- **Fluent API**: Consistent boolean return values across all checking functions
63
- **Environment Detection**: Browser and device-specific checks available in browser contexts
64
65
## Capabilities
66
67
### Type Checking
68
69
Core type validation functions for JavaScript primitives and objects. Essential for runtime type safety and input validation.
70
71
```javascript { .api }
72
// Basic type checks
73
function arguments(value: any): boolean;
74
function array(value: any): boolean;
75
function boolean(value: any): boolean;
76
function date(value: any): boolean;
77
function error(value: any): boolean;
78
function function(value: any): boolean;
79
function number(value: any): boolean;
80
function object(value: any): boolean;
81
function regexp(value: any): boolean;
82
function string(value: any): boolean;
83
84
// Special type checks
85
function char(value: any): boolean;
86
function domNode(value: any): boolean;
87
function json(value: any): boolean;
88
function nan(value: any): boolean;
89
function null(value: any): boolean;
90
function sameType(value: any, other: any): boolean;
91
function undefined(value: any): boolean;
92
function windowObject(value: any): boolean;
93
```
94
95
[Type Checking](./type-checking.md)
96
97
### Value Presence and State
98
99
Functions for checking value existence, truthiness, and basic state validation.
100
101
```javascript { .api }
102
function empty(value: any): boolean;
103
function existy(value: any): boolean;
104
function falsy(value: any): boolean;
105
function truthy(value: any): boolean;
106
function space(value: any): boolean;
107
```
108
109
[Presence Checking](./presence-checking.md)
110
111
### String Validation
112
113
String-specific validation including case checking, content analysis, and format validation.
114
115
```javascript { .api }
116
function capitalized(value: string): boolean;
117
function endWith(string: string, target: string): boolean;
118
function include(string: string, target: string): boolean;
119
function lowerCase(value: string): boolean;
120
function palindrome(value: string): boolean;
121
function startWith(string: string, target: string): boolean;
122
function upperCase(value: string): boolean;
123
```
124
125
[String Checking](./string-checking.md)
126
127
### Pattern Matching
128
129
Regular expression-based validation for common data formats including emails, URLs, phone numbers, and postal codes.
130
131
```javascript { .api }
132
function affirmative(value: any): boolean;
133
function alphaNumeric(value: any): boolean;
134
function caPostalCode(value: any): boolean;
135
function creditCard(value: any): boolean;
136
function dateString(value: any): boolean;
137
function email(value: any): boolean;
138
function hexadecimal(value: any): boolean;
139
function hexColor(value: any): boolean;
140
function ip(value: any): boolean;
141
function ipv4(value: any): boolean;
142
function ipv6(value: any): boolean;
143
function nanpPhone(value: any): boolean;
144
function socialSecurityNumber(value: any): boolean;
145
function timeString(value: any): boolean;
146
function ukPostCode(value: any): boolean;
147
function url(value: any): boolean;
148
function usZipCode(value: any): boolean;
149
```
150
151
[Pattern Matching](./pattern-matching.md)
152
153
### Numeric Operations
154
155
Mathematical validation functions for number properties, comparisons, and arithmetic checks.
156
157
```javascript { .api }
158
function above(n: number, min: number): boolean;
159
function decimal(n: number): boolean;
160
function equal(value: any, other: any): boolean;
161
function even(n: number): boolean;
162
function finite(n: number): boolean;
163
function infinite(n: number): boolean;
164
function integer(n: number): boolean;
165
function negative(n: number): boolean;
166
function odd(n: number): boolean;
167
function positive(n: number): boolean;
168
function under(n: number, max: number): boolean;
169
function within(n: number, min: number, max: number): boolean;
170
```
171
172
[Numeric Operations](./numeric-operations.md)
173
174
### Collection Validation
175
176
Functions for validating arrays, objects, and their properties.
177
178
```javascript { .api }
179
function inArray(value: any, array: any[]): boolean;
180
function sorted(array: any[], sign?: string): boolean;
181
function propertyCount(object: any, count: number): boolean;
182
function propertyDefined(object: any, property: string): boolean;
183
```
184
185
[Collection Validation](./collection-validation.md)
186
187
### Date and Time
188
189
Comprehensive date validation including relative time checks, specific date matching, and time range validation.
190
191
```javascript { .api }
192
function day(date: Date, day: string): boolean;
193
function dayLightSavingTime(date: Date): boolean;
194
function future(date: Date): boolean;
195
function inDateRange(date: Date, start: Date, end: Date): boolean;
196
function leapYear(year: number): boolean;
197
function month(date: Date, month: string): boolean;
198
function past(date: Date): boolean;
199
function quarterOfYear(date: Date, quarter: number): boolean;
200
function today(date: Date): boolean;
201
function tomorrow(date: Date): boolean;
202
function weekend(date: Date): boolean;
203
function weekday(date: Date): boolean;
204
function year(date: Date, year: number): boolean;
205
function yesterday(date: Date): boolean;
206
```
207
208
[Date and Time](./date-time.md)
209
210
### Environment Detection
211
212
Browser and device detection functions for responsive behavior and feature detection.
213
214
```javascript { .api }
215
// Browser detection
216
function chrome(range?: string | number): boolean;
217
function edge(range?: string | number): boolean;
218
function firefox(range?: string | number): boolean;
219
function ie(range?: string | number): boolean;
220
function opera(range?: string | number): boolean;
221
function safari(range?: string | number): boolean;
222
223
// Device detection
224
function android(): boolean;
225
function ios(): boolean;
226
function mobile(): boolean;
227
function tablet(): boolean;
228
function desktop(): boolean;
229
230
// Operating system detection
231
function linux(): boolean;
232
function mac(): boolean;
233
function windows(): boolean;
234
```
235
236
[Environment Detection](./environment-detection.md)
237
238
### Configuration and Utilities
239
240
Library configuration and utility functions for customization and namespace management.
241
242
```javascript { .api }
243
function setNamespace(): typeof is;
244
function setRegexp(regexp: RegExp, name: string): void;
245
```
246
247
[Configuration](./configuration.md)
248
249
## Interface Modifiers
250
251
### not Interface
252
253
All functions are available with negated logic through the `not` interface:
254
255
```javascript { .api }
256
interface NotInterface {
257
[K in keyof IsInterface]: IsInterface[K];
258
}
259
260
const not: NotInterface;
261
```
262
263
### all Interface
264
265
Functions supporting the `all` interface check that all provided arguments pass the test:
266
267
```javascript { .api }
268
interface AllInterface {
269
[K in SupportedFunction]: (...args: any[]) => boolean;
270
}
271
272
const all: AllInterface;
273
```
274
275
### any Interface
276
277
Functions supporting the `any` interface check that at least one provided argument passes the test:
278
279
```javascript { .api }
280
interface AnyInterface {
281
[K in SupportedFunction]: (...args: any[]) => boolean;
282
}
283
284
const any: AnyInterface;
285
```
286
287
## Types
288
289
```javascript { .api }
290
interface IsInterface {
291
VERSION: string; // '0.8.0' as defined in source code
292
not: NotInterface;
293
all: AllInterface;
294
any: AnyInterface;
295
296
// All checking functions return boolean
297
[functionName: string]: (...args: any[]) => boolean;
298
}
299
300
// Main export
301
const is: IsInterface;
302
```