vest 3.2.4-dev-c9788a → 3.2.7
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 +115 -0
- package/any.d.ts +3 -0
- package/any.js +1 -0
- package/classNames.d.ts +14 -0
- package/classNames.js +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +115 -0
- package/docs/_assets/favicon.ico +0 -0
- package/docs/_assets/vest-logo.png +0 -0
- package/docs/_sidebar.md +19 -0
- package/docs/_sidebar.md.bak +14 -0
- package/docs/cross_field_validations.md +79 -0
- package/docs/enforce.md +18 -0
- package/docs/enforce.md.bak +13 -0
- package/docs/exclusion.md +128 -0
- package/docs/getting_started.md +79 -0
- package/docs/group.md +142 -0
- package/docs/index.html +41 -0
- package/docs/migration.md +107 -0
- package/docs/n4s/compound.md +187 -0
- package/docs/n4s/custom.md +52 -0
- package/docs/n4s/external.md +54 -0
- package/docs/n4s/rules.md +1282 -0
- package/docs/n4s/template.md +53 -0
- package/docs/node.md +43 -0
- package/docs/optional.md +51 -0
- package/docs/result.md +238 -0
- package/docs/state.md +102 -0
- package/docs/test.md +172 -0
- package/docs/utilities.md +105 -0
- package/docs/warn.md +82 -0
- package/enforce.d.ts +230 -0
- package/esm/package.json +1 -0
- package/esm/vest.es.development.js +2493 -0
- package/esm/vest.es.production.js +2490 -0
- package/esm/vest.es.production.min.js +1 -0
- package/package.json +65 -12
- package/promisify.d.ts +7 -0
- package/{dist/umd/promisify.production.js → promisify.js} +1 -1
- package/schema.d.ts +26 -0
- package/schema.js +1 -0
- package/vest.cjs.development.js +2494 -0
- package/vest.cjs.production.js +2491 -0
- package/vest.cjs.production.min.js +1 -0
- package/vest.d.ts +249 -0
- package/vest.js +7 -0
- package/vest.umd.development.js +2711 -0
- package/vest.umd.production.js +2708 -0
- package/vest.umd.production.min.js +1 -0
- package/vestResult.d.ts +105 -0
- package/CHANGELOG.md +0 -52
- package/LICENSE +0 -21
- package/dist/cjs/classnames.development.js +0 -67
- package/dist/cjs/classnames.production.js +0 -1
- package/dist/cjs/promisify.development.js +0 -20
- package/dist/cjs/promisify.production.js +0 -1
- package/dist/cjs/vest.development.js +0 -1616
- package/dist/cjs/vest.production.js +0 -1
- package/dist/es/classnames.development.js +0 -65
- package/dist/es/classnames.production.js +0 -1
- package/dist/es/promisify.development.js +0 -18
- package/dist/es/promisify.production.js +0 -1
- package/dist/es/vest.development.js +0 -1604
- package/dist/es/vest.production.js +0 -1
- package/dist/umd/classnames.development.js +0 -73
- package/dist/umd/classnames.production.js +0 -1
- package/dist/umd/promisify.development.js +0 -26
- package/dist/umd/vest.development.js +0 -1622
- package/dist/umd/vest.production.js +0 -1
- package/index.js +0 -7
|
@@ -0,0 +1,1282 @@
|
|
|
1
|
+
# List of Enforce rules
|
|
2
|
+
|
|
3
|
+
Enforce rules are functions that allow you to test your data against different criteria. The following rules are supported out-of-the-box.
|
|
4
|
+
|
|
5
|
+
- [equals](#equals)
|
|
6
|
+
- [notEquals](#notequals)
|
|
7
|
+
- [isEmpty](#isempty)
|
|
8
|
+
- [isNotEmpty](#isnotempty)
|
|
9
|
+
- [isNumeric](#isnumeric)
|
|
10
|
+
- [isNotNumeric](#isnotnumeric)
|
|
11
|
+
- [greaterThan](#greaterthan)
|
|
12
|
+
- [greaterThanOrEquals](#greaterthanorequals)
|
|
13
|
+
- [lengthEquals](#lengthequals)
|
|
14
|
+
- [lengthNotEquals](#lengthnotequals)
|
|
15
|
+
- [lessThan](#lessthan)
|
|
16
|
+
- [lessThanOrEquals](#lessthanorequals)
|
|
17
|
+
- [longerThan](#longerthan)
|
|
18
|
+
- [longerThanOrEquals](#longerthanorequals)
|
|
19
|
+
- [numberEquals](#numberequals)
|
|
20
|
+
- [numberNotEquals](#numbernotequals)
|
|
21
|
+
- [shorterThan](#shorterthan)
|
|
22
|
+
- [shorterThanOrEquals](#shorterthanorequals)
|
|
23
|
+
- [matches](#matches)
|
|
24
|
+
- [notMatches](#notmatches)
|
|
25
|
+
- [inside](#inside)
|
|
26
|
+
- [notInside](#notinside)
|
|
27
|
+
- [isTruthy](#istruthy)
|
|
28
|
+
- [isFalsy](#isfalsy)
|
|
29
|
+
- [isArray](#isarray)
|
|
30
|
+
- [isNotArray](#isnotarray)
|
|
31
|
+
- [isBoolean](#isboolean)
|
|
32
|
+
- [isNotBoolean](#isnotboolean)
|
|
33
|
+
- [isBlank](#isblank)
|
|
34
|
+
- [isNotBlank](#isnotblank)
|
|
35
|
+
- [isNumber](#isnumber)
|
|
36
|
+
- [isNotNumber](#isnotnumber)
|
|
37
|
+
- [isNaN](#isNaN)
|
|
38
|
+
- [isNotNaN](#isNotNaN)
|
|
39
|
+
- [isNull](#isnull)
|
|
40
|
+
- [isNotNull](#isnotnull)
|
|
41
|
+
- [isString](#isstring)
|
|
42
|
+
- [isNotString](#isnotstring)
|
|
43
|
+
- [isUndefined](#isundefined)
|
|
44
|
+
- [isOdd](#isodd)
|
|
45
|
+
- [isEven](#iseven)
|
|
46
|
+
- [isBetween](#isbetween)
|
|
47
|
+
- [isNotBetween](#isnotbetween)
|
|
48
|
+
- [endsWith](#endswith)
|
|
49
|
+
- [doesNotEndWith](#doesnotendwith)
|
|
50
|
+
- [startsWith](#startsWith)
|
|
51
|
+
- [doesNotStartWith](#doesnotstartwith)
|
|
52
|
+
- [isNegative](#isnegative)
|
|
53
|
+
- [isPositive](#ispositive)
|
|
54
|
+
|
|
55
|
+
## equals
|
|
56
|
+
|
|
57
|
+
### Description
|
|
58
|
+
|
|
59
|
+
Checks if your enforced value <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Strict_equality_using" target="_blank">strictly equals</a> (`===`) another.
|
|
60
|
+
|
|
61
|
+
It is not recommended to use this rule to compare arrays or objects, as it does not perform any sort of deep comparison on the value.
|
|
62
|
+
|
|
63
|
+
For numeric value comparison, you should use `numberEquals`, which coerces numeric strings into numbers before comparing.
|
|
64
|
+
|
|
65
|
+
### Arguments
|
|
66
|
+
|
|
67
|
+
- `value`: Any value you wish to check your enforced value against
|
|
68
|
+
|
|
69
|
+
### Usage examples:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
enforce(1).equals(1);
|
|
73
|
+
|
|
74
|
+
enforce('hello').equals('hello');
|
|
75
|
+
|
|
76
|
+
const a = [1, 2, 3];
|
|
77
|
+
|
|
78
|
+
enforce(a).equals(a);
|
|
79
|
+
// passes
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
enforce('1').equals(1);
|
|
84
|
+
enforce([1, 2, 3]).equals([1, 2, 3]);
|
|
85
|
+
// throws
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## notEquals
|
|
89
|
+
|
|
90
|
+
### Description
|
|
91
|
+
|
|
92
|
+
Checks if your enforced value does not <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Strict_equality_using" target="_blank">strictly equal</a> (`===`) another.
|
|
93
|
+
|
|
94
|
+
Reverse implementation of `equals`.
|
|
95
|
+
|
|
96
|
+
### Usage examples:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
enforce('1').notEquals(1);
|
|
100
|
+
enforce([1, 2, 3]).notEquals([1, 2, 3]);
|
|
101
|
+
// passes
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
enforce(1).notEquals(1);
|
|
106
|
+
enforce('hello').notEquals('hello');
|
|
107
|
+
|
|
108
|
+
const a = [1, 2, 3];
|
|
109
|
+
|
|
110
|
+
enforce(a).notEquals(a);
|
|
111
|
+
// throws
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## isEmpty
|
|
115
|
+
|
|
116
|
+
### Description
|
|
117
|
+
|
|
118
|
+
Checks if your enforced value is empty, false, zero, null or undefined.
|
|
119
|
+
|
|
120
|
+
Expected results are:
|
|
121
|
+
|
|
122
|
+
- object: checks against the count of keys (`0` is empty)
|
|
123
|
+
- array/string: checks against length. (`0` is empty)
|
|
124
|
+
- number: checks the value of the number. (`0` and `NaN` are empty)
|
|
125
|
+
- boolean: `false` is empty.
|
|
126
|
+
- undefined/null: are both empty.
|
|
127
|
+
|
|
128
|
+
### Usage examples:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
enforce([]).isEmpty();
|
|
132
|
+
enforce('').isEmpty();
|
|
133
|
+
enforce({}).isEmpty();
|
|
134
|
+
enforce(0).isEmpty();
|
|
135
|
+
enforce(NaN).isEmpty();
|
|
136
|
+
enforce(undefined).isEmpty();
|
|
137
|
+
enforce(null).isEmpty();
|
|
138
|
+
enforce(false).isEmpty();
|
|
139
|
+
// passes
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
enforce([1]).isEmpty();
|
|
144
|
+
enforce('1').isEmpty();
|
|
145
|
+
enforce({ 1: 1 }).isEmpty();
|
|
146
|
+
enforce(1).isEmpty();
|
|
147
|
+
enforce(true).isEmpty();
|
|
148
|
+
// throws
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## isNotEmpty
|
|
152
|
+
|
|
153
|
+
### Description
|
|
154
|
+
|
|
155
|
+
Checks that your enforced value is not empty, false, or zero.
|
|
156
|
+
Reverse implementation of `isEmpty`.
|
|
157
|
+
|
|
158
|
+
### Usage examples:
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
enforce([1]).isNotEmpty();
|
|
162
|
+
enforce('1').isNotEmpty();
|
|
163
|
+
enforce({ 1: 1 }).isNotEmpty();
|
|
164
|
+
// passes
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
enforce([]).isNotEmpty();
|
|
169
|
+
enforce('').isNotEmpty();
|
|
170
|
+
enforce({}).isNotEmpty();
|
|
171
|
+
enforce(0).isNotEmpty();
|
|
172
|
+
// throws
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## isNumeric
|
|
176
|
+
|
|
177
|
+
### Description
|
|
178
|
+
|
|
179
|
+
Checks if a value is a representation of a real number
|
|
180
|
+
|
|
181
|
+
### Usage examples:
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
enforce(143).isNumeric();
|
|
185
|
+
enforce('143').isNumeric();
|
|
186
|
+
// passes
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
enforce(NaN).isNumeric();
|
|
191
|
+
enforce('1hello').isNumeric();
|
|
192
|
+
enforce('hi').isNumeric();
|
|
193
|
+
// throws
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## isNotNumeric
|
|
197
|
+
|
|
198
|
+
### Description
|
|
199
|
+
|
|
200
|
+
Checks if a value is not a representation of a real number.
|
|
201
|
+
Reverse implementation of `isNumeric`.
|
|
202
|
+
|
|
203
|
+
### Usage examples:
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
enforce(NaN).isNotNumeric();
|
|
207
|
+
enforce('Hello World!').isNotNumeric();
|
|
208
|
+
// passes
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
enforce(731).isNotNumeric();
|
|
213
|
+
enforce('42').isNotNumeric();
|
|
214
|
+
// throws
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## greaterThan
|
|
218
|
+
|
|
219
|
+
- alias: `gt`
|
|
220
|
+
|
|
221
|
+
### Description
|
|
222
|
+
|
|
223
|
+
Checks that your numeric enforced value is larger than a given numeric value.
|
|
224
|
+
|
|
225
|
+
### Arguments
|
|
226
|
+
|
|
227
|
+
- `value`: `number | string` | A numeric value against which you want to check your enforced value.
|
|
228
|
+
|
|
229
|
+
Strings are parsed using `Number()`, values which are not fully numeric always return false;
|
|
230
|
+
|
|
231
|
+
### Usage
|
|
232
|
+
|
|
233
|
+
```js
|
|
234
|
+
enforce(1).greaterThan(0);
|
|
235
|
+
enforce('10').greaterThan(0);
|
|
236
|
+
enforce(900).gt('100');
|
|
237
|
+
// passes
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
```js
|
|
241
|
+
enforce(100).greaterThan(100);
|
|
242
|
+
enforce('100').greaterThan(110);
|
|
243
|
+
enforce([100]).gt(1);
|
|
244
|
+
// throws
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## greaterThanOrEquals
|
|
248
|
+
|
|
249
|
+
- alias: `gte()`
|
|
250
|
+
|
|
251
|
+
### Description
|
|
252
|
+
|
|
253
|
+
Checks that your numeric enforced value is larger than or equals to a given numeric value.
|
|
254
|
+
|
|
255
|
+
### Arguments
|
|
256
|
+
|
|
257
|
+
- `value`: `number | string` | A numeric value against which you want to check your enforced value.
|
|
258
|
+
|
|
259
|
+
Strings are parsed using `Number()`, values which are not fully numeric always return false;
|
|
260
|
+
|
|
261
|
+
### Usage
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
enforce(1).greaterThanOrEquals(0);
|
|
265
|
+
enforce('10').greaterThanOrEquals(0);
|
|
266
|
+
enforce(900).greaterThanOrEquals('100');
|
|
267
|
+
enforce(100).greaterThanOrEquals('100');
|
|
268
|
+
enforce(900).gte('900');
|
|
269
|
+
enforce('1337').gte(1337);
|
|
270
|
+
// passes
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
```js
|
|
274
|
+
enforce(100).greaterThanOrEquals('120');
|
|
275
|
+
enforce('100').greaterThanOrEquals(110);
|
|
276
|
+
enforce([100]).gte(1);
|
|
277
|
+
// throws
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## lengthEquals
|
|
281
|
+
|
|
282
|
+
### Description
|
|
283
|
+
|
|
284
|
+
Checks that your enforced value is equal to the given number.
|
|
285
|
+
|
|
286
|
+
### Arguments
|
|
287
|
+
|
|
288
|
+
- `size`: `number` | the number which you would like your initial value to be tested against.
|
|
289
|
+
|
|
290
|
+
The `value` argument can be of the following types:
|
|
291
|
+
|
|
292
|
+
- array: checks against length.
|
|
293
|
+
- string: checks against length.
|
|
294
|
+
|
|
295
|
+
### Usage examples:
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
enforce([1]).lengthEquals(1);
|
|
299
|
+
enforce('a').lengthEquals(1);
|
|
300
|
+
// passes
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
enforce([1, 2]).lengthEquals(1);
|
|
305
|
+
enforce('').lengthEquals(1);
|
|
306
|
+
// throws
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## lengthNotEquals
|
|
310
|
+
|
|
311
|
+
### Description
|
|
312
|
+
|
|
313
|
+
Checks that your enforced value is not equal to the given number.
|
|
314
|
+
Reverse implementation of `lengthEquals`.
|
|
315
|
+
|
|
316
|
+
### Arguments
|
|
317
|
+
|
|
318
|
+
- `size`: `number` | the number which you would like your initial value to be tested against.
|
|
319
|
+
|
|
320
|
+
The `value` argument can be of the following types:
|
|
321
|
+
|
|
322
|
+
- array: checks against length.
|
|
323
|
+
- string: checks against length.
|
|
324
|
+
|
|
325
|
+
### Usage examples:
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
enforce([1]).lengthNotEquals(0);
|
|
329
|
+
enforce('a').lengthNotEquals(3);
|
|
330
|
+
// passes
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
```js
|
|
334
|
+
enforce([1]).lengthNotEquals(1);
|
|
335
|
+
enforce('').lengthNotEquals(0);
|
|
336
|
+
// throws
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## lessThan
|
|
340
|
+
|
|
341
|
+
- alias: `lt()`
|
|
342
|
+
|
|
343
|
+
### Description
|
|
344
|
+
|
|
345
|
+
Checks that your numeric enforced value is smaller than a given numeric value.
|
|
346
|
+
|
|
347
|
+
### Arguments
|
|
348
|
+
|
|
349
|
+
- `value`: `number | string` | A numeric value against which you want to check your enforced value.
|
|
350
|
+
|
|
351
|
+
Strings are parsed using `Number()`, values which are not fully numeric always return false;
|
|
352
|
+
|
|
353
|
+
### Usage
|
|
354
|
+
|
|
355
|
+
```js
|
|
356
|
+
enforce(0).lessThan(1);
|
|
357
|
+
enforce(2).lessThan('10');
|
|
358
|
+
enforce('90').lt(100);
|
|
359
|
+
// passes
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
```js
|
|
363
|
+
enforce(100).lessThan(100);
|
|
364
|
+
enforce('110').lessThan(100);
|
|
365
|
+
enforce([0]).lt(1);
|
|
366
|
+
// throws
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## lessThanOrEquals
|
|
370
|
+
|
|
371
|
+
- alias: `lte()`
|
|
372
|
+
|
|
373
|
+
### Description
|
|
374
|
+
|
|
375
|
+
Checks that your numeric enforced value is smaller than or equals to a given numeric value.
|
|
376
|
+
|
|
377
|
+
### Arguments
|
|
378
|
+
|
|
379
|
+
- `value`: `number | string` | A numeric value against which you want to check your enforced value.
|
|
380
|
+
|
|
381
|
+
Strings are parsed using `Number()`, values which are not fully numeric always return false;
|
|
382
|
+
|
|
383
|
+
### Usage
|
|
384
|
+
|
|
385
|
+
```js
|
|
386
|
+
enforce(0).lessThanOrEquals(1);
|
|
387
|
+
enforce(2).lessThanOrEquals('10');
|
|
388
|
+
enforce('90').lte(100);
|
|
389
|
+
enforce(100).lte('100');
|
|
390
|
+
// passes
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
```js
|
|
394
|
+
enforce(100).lessThanOrEquals(90);
|
|
395
|
+
enforce('110').lessThanOrEquals(100);
|
|
396
|
+
enforce([0]).lte(1);
|
|
397
|
+
// throws
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
## longerThan
|
|
401
|
+
|
|
402
|
+
### Description
|
|
403
|
+
|
|
404
|
+
Checks that your enforced value is longer than a given number.
|
|
405
|
+
|
|
406
|
+
### Arguments
|
|
407
|
+
|
|
408
|
+
- `size`: `number` | the number which you would like your initial value to be tested against.
|
|
409
|
+
|
|
410
|
+
The `value` argument can be of the following types:
|
|
411
|
+
|
|
412
|
+
- array: checks against length.
|
|
413
|
+
- string: checks against length.
|
|
414
|
+
|
|
415
|
+
### Usage examples:
|
|
416
|
+
|
|
417
|
+
```js
|
|
418
|
+
enforce([1]).longerThan(0);
|
|
419
|
+
enforce('ab').longerThan(1);
|
|
420
|
+
// passes
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
```js
|
|
424
|
+
enforce([1]).longerThan(2);
|
|
425
|
+
enforce('').longerThan(0);
|
|
426
|
+
// throws
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## longerThanOrEquals
|
|
430
|
+
|
|
431
|
+
### Description
|
|
432
|
+
|
|
433
|
+
Checks that your enforced value is longer than or equals to a given number.
|
|
434
|
+
|
|
435
|
+
### Arguments
|
|
436
|
+
|
|
437
|
+
- `size`: `number` | the number which you would like your initial value to be tested against.
|
|
438
|
+
|
|
439
|
+
The `value` argument can be of the following types:
|
|
440
|
+
|
|
441
|
+
- array: checks against length.
|
|
442
|
+
- string: checks against length.
|
|
443
|
+
|
|
444
|
+
### Usage examples:
|
|
445
|
+
|
|
446
|
+
```js
|
|
447
|
+
enforce([1]).longerThanOrEquals(0);
|
|
448
|
+
enforce('ab').longerThanOrEquals(1);
|
|
449
|
+
enforce([1]).longerThanOrEquals(1);
|
|
450
|
+
enforce('a').longerThanOrEquals(1);
|
|
451
|
+
// passes
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
```js
|
|
455
|
+
enforce([1]).longerThanOrEquals(2);
|
|
456
|
+
enforce('').longerThanOrEquals(1);
|
|
457
|
+
// throws
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## numberEquals
|
|
461
|
+
|
|
462
|
+
### Description
|
|
463
|
+
|
|
464
|
+
Checks that your numeric enforced value is equals another value.
|
|
465
|
+
|
|
466
|
+
### Arguments
|
|
467
|
+
|
|
468
|
+
- `value`: `number | string` | A numeric value against which you want to check your enforced value.
|
|
469
|
+
|
|
470
|
+
Strings are parsed using `Number()`, values which are not fully numeric always return false;
|
|
471
|
+
|
|
472
|
+
### Usage
|
|
473
|
+
|
|
474
|
+
```js
|
|
475
|
+
enforce(0).numberEquals(0);
|
|
476
|
+
enforce(2).numberEquals('2');
|
|
477
|
+
// passes
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
```js
|
|
481
|
+
enforce(100).numberEquals(10);
|
|
482
|
+
enforce('110').numberEquals(100);
|
|
483
|
+
enforce([0]).numberEquals(1);
|
|
484
|
+
// throws
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
## numberNotEquals
|
|
488
|
+
|
|
489
|
+
### Description
|
|
490
|
+
|
|
491
|
+
Checks that your numeric enforced value does not equal another value.
|
|
492
|
+
Reverse implementation of `numberEquals`.
|
|
493
|
+
|
|
494
|
+
### Arguments
|
|
495
|
+
|
|
496
|
+
- `value`: `number | string` | A numeric value against which you want to check your enforced value.
|
|
497
|
+
|
|
498
|
+
Strings are parsed using `Number()`, values which are not fully numeric always return false;
|
|
499
|
+
|
|
500
|
+
### Usage
|
|
501
|
+
|
|
502
|
+
```js
|
|
503
|
+
enforce(2).numberNotEquals(0);
|
|
504
|
+
enforce('11').numberNotEquals('10');
|
|
505
|
+
// passes
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
```js
|
|
509
|
+
enforce(100).numberNotEquals(100);
|
|
510
|
+
enforce('110').numberNotEquals(100);
|
|
511
|
+
// throws
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
## shorterThan
|
|
515
|
+
|
|
516
|
+
### Description
|
|
517
|
+
|
|
518
|
+
Checks that your enforced value is shorter than a given number.
|
|
519
|
+
|
|
520
|
+
### Arguments
|
|
521
|
+
|
|
522
|
+
- `size`: `number` | the number which you would like your initial value to be tested against.
|
|
523
|
+
|
|
524
|
+
The `value` argument can be of the following types:
|
|
525
|
+
|
|
526
|
+
- array: checks against length.
|
|
527
|
+
- string: checks against length.
|
|
528
|
+
|
|
529
|
+
### Usage examples:
|
|
530
|
+
|
|
531
|
+
```js
|
|
532
|
+
enforce([]).shorterThan(1);
|
|
533
|
+
enforce('a').shorterThan(2);
|
|
534
|
+
// passes
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
```js
|
|
538
|
+
enforce([1]).shorterThan(0);
|
|
539
|
+
enforce('').shorterThan(0);
|
|
540
|
+
// throws
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
## shorterThanOrEquals
|
|
544
|
+
|
|
545
|
+
### Description
|
|
546
|
+
|
|
547
|
+
Checks that your enforced value is shorter than or equals to a given number.
|
|
548
|
+
|
|
549
|
+
### Arguments
|
|
550
|
+
|
|
551
|
+
- `size`: `number` | the number which you would like your initial value to be tested against.
|
|
552
|
+
|
|
553
|
+
The `value` argument can be of the following types:
|
|
554
|
+
|
|
555
|
+
- array: checks against length.
|
|
556
|
+
- string: checks against length.
|
|
557
|
+
|
|
558
|
+
### Usage examples:
|
|
559
|
+
|
|
560
|
+
#### Passing examples:
|
|
561
|
+
|
|
562
|
+
```js
|
|
563
|
+
enforce([]).shorterThanOrEquals(1);
|
|
564
|
+
enforce('a').shorterThanOrEquals(2);
|
|
565
|
+
enforce([]).shorterThanOrEquals(0);
|
|
566
|
+
enforce('a').shorterThanOrEquals(1);
|
|
567
|
+
// passes
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
```js
|
|
571
|
+
enforce([1]).shorterThanOrEquals(0);
|
|
572
|
+
enforce('ab').shorterThanOrEquals(1);
|
|
573
|
+
// throws
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
## matches
|
|
577
|
+
|
|
578
|
+
### Description
|
|
579
|
+
|
|
580
|
+
Checks if a value contains a regex match.
|
|
581
|
+
|
|
582
|
+
### Arguments
|
|
583
|
+
|
|
584
|
+
- `regexp`: either a `RegExp` object, or a RegExp valid string
|
|
585
|
+
|
|
586
|
+
### Usage examples:
|
|
587
|
+
|
|
588
|
+
```js
|
|
589
|
+
enforce(1984).matches(/[0-9]/);
|
|
590
|
+
enforce(1984).matches('[0-9]');
|
|
591
|
+
enforce('1984').matches(/[0-9]/);
|
|
592
|
+
enforce('1984').matches('[0-9]');
|
|
593
|
+
enforce('198four').matches(/[0-9]/);
|
|
594
|
+
enforce('198four').matches('[0-9]');
|
|
595
|
+
// passes
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
```js
|
|
599
|
+
enforce('ninety eighty four').matches(/[0-9]/);
|
|
600
|
+
enforce('ninety eighty four').matches('[0-9]');
|
|
601
|
+
// throws
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
## notMatches
|
|
605
|
+
|
|
606
|
+
### Description
|
|
607
|
+
|
|
608
|
+
Checks if a value does not contain a regex match.
|
|
609
|
+
Reverse implementation of `matches`.
|
|
610
|
+
|
|
611
|
+
### Usage examples:
|
|
612
|
+
|
|
613
|
+
```js
|
|
614
|
+
enforce(1984).notMatches(/[0-9]/);
|
|
615
|
+
// throws
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
```js
|
|
619
|
+
enforce('ninety eighty four').notMatches('[0-9]');
|
|
620
|
+
// passes
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
## inside
|
|
624
|
+
|
|
625
|
+
### Description
|
|
626
|
+
|
|
627
|
+
Checks if your enforced value is contained in another array or string.
|
|
628
|
+
Your enforced value can be of the following types:
|
|
629
|
+
|
|
630
|
+
- `string`
|
|
631
|
+
- `number`
|
|
632
|
+
- `boolean`
|
|
633
|
+
|
|
634
|
+
### Arguments
|
|
635
|
+
|
|
636
|
+
- `container`: a `string` or an `array` which may contain the value specified.
|
|
637
|
+
|
|
638
|
+
### Usage examples:
|
|
639
|
+
|
|
640
|
+
#### inside: array
|
|
641
|
+
|
|
642
|
+
Checks for membership in an array.
|
|
643
|
+
|
|
644
|
+
- string: checks if a string is an element in an array
|
|
645
|
+
|
|
646
|
+
```js
|
|
647
|
+
enforce('hello').inside(['hello', 'world']);
|
|
648
|
+
// passes
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
```js
|
|
652
|
+
enforce('hello!').inside(['hello', 'world']);
|
|
653
|
+
// throws
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
- number: checks if a number is an element in an array
|
|
657
|
+
|
|
658
|
+
```js
|
|
659
|
+
enforce(1).inside([1, 2]);
|
|
660
|
+
// passes
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
```js
|
|
664
|
+
enforce(3).inside([1, 2]);
|
|
665
|
+
// throws
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
- boolean: checks if a number is an element in an array
|
|
669
|
+
|
|
670
|
+
```js
|
|
671
|
+
enforce(false).inside([true, false]);
|
|
672
|
+
// passes
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
```js
|
|
676
|
+
enforce(true).inside([1, 2, 3]);
|
|
677
|
+
// throws
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
#### inside: string
|
|
681
|
+
|
|
682
|
+
- string: checks if a string is inside another string
|
|
683
|
+
|
|
684
|
+
```js
|
|
685
|
+
enforce('da').inside('tru dat.');
|
|
686
|
+
// passes
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
```js
|
|
690
|
+
enforce('ad').inside('tru dat.');
|
|
691
|
+
// throws
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
## notInside
|
|
695
|
+
|
|
696
|
+
### Description
|
|
697
|
+
|
|
698
|
+
Checks if a given value is not contained in another array or string.
|
|
699
|
+
Reverse implementation of `inside`.
|
|
700
|
+
|
|
701
|
+
### Usage examples:
|
|
702
|
+
|
|
703
|
+
```js
|
|
704
|
+
enforce('ad').notInside('tru dat.');
|
|
705
|
+
enforce('hello!').notInside(['hello', 'world']);
|
|
706
|
+
// passes
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
```js
|
|
710
|
+
enforce('hello').notInside(['hello', 'world']);
|
|
711
|
+
enforce('da').notInside('tru dat.');
|
|
712
|
+
// throws
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
## isTruthy
|
|
716
|
+
|
|
717
|
+
### Description
|
|
718
|
+
|
|
719
|
+
Checks if a value is truthy; Meaning: if it can be coerced into boolean `true`.
|
|
720
|
+
Anything not in the following list is considered to be truthy.
|
|
721
|
+
|
|
722
|
+
- `undefined`
|
|
723
|
+
- `null`
|
|
724
|
+
- `false`
|
|
725
|
+
- `0`
|
|
726
|
+
- `NaN`
|
|
727
|
+
- empty string (`""`)
|
|
728
|
+
|
|
729
|
+
### Usage examples:
|
|
730
|
+
|
|
731
|
+
```js
|
|
732
|
+
enforce('hello').isTruthy();
|
|
733
|
+
enforce(true).isTruthy();
|
|
734
|
+
enforce(1).isTruthy();
|
|
735
|
+
// passes
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
```js
|
|
739
|
+
enforce(false).isTruthy();
|
|
740
|
+
enforce(null).isTruthy();
|
|
741
|
+
enforce(undefined).isTruthy();
|
|
742
|
+
enforce(0).isTruthy();
|
|
743
|
+
enforce(NaN).isTruthy();
|
|
744
|
+
enforce('').isTruthy();
|
|
745
|
+
// throws
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
## isFalsy
|
|
749
|
+
|
|
750
|
+
### Description
|
|
751
|
+
|
|
752
|
+
Checks if a value is falsy; Meaning: if it can be coerced into boolean `false`.
|
|
753
|
+
Reverse implementation of `isTruthy`.
|
|
754
|
+
|
|
755
|
+
Anything not in the following list is considered to be truthy:
|
|
756
|
+
|
|
757
|
+
- `undefined`
|
|
758
|
+
- `null`
|
|
759
|
+
- `false`
|
|
760
|
+
- `0`
|
|
761
|
+
- `NaN`
|
|
762
|
+
- empty string (`""`)
|
|
763
|
+
|
|
764
|
+
### Usage examples:
|
|
765
|
+
|
|
766
|
+
```js
|
|
767
|
+
enforce(false).isFalsy();
|
|
768
|
+
enforce(0).isFalsy();
|
|
769
|
+
enforce(undefined).isFalsy();
|
|
770
|
+
// passes
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
```js
|
|
774
|
+
enforce(1).isFalsy();
|
|
775
|
+
enforce(true).isFalsy();
|
|
776
|
+
enforce('hi').isFalsy();
|
|
777
|
+
// throws
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
## isArray
|
|
781
|
+
|
|
782
|
+
### Description
|
|
783
|
+
|
|
784
|
+
Checks if a value is of type `Array`.
|
|
785
|
+
|
|
786
|
+
### Usage examples:
|
|
787
|
+
|
|
788
|
+
```js
|
|
789
|
+
enforce(['hello']).isArray();
|
|
790
|
+
// passes
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
```js
|
|
794
|
+
enforce('hello').isArray();
|
|
795
|
+
// throws
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
## isNotArray
|
|
799
|
+
|
|
800
|
+
### Description
|
|
801
|
+
|
|
802
|
+
Checks if a value is of any type other than `Array`.
|
|
803
|
+
Reverse implementation of `isArray`.
|
|
804
|
+
|
|
805
|
+
### Usage examples:
|
|
806
|
+
|
|
807
|
+
```js
|
|
808
|
+
enforce(['hello']).isNotArray();
|
|
809
|
+
// throws
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
```js
|
|
813
|
+
enforce('hello').isNotArray();
|
|
814
|
+
// passes
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
## isBoolean
|
|
818
|
+
|
|
819
|
+
### Description
|
|
820
|
+
|
|
821
|
+
Checks if a value is of type `boolean`.
|
|
822
|
+
Equals to `typeof value === 'boolean'`
|
|
823
|
+
|
|
824
|
+
### Usage examples:
|
|
825
|
+
|
|
826
|
+
```js
|
|
827
|
+
enforce(true).isBoolean();
|
|
828
|
+
enforce(false).isBoolean();
|
|
829
|
+
enforce(!!0).isBoolean();
|
|
830
|
+
// passes
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
```js
|
|
834
|
+
enforce([]).isBoolean();
|
|
835
|
+
enforce('143').isBoolean();
|
|
836
|
+
enforce('false').isBoolean();
|
|
837
|
+
// throws
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
## isNotBoolean
|
|
841
|
+
|
|
842
|
+
### Description
|
|
843
|
+
|
|
844
|
+
Checks if a value is of any type other than `boolean`.
|
|
845
|
+
Reverse implementation of `isBoolean`.
|
|
846
|
+
|
|
847
|
+
### Usage examples:
|
|
848
|
+
|
|
849
|
+
```js
|
|
850
|
+
enforce('143').isNotBoolean();
|
|
851
|
+
enforce(143).isNotBoolean();
|
|
852
|
+
// passes
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
```js
|
|
856
|
+
enforce(true).isNotBoolean();
|
|
857
|
+
enforce(false).isNotBoolean();
|
|
858
|
+
// throws
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
## isBlank
|
|
862
|
+
|
|
863
|
+
### Description
|
|
864
|
+
|
|
865
|
+
Determines wheter an enforced string contains only whitespaces
|
|
866
|
+
|
|
867
|
+
### Usage examples:
|
|
868
|
+
|
|
869
|
+
```js
|
|
870
|
+
enforce(' ').isBlank(); // passes
|
|
871
|
+
enforce('not blank').isBlank(); // throws
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
## isNotBlank
|
|
875
|
+
|
|
876
|
+
### Description
|
|
877
|
+
|
|
878
|
+
Determines wheter an enforced string contains at least a non-whitespace character
|
|
879
|
+
|
|
880
|
+
### Usage examples:
|
|
881
|
+
|
|
882
|
+
```js
|
|
883
|
+
enforce('not blank').isNotBlank(); // passes
|
|
884
|
+
enforce(' ').isNotBlank(); // throws
|
|
885
|
+
```
|
|
886
|
+
|
|
887
|
+
## isNumber
|
|
888
|
+
|
|
889
|
+
### Description
|
|
890
|
+
|
|
891
|
+
Checks if a value is of type `number`.
|
|
892
|
+
Equals to `typeof value === 'number'`
|
|
893
|
+
|
|
894
|
+
### Usage examples:
|
|
895
|
+
|
|
896
|
+
```js
|
|
897
|
+
enforce(143).isNumber();
|
|
898
|
+
enforce(NaN).isNumber(); // (NaN is of type 'number!')
|
|
899
|
+
// passes
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
```js
|
|
903
|
+
enforce([]).isNumber();
|
|
904
|
+
enforce('143').isNumber();
|
|
905
|
+
// throws
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
## isNotNumber
|
|
909
|
+
|
|
910
|
+
### Description
|
|
911
|
+
|
|
912
|
+
Checks if a value is of any type other than `number`.
|
|
913
|
+
Reverse implementation of `isNumber`.
|
|
914
|
+
|
|
915
|
+
**note** isNotNumber does not check for `NaN` value. For NaN values, use [isNaN](#isNaN).
|
|
916
|
+
|
|
917
|
+
### Usage examples:
|
|
918
|
+
|
|
919
|
+
```js
|
|
920
|
+
enforce('143').isNotNumber();
|
|
921
|
+
enforce(143).isNotNumber();
|
|
922
|
+
// passes
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
```js
|
|
926
|
+
enforce(143).isNotNumber();
|
|
927
|
+
enforce(NaN).isNotNumber(); // throws (NaN is of type 'number!')
|
|
928
|
+
// throws
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
## isNaN
|
|
932
|
+
|
|
933
|
+
### Description
|
|
934
|
+
|
|
935
|
+
A wrapper around JavaScripts Number.isNaN() function. Checks if a value is NaN.
|
|
936
|
+
|
|
937
|
+
### Usage examples:
|
|
938
|
+
|
|
939
|
+
```js
|
|
940
|
+
enforce(NaN).isNaN();
|
|
941
|
+
enforce('A' / 'B').isNaN();
|
|
942
|
+
// passes
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
```js
|
|
946
|
+
enforce(null * null).isNaN(); // null*null = 0
|
|
947
|
+
enforce(200).isNaN();
|
|
948
|
+
enforce('1984').isNaN();
|
|
949
|
+
// throws
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
## isNotNaN
|
|
953
|
+
|
|
954
|
+
### Description
|
|
955
|
+
|
|
956
|
+
Reverse implementation of `isNaN`. Checks that a value is not NaN.
|
|
957
|
+
|
|
958
|
+
### Usage examples:
|
|
959
|
+
|
|
960
|
+
```js
|
|
961
|
+
enforce(null * null).isNaN(); // null*null = 0
|
|
962
|
+
enforce(200).isNaN();
|
|
963
|
+
enforce('1984').isNaN();
|
|
964
|
+
// passes
|
|
965
|
+
```
|
|
966
|
+
|
|
967
|
+
```js
|
|
968
|
+
enforce(NaN).isNaN();
|
|
969
|
+
enforce('A' / 'B').isNaN();
|
|
970
|
+
// throws
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
## isNull
|
|
974
|
+
|
|
975
|
+
### Description
|
|
976
|
+
|
|
977
|
+
Enforces that a specified value is `null`.
|
|
978
|
+
|
|
979
|
+
### Usage examples:
|
|
980
|
+
|
|
981
|
+
```js
|
|
982
|
+
enforce(null).isNull();
|
|
983
|
+
// passes
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
```js
|
|
987
|
+
enforce(undefined).isNull();
|
|
988
|
+
enforce(true).isNull();
|
|
989
|
+
// throws
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
## isNotNull
|
|
993
|
+
|
|
994
|
+
### Description
|
|
995
|
+
|
|
996
|
+
Reverse implementation of `isNull`. Checks that a value is not null.
|
|
997
|
+
|
|
998
|
+
### Usage examples:
|
|
999
|
+
|
|
1000
|
+
```js
|
|
1001
|
+
enforce('hello').isNull();
|
|
1002
|
+
enforce(200).isNull();
|
|
1003
|
+
// passes
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
```js
|
|
1007
|
+
enforce(null).isNull();
|
|
1008
|
+
// throws
|
|
1009
|
+
```
|
|
1010
|
+
|
|
1011
|
+
## isString
|
|
1012
|
+
|
|
1013
|
+
### Description
|
|
1014
|
+
|
|
1015
|
+
Checks if a value is of type `String`.
|
|
1016
|
+
|
|
1017
|
+
### Usage examples:
|
|
1018
|
+
|
|
1019
|
+
```js
|
|
1020
|
+
enforce('hello').isString();
|
|
1021
|
+
// passes
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
```js
|
|
1025
|
+
enforce(['hello']).isString();
|
|
1026
|
+
enforce(1984).isString();
|
|
1027
|
+
// throws
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
## isNotString
|
|
1031
|
+
|
|
1032
|
+
### Description
|
|
1033
|
+
|
|
1034
|
+
Checks if a value is of any type other than `String`.
|
|
1035
|
+
Reverse implementation of `isString`.
|
|
1036
|
+
|
|
1037
|
+
### Usage examples:
|
|
1038
|
+
|
|
1039
|
+
```js
|
|
1040
|
+
enforce('hello').isNotString();
|
|
1041
|
+
// throws
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
```js
|
|
1045
|
+
enforce(['hello']).isNotString();
|
|
1046
|
+
// passes
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
## isUndefined
|
|
1050
|
+
|
|
1051
|
+
### Description
|
|
1052
|
+
|
|
1053
|
+
Enforces that a given value is (`===`) undefined.
|
|
1054
|
+
|
|
1055
|
+
### Usage examples:
|
|
1056
|
+
|
|
1057
|
+
```js
|
|
1058
|
+
enforce().isUndefined();
|
|
1059
|
+
enforce(undefined).isUndefined();
|
|
1060
|
+
// passes
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
```js
|
|
1064
|
+
enforce(null).isUndefined();
|
|
1065
|
+
enforce(true).isUndefined();
|
|
1066
|
+
// throws
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
## isOdd
|
|
1070
|
+
|
|
1071
|
+
### Description
|
|
1072
|
+
|
|
1073
|
+
Checks if a value is an odd numeric value.
|
|
1074
|
+
|
|
1075
|
+
### Usage examples:
|
|
1076
|
+
|
|
1077
|
+
```js
|
|
1078
|
+
enforce('1').isOdd();
|
|
1079
|
+
enforce(9).isOdd();
|
|
1080
|
+
// passes
|
|
1081
|
+
```
|
|
1082
|
+
|
|
1083
|
+
```js
|
|
1084
|
+
enforce(2).isOdd();
|
|
1085
|
+
enforce('4').isOdd();
|
|
1086
|
+
enforce('1withNumber').isOdd();
|
|
1087
|
+
enforce([1]).isOdd();
|
|
1088
|
+
// throws
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
## isEven
|
|
1092
|
+
|
|
1093
|
+
### Description
|
|
1094
|
+
|
|
1095
|
+
Checks if a value is an even numeric value.
|
|
1096
|
+
|
|
1097
|
+
### Usage examples:
|
|
1098
|
+
|
|
1099
|
+
```js
|
|
1100
|
+
enforce(0).isEven();
|
|
1101
|
+
enforce('2').isEven();
|
|
1102
|
+
// passes
|
|
1103
|
+
```
|
|
1104
|
+
|
|
1105
|
+
```js
|
|
1106
|
+
enforce(1).isEven();
|
|
1107
|
+
enforce('3').isEven();
|
|
1108
|
+
enforce('2withNumber').isEven();
|
|
1109
|
+
enforce([0]).isEven();
|
|
1110
|
+
// throws
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
## isBetween
|
|
1114
|
+
|
|
1115
|
+
### Description
|
|
1116
|
+
|
|
1117
|
+
Checks if a number is in range of two numbers (edges of range included)
|
|
1118
|
+
|
|
1119
|
+
### Usage examples:
|
|
1120
|
+
|
|
1121
|
+
```js
|
|
1122
|
+
enforce(5).isBetween(0, 5);
|
|
1123
|
+
enforce(5).isBetween(0, 10);
|
|
1124
|
+
enforce(-5).isBetween(-10, -1);
|
|
1125
|
+
enforce(-5.5).isBetween(-10, -1);
|
|
1126
|
+
enforce(-5.5).isBetween(-10, -1.1);
|
|
1127
|
+
enforce(-5.5).isBetween(-9.5, -1.1);
|
|
1128
|
+
// passes
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
```js
|
|
1132
|
+
enforce(5).isBetween(0, 2);
|
|
1133
|
+
enforce(-5).isBetween(0, 2);
|
|
1134
|
+
enforce('some_string').isBetween(0, 2);
|
|
1135
|
+
enforce(false).isBetween(0, 2);
|
|
1136
|
+
// throws
|
|
1137
|
+
```
|
|
1138
|
+
|
|
1139
|
+
## isNotBetween
|
|
1140
|
+
|
|
1141
|
+
### Description
|
|
1142
|
+
|
|
1143
|
+
Checks if a number **is not** in range of two numbers (edges of range excluded)
|
|
1144
|
+
|
|
1145
|
+
### Usage examples:
|
|
1146
|
+
|
|
1147
|
+
```js
|
|
1148
|
+
enforce(5).isNotBetween(0, 4);
|
|
1149
|
+
enforce(5).isNotBetween(0, 10);
|
|
1150
|
+
enforce(-5).isNotBetween(-10, -1);
|
|
1151
|
+
enforce(-5.5).isNotBetween(-10, -1);
|
|
1152
|
+
enforce(-5.5).isNotBetween(-10, -1.1);
|
|
1153
|
+
// passes
|
|
1154
|
+
```
|
|
1155
|
+
|
|
1156
|
+
```js
|
|
1157
|
+
enforce(5).isNotBetween(0, 5);
|
|
1158
|
+
enforce(5).isNotBetween(0, 10);
|
|
1159
|
+
enforce(-5).isNotBetween(-10, -1);
|
|
1160
|
+
enforce(-5).isNotBetween(-5, -1);
|
|
1161
|
+
enforce('some_string').isNotBetween(0, 2);
|
|
1162
|
+
enforce(false).isNotBetween(0, 2);
|
|
1163
|
+
// throws
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
## endsWith
|
|
1167
|
+
|
|
1168
|
+
### Description
|
|
1169
|
+
|
|
1170
|
+
Determines whether a string ends with the characters of a specified string.
|
|
1171
|
+
|
|
1172
|
+
### Usage examples:
|
|
1173
|
+
|
|
1174
|
+
```js
|
|
1175
|
+
enforce('aba').endsWith('ba');
|
|
1176
|
+
enforce('some_string').endsWith('_string');
|
|
1177
|
+
enforce('string with spaces').endsWith('ng with spaces');
|
|
1178
|
+
enforce('aaaa ').endsWith(' ');
|
|
1179
|
+
// passes
|
|
1180
|
+
```
|
|
1181
|
+
|
|
1182
|
+
```js
|
|
1183
|
+
enforce('for').endsWith('tor');
|
|
1184
|
+
enforce('aaaab').endsWith('aaaa');
|
|
1185
|
+
enforce('aa').endsWith('aaa');
|
|
1186
|
+
enforce(42).endsWith('b');
|
|
1187
|
+
enforce(42).endsWith(50);
|
|
1188
|
+
enforce(true).endsWith(100);
|
|
1189
|
+
// throws
|
|
1190
|
+
```
|
|
1191
|
+
|
|
1192
|
+
## doesNotEndWith
|
|
1193
|
+
|
|
1194
|
+
### Description
|
|
1195
|
+
|
|
1196
|
+
Determines whether a string does not end with the characters of a specified string.
|
|
1197
|
+
Reverse implementation of `endsWith`.
|
|
1198
|
+
|
|
1199
|
+
## startsWith
|
|
1200
|
+
|
|
1201
|
+
### Description
|
|
1202
|
+
|
|
1203
|
+
Determines whether a string starts with the characters of a specified string.
|
|
1204
|
+
|
|
1205
|
+
### Usage examples:
|
|
1206
|
+
|
|
1207
|
+
```js
|
|
1208
|
+
enforce('aba').startsWith('ab');
|
|
1209
|
+
enforce('some_string').startsWith('some_');
|
|
1210
|
+
enforce('string with spaces').startsWith('string with s');
|
|
1211
|
+
enforce('aaaa ').startsWith('aaaa ');
|
|
1212
|
+
// passes
|
|
1213
|
+
```
|
|
1214
|
+
|
|
1215
|
+
```js
|
|
1216
|
+
enforce('for').startsWith('tor');
|
|
1217
|
+
enforce('aaaab').startsWith('aab');
|
|
1218
|
+
enforce('aa').startsWith('aaa');
|
|
1219
|
+
enforce(42).startsWith('b');
|
|
1220
|
+
enforce(42).startsWith(50);
|
|
1221
|
+
enforce(true).startsWith(100);
|
|
1222
|
+
// throws
|
|
1223
|
+
```
|
|
1224
|
+
|
|
1225
|
+
## doesNotStartWith
|
|
1226
|
+
|
|
1227
|
+
### Description
|
|
1228
|
+
|
|
1229
|
+
Determines whether a string does not start with the characters of a specified string.
|
|
1230
|
+
Reverse implementation of `startsWith`.
|
|
1231
|
+
|
|
1232
|
+
### Usage examples:
|
|
1233
|
+
|
|
1234
|
+
```js
|
|
1235
|
+
enforce('for').doesNotStartWith('tor');
|
|
1236
|
+
enforce('aaaab').doesNotStartWith('aab');
|
|
1237
|
+
enforce('aa').doesNotStartWith('aaa');
|
|
1238
|
+
enforce(42).doesNotStartWith('b');
|
|
1239
|
+
enforce(42).doesNotStartWith(50);
|
|
1240
|
+
enforce(true).doesNotStartWith(100);
|
|
1241
|
+
// passes
|
|
1242
|
+
```
|
|
1243
|
+
|
|
1244
|
+
```js
|
|
1245
|
+
enforce('aba').doesNotStartWith('ab');
|
|
1246
|
+
enforce('some_string').doesNotStartWith('some_');
|
|
1247
|
+
enforce('string with spaces').doesNotStartWith('string with s');
|
|
1248
|
+
enforce('aaaa ').doesNotStartWith('aaaa ');
|
|
1249
|
+
// throws
|
|
1250
|
+
```
|
|
1251
|
+
|
|
1252
|
+
## isNegative
|
|
1253
|
+
|
|
1254
|
+
### Description
|
|
1255
|
+
|
|
1256
|
+
Determines whether a numeric value is negative or not.
|
|
1257
|
+
|
|
1258
|
+
### Usage examples:
|
|
1259
|
+
|
|
1260
|
+
```js
|
|
1261
|
+
enforce(-10).isNegative(); //passes
|
|
1262
|
+
enforce(-10.12).isNegative(); //passes
|
|
1263
|
+
enforce('-10.12').isNegative(); //passes
|
|
1264
|
+
enforce(10).isNegative(); // throws
|
|
1265
|
+
enforce('10').isNegative(); // throws
|
|
1266
|
+
```
|
|
1267
|
+
|
|
1268
|
+
## isPositive
|
|
1269
|
+
|
|
1270
|
+
### Description
|
|
1271
|
+
|
|
1272
|
+
Determines whether a numeric value is positive or not.
|
|
1273
|
+
|
|
1274
|
+
### Usage examples:
|
|
1275
|
+
|
|
1276
|
+
```js
|
|
1277
|
+
enforce(10).isPositive(); //passes
|
|
1278
|
+
enforce(10.12).isPositive(); //passes
|
|
1279
|
+
enforce('10.12').isPositive(); //passes
|
|
1280
|
+
enforce(-10).isPositive(); // throws
|
|
1281
|
+
enforce('-10.12').isPositive(); // throws
|
|
1282
|
+
```
|