preconditions 3.0.1 → 4.0.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.
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master, main]
6
+ pull_request:
7
+ branches: [master, main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version: [24.x, 25.x]
15
+ steps:
16
+ - uses: actions/checkout@v5
17
+ - uses: actions/setup-node@v6
18
+ with:
19
+ node-version: ${{ matrix.node-version }}
20
+ cache: npm
21
+ - run: npm install
22
+ - run: npm test
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![view on npm](http://img.shields.io/npm/v/preconditions.svg)](https://www.npmjs.org/package/preconditions)
4
4
  [![npm module downloads](http://img.shields.io/npm/dt/preconditions.svg)](https://www.npmjs.org/package/preconditions)
5
- [![Build Status](https://travis-ci.org/corybill/preconditions.svg?branch=master)](https://travis-ci.org/corybill/Preconditions)
5
+ [![CI](https://github.com/corybill/preconditions/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/corybill/preconditions/actions/workflows/ci.yml)
6
6
  [![Gitter](https://badges.gitter.im/corybill/preconditions.svg)](https://gitter.im/corybill/preconditions?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
7
 
8
8
  #### Support for Precondition error checking in Node.js
@@ -0,0 +1,32 @@
1
+ import js from "@eslint/js";
2
+ import globals from "globals";
3
+
4
+ export default [
5
+ js.configs.recommended,
6
+ {
7
+ languageOptions: {
8
+ ecmaVersion: 2024,
9
+ sourceType: "module",
10
+ globals: {
11
+ ...globals.node,
12
+ ...globals.mocha
13
+ }
14
+ },
15
+ rules: {
16
+ "indent": ["error", 2, { "SwitchCase": 1 }],
17
+ "quotes": ["error", "double"],
18
+ "semi": ["error", "always"],
19
+ "no-var": "error",
20
+ "prefer-const": "error",
21
+ "eqeqeq": ["error", "smart"],
22
+ "curly": ["error", "all"],
23
+ "no-throw-literal": "warn"
24
+ }
25
+ },
26
+ {
27
+ files: ["spec/**/*.js"],
28
+ rules: {
29
+ "prefer-const": "off"
30
+ }
31
+ }
32
+ ];
package/lib/constants.js CHANGED
@@ -1,43 +1,43 @@
1
- exports.ShouldBeDefined = "Variable should be defined.";
2
- exports.ShouldBeUndefined = "Variable should be undefined.";
1
+ export const ShouldBeDefined = "Variable should be defined.";
2
+ export const ShouldBeUndefined = "Variable should be undefined.";
3
3
 
4
- exports.ShouldBeArray = "Variable should be of type Array.";
5
- exports.ShouldNotBeArray = "Variable should NOT be of type Array.";
4
+ export const ShouldBeArray = "Variable should be of type Array.";
5
+ export const ShouldNotBeArray = "Variable should NOT be of type Array.";
6
6
 
7
- exports.ShouldBeObject = "Variable should be of type Object.";
8
- exports.ShouldNotBeObject = "Variable should NOT be of type Object.";
7
+ export const ShouldBeObject = "Variable should be of type Object.";
8
+ export const ShouldNotBeObject = "Variable should NOT be of type Object.";
9
9
 
10
- exports.ShouldBeEmpty = "Array or object should be empty.";
11
- exports.ShouldNotBeEmpty = "Array or object should NOT be empty.";
10
+ export const ShouldBeEmpty = "Array or object should be empty.";
11
+ export const ShouldNotBeEmpty = "Array or object should NOT be empty.";
12
12
 
13
- exports.ShouldBeFunction = "Variable should be a Function.";
14
- exports.ShouldNotBeFunction = "Variable should NOT be a Function.";
13
+ export const ShouldBeFunction = "Variable should be a Function.";
14
+ export const ShouldNotBeFunction = "Variable should NOT be a Function.";
15
15
 
16
- exports.ShouldBeString = "Variable should be a String.";
17
- exports.ShouldNotBeString = "Variable should NOT be a String.";
16
+ export const ShouldBeString = "Variable should be a String.";
17
+ export const ShouldNotBeString = "Variable should NOT be a String.";
18
18
 
19
- exports.ShouldBeNumber = "Variable should be a Number.";
20
- exports.ShouldNotBeNumber = "Variable should NOT be a Number.";
19
+ export const ShouldBeNumber = "Variable should be a Number.";
20
+ export const ShouldNotBeNumber = "Variable should NOT be a Number.";
21
21
 
22
- exports.ShouldBeFinite = "Variable should be Finite (i.e. not infinity).";
23
- exports.ShouldBeInfinite = "Variable should be Infinite.";
22
+ export const ShouldBeFinite = "Variable should be Finite (i.e. not infinity).";
23
+ export const ShouldBeInfinite = "Variable should be Infinite.";
24
24
 
25
- exports.ShouldBeBoolean = "Variable should be a Boolean.";
26
- exports.ShouldNotBeBoolean = "Variable should NOT be a Boolean.";
25
+ export const ShouldBeBoolean = "Variable should be a Boolean.";
26
+ export const ShouldNotBeBoolean = "Variable should NOT be a Boolean.";
27
27
 
28
- exports.ShouldBeDate = "Variable should be a Date.";
29
- exports.ShouldNotBeDate = "Variable should NOT be a Date.";
28
+ export const ShouldBeDate = "Variable should be a Date.";
29
+ export const ShouldNotBeDate = "Variable should NOT be a Date.";
30
30
 
31
- exports.ShouldBeRegExp = "Variable should be a RegExp.";
32
- exports.ShouldNotBeRegExp = "Variable should NOT be a RegExp.";
31
+ export const ShouldBeRegExp = "Variable should be a RegExp.";
32
+ export const ShouldNotBeRegExp = "Variable should NOT be a RegExp.";
33
33
 
34
- exports.ShouldBeFalsey = "Variable should be falsey.";
35
- exports.ShouldNotBeFalsey = "Variable should NOT be falsey.";
34
+ export const ShouldBeFalsey = "Variable should be falsey.";
35
+ export const ShouldNotBeFalsey = "Variable should NOT be falsey.";
36
36
 
37
- exports.IllegalArgument = "Illegal Argument.";
38
- exports.IllegalState = "Illegal State.";
37
+ export const IllegalArgument = "Illegal Argument.";
38
+ export const IllegalState = "Illegal State.";
39
39
 
40
- exports.ShouldHaveValidIndex = "Index should be between between 0 (inclusive) and size (exclusive).";
41
- exports.ShouldHaveValidPosition = "Index should be between index between 0 (inclusive) and size (inclusive).";
42
- exports.ShouldHaveValidPositions = "Start and End should be between valid sub range between 0 (inclusive) and size (inclusive).";
43
- exports.StartBeforeEnd = "Start value should be less than the end value.";
40
+ export const ShouldHaveValidIndex = "Index should be between between 0 (inclusive) and size (exclusive).";
41
+ export const ShouldHaveValidPosition = "Index should be between index between 0 (inclusive) and size (inclusive).";
42
+ export const ShouldHaveValidPositions = "Start and End should be between valid sub range between 0 (inclusive) and size (inclusive).";
43
+ export const StartBeforeEnd = "Start value should be less than the end value.";
@@ -1,6 +1,4 @@
1
- "use strict";
2
-
3
- var errValidation = require("./singleton-validator");
1
+ import errValidation from "./singleton-validator.js";
4
2
 
5
3
  /**
6
4
  *
@@ -21,10 +19,10 @@ class InstanceValidator {
21
19
  }
22
20
 
23
21
  _validate_(configPath, verification, message) {
24
- var variables = configPath.split(".");
22
+ const variables = configPath.split(".");
25
23
 
26
- var current = this.out || {};
27
- var count = 0;
24
+ let current = this.out || {};
25
+ let count = 0;
28
26
 
29
27
  variables.forEach((variable) => {
30
28
  // If statement needed because we need to be able to verify shouldBeUndefined.
@@ -541,4 +539,4 @@ class InstanceValidator {
541
539
  }
542
540
  }
543
541
 
544
- module.exports = InstanceValidator;
542
+ export default InstanceValidator;
@@ -1,9 +1,14 @@
1
- "use strict";
1
+ import { format } from "node:util";
2
2
 
3
- var constants = require("./../constants"),
4
- validate = require("../validator/validate");
3
+ import * as constants from "../constants.js";
4
+ import validate from "../validator/validate.js";
5
5
 
6
- var util = require("util");
6
+ function formatMessage(message, template) {
7
+ if (template === undefined) {
8
+ return message;
9
+ }
10
+ return format(message, ...template);
11
+ }
7
12
 
8
13
  /**
9
14
  * Validate single value with a chainable interface.
@@ -23,10 +28,7 @@ class SingletonValidator {
23
28
  */
24
29
  static shouldBeDefined(val, message, template) {
25
30
  if (validate.shouldBeDefined(val)) {
26
- var msg = message || constants.ShouldBeDefined;
27
-
28
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
29
- throw new Error(msg);
31
+ throw new Error(formatMessage(message || constants.ShouldBeDefined, template));
30
32
  }
31
33
  return this;
32
34
  }
@@ -41,10 +43,7 @@ class SingletonValidator {
41
43
  */
42
44
  static shouldBeUndefined(val, message, template) {
43
45
  if (validate.shouldBeUndefined(val)) {
44
- var msg = message || constants.ShouldBeUndefined;
45
-
46
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
47
- throw new Error(msg);
46
+ throw new Error(formatMessage(message || constants.ShouldBeUndefined, template));
48
47
  }
49
48
  return this;
50
49
  }
@@ -59,10 +58,7 @@ class SingletonValidator {
59
58
  */
60
59
  static shouldBeArray(val, message, template) {
61
60
  if (validate.shouldBeArray(val)) {
62
- var msg = message || constants.ShouldBeArray;
63
-
64
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
65
- throw new Error(msg);
61
+ throw new Error(formatMessage(message || constants.ShouldBeArray, template));
66
62
  }
67
63
  return this;
68
64
  }
@@ -77,10 +73,7 @@ class SingletonValidator {
77
73
  */
78
74
  static shouldNotBeArray(val, message, template) {
79
75
  if (validate.shouldNotBeArray(val)) {
80
- var msg = message || constants.ShouldNotBeArray;
81
-
82
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
83
- throw new Error(msg);
76
+ throw new Error(formatMessage(message || constants.ShouldNotBeArray, template));
84
77
  }
85
78
  return this;
86
79
  }
@@ -95,10 +88,7 @@ class SingletonValidator {
95
88
  */
96
89
  static shouldBeObject(val, message, template) {
97
90
  if (validate.shouldBeObject(val)) {
98
- var msg = message || constants.ShouldBeObject;
99
-
100
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
101
- throw new Error(msg);
91
+ throw new Error(formatMessage(message || constants.ShouldBeObject, template));
102
92
  }
103
93
  return this;
104
94
  }
@@ -113,10 +103,7 @@ class SingletonValidator {
113
103
  */
114
104
  static shouldNotBeObject(val, message, template) {
115
105
  if (validate.shouldNotBeObject(val)) {
116
- var msg = message || constants.ShouldNotBeObject;
117
-
118
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
119
- throw new Error(msg);
106
+ throw new Error(formatMessage(message || constants.ShouldNotBeObject, template));
120
107
  }
121
108
  return this;
122
109
  }
@@ -131,10 +118,7 @@ class SingletonValidator {
131
118
  */
132
119
  static shouldBeEmpty(val, message, template) {
133
120
  if (validate.shouldBeEmpty(val)) {
134
- var msg = message || constants.ShouldBeEmpty;
135
-
136
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
137
- throw new Error(msg);
121
+ throw new Error(formatMessage(message || constants.ShouldBeEmpty, template));
138
122
  }
139
123
  return this;
140
124
  }
@@ -149,10 +133,7 @@ class SingletonValidator {
149
133
  */
150
134
  static shouldNotBeEmpty(val, message, template) {
151
135
  if (validate.shouldNotBeEmpty(val)) {
152
- var msg = message || constants.ShouldNotBeEmpty;
153
-
154
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
155
- throw new Error(msg);
136
+ throw new Error(formatMessage(message || constants.ShouldNotBeEmpty, template));
156
137
  }
157
138
  return this;
158
139
  }
@@ -167,10 +148,7 @@ class SingletonValidator {
167
148
  */
168
149
  static shouldBeFunction(val, message, template) {
169
150
  if (validate.shouldBeFunction(val)) {
170
- var msg = message || constants.ShouldBeFunction;
171
-
172
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
173
- throw new Error(msg);
151
+ throw new Error(formatMessage(message || constants.ShouldBeFunction, template));
174
152
  }
175
153
  return this;
176
154
  }
@@ -185,10 +163,7 @@ class SingletonValidator {
185
163
  */
186
164
  static shouldNotBeFunction(val, message, template) {
187
165
  if (validate.shouldNotBeFunction(val)) {
188
- var msg = message || constants.ShouldNotBeFunction;
189
-
190
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
191
- throw new Error(msg);
166
+ throw new Error(formatMessage(message || constants.ShouldNotBeFunction, template));
192
167
  }
193
168
  return this;
194
169
  }
@@ -203,10 +178,7 @@ class SingletonValidator {
203
178
  */
204
179
  static shouldBeString(val, message, template) {
205
180
  if (validate.shouldBeString(val)) {
206
- var msg = message || constants.ShouldBeString;
207
-
208
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
209
- throw new Error(msg);
181
+ throw new Error(formatMessage(message || constants.ShouldBeString, template));
210
182
  }
211
183
  return this;
212
184
  }
@@ -221,10 +193,7 @@ class SingletonValidator {
221
193
  */
222
194
  static shouldNotBeString(val, message, template) {
223
195
  if (validate.shouldNotBeString(val)) {
224
- var msg = message || constants.ShouldNotBeString;
225
-
226
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
227
- throw new Error(msg);
196
+ throw new Error(formatMessage(message || constants.ShouldNotBeString, template));
228
197
  }
229
198
  return this;
230
199
  }
@@ -239,10 +208,7 @@ class SingletonValidator {
239
208
  */
240
209
  static shouldBeNumber(val, message, template) {
241
210
  if (validate.shouldBeNumber(val)) {
242
- var msg = message || constants.ShouldBeNumber;
243
-
244
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
245
- throw new Error(msg);
211
+ throw new Error(formatMessage(message || constants.ShouldBeNumber, template));
246
212
  }
247
213
  return this;
248
214
  }
@@ -257,10 +223,7 @@ class SingletonValidator {
257
223
  */
258
224
  static shouldNotBeNumber(val, message, template) {
259
225
  if (validate.shouldNotBeNumber(val)) {
260
- var msg = message || constants.ShouldNotBeNumber;
261
-
262
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
263
- throw new Error(msg);
226
+ throw new Error(formatMessage(message || constants.ShouldNotBeNumber, template));
264
227
  }
265
228
  return this;
266
229
  }
@@ -275,10 +238,7 @@ class SingletonValidator {
275
238
  */
276
239
  static shouldBeFinite(val, message, template) {
277
240
  if (validate.shouldBeFinite(val)) {
278
- var msg = message || constants.ShouldBeFinite;
279
-
280
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
281
- throw new Error(msg);
241
+ throw new Error(formatMessage(message || constants.ShouldBeFinite, template));
282
242
  }
283
243
  return this;
284
244
  }
@@ -293,10 +253,7 @@ class SingletonValidator {
293
253
  */
294
254
  static shouldBeInfinite(val, message, template) {
295
255
  if (validate.shouldBeInfinite(val)) {
296
- var msg = message || constants.ShouldBeInfinite;
297
-
298
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
299
- throw new Error(msg);
256
+ throw new Error(formatMessage(message || constants.ShouldBeInfinite, template));
300
257
  }
301
258
  return this;
302
259
  }
@@ -311,10 +268,7 @@ class SingletonValidator {
311
268
  */
312
269
  static shouldBeBoolean(val, message, template) {
313
270
  if (validate.shouldBeBoolean(val)) {
314
- var msg = message || constants.ShouldBeBoolean;
315
-
316
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
317
- throw new Error(msg);
271
+ throw new Error(formatMessage(message || constants.ShouldBeBoolean, template));
318
272
  }
319
273
  return this;
320
274
  }
@@ -329,10 +283,7 @@ class SingletonValidator {
329
283
  */
330
284
  static shouldNotBeBoolean(val, message, template) {
331
285
  if (validate.shouldNotBeBoolean(val)) {
332
- var msg = message || constants.ShouldNotBeBoolean;
333
-
334
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
335
- throw new Error(msg);
286
+ throw new Error(formatMessage(message || constants.ShouldNotBeBoolean, template));
336
287
  }
337
288
  return this;
338
289
  }
@@ -347,10 +298,7 @@ class SingletonValidator {
347
298
  */
348
299
  static shouldBeDate(val, message, template) {
349
300
  if (validate.shouldBeDate(val)) {
350
- var msg = message || constants.ShouldBeDate;
351
-
352
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
353
- throw new Error(msg);
301
+ throw new Error(formatMessage(message || constants.ShouldBeDate, template));
354
302
  }
355
303
  return this;
356
304
  }
@@ -365,10 +313,7 @@ class SingletonValidator {
365
313
  */
366
314
  static shouldNotBeDate(val, message, template) {
367
315
  if (validate.shouldNotBeDate(val)) {
368
- var msg = message || constants.ShouldNotBeDate;
369
-
370
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
371
- throw new Error(msg);
316
+ throw new Error(formatMessage(message || constants.ShouldNotBeDate, template));
372
317
  }
373
318
  return this;
374
319
  }
@@ -383,10 +328,7 @@ class SingletonValidator {
383
328
  */
384
329
  static shouldBeRegExp(val, message, template) {
385
330
  if (validate.shouldBeRegExp(val)) {
386
- var msg = message || constants.ShouldBeRegExp;
387
-
388
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
389
- throw new Error(msg);
331
+ throw new Error(formatMessage(message || constants.ShouldBeRegExp, template));
390
332
  }
391
333
  return this;
392
334
  }
@@ -401,10 +343,7 @@ class SingletonValidator {
401
343
  */
402
344
  static shouldNotBeRegExp(val, message, template) {
403
345
  if (validate.shouldNotBeRegExp(val)) {
404
- var msg = message || constants.ShouldNotBeRegExp;
405
-
406
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
407
- throw new Error(msg);
346
+ throw new Error(formatMessage(message || constants.ShouldNotBeRegExp, template));
408
347
  }
409
348
  return this;
410
349
  }
@@ -419,10 +358,7 @@ class SingletonValidator {
419
358
  */
420
359
  static shouldBeFalsey(val, message, template) {
421
360
  if (validate.shouldBeFalsey(val)) {
422
- var msg = message || constants.ShouldBeFalsey;
423
-
424
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
425
- throw new Error(msg);
361
+ throw new Error(formatMessage(message || constants.ShouldBeFalsey, template));
426
362
  }
427
363
  return this;
428
364
  }
@@ -437,10 +373,7 @@ class SingletonValidator {
437
373
  */
438
374
  static shouldNotBeFalsey(val, message, template) {
439
375
  if (validate.shouldNotBeFalsey(val)) {
440
- var msg = message || constants.ShouldNotBeFalsey;
441
-
442
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
443
- throw new Error(msg);
376
+ throw new Error(formatMessage(message || constants.ShouldNotBeFalsey, template));
444
377
  }
445
378
  return this;
446
379
  }
@@ -503,10 +436,7 @@ class SingletonValidator {
503
436
  */
504
437
  static checkArgument(expression, message, template) {
505
438
  if (validate.checkArgument(expression)) {
506
- var msg = message || constants.IllegalArgument;
507
-
508
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
509
- throw new Error(msg);
439
+ throw new Error(formatMessage(message || constants.IllegalArgument, template));
510
440
  }
511
441
  return this;
512
442
  }
@@ -521,10 +451,7 @@ class SingletonValidator {
521
451
  */
522
452
  static checkState(expression, message, template) {
523
453
  if (validate.checkState(expression)) {
524
- var msg = message || constants.IllegalState;
525
-
526
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
527
- throw new Error(msg);
454
+ throw new Error(formatMessage(message || constants.IllegalState, template));
528
455
  }
529
456
  return this;
530
457
  }
@@ -540,10 +467,7 @@ class SingletonValidator {
540
467
  */
541
468
  static checkElementIndex(index, size, message, template) {
542
469
  if (validate.checkElementIndex(index, size)) {
543
- var msg = message || constants.ShouldHaveValidIndex;
544
-
545
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
546
- throw new Error(msg);
470
+ throw new Error(formatMessage(message || constants.ShouldHaveValidIndex, template));
547
471
  }
548
472
  return this;
549
473
  }
@@ -559,10 +483,7 @@ class SingletonValidator {
559
483
  */
560
484
  static checkPositionIndex(index, size, message, template) {
561
485
  if (validate.checkPositionIndex(index, size)) {
562
- var msg = message || constants.ShouldHaveValidPosition;
563
-
564
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
565
- throw new Error(msg);
486
+ throw new Error(formatMessage(message || constants.ShouldHaveValidPosition, template));
566
487
  }
567
488
  return this;
568
489
  }
@@ -579,13 +500,10 @@ class SingletonValidator {
579
500
  */
580
501
  static checkPositionIndexes(start, end, size, message, template) {
581
502
  if (validate.checkPositionIndexes(start, end, size)) {
582
- var msg = message || constants.ShouldHaveValidPositions;
583
-
584
- msg = (template === undefined) ? msg : util.format.apply(this, [msg].concat(template));
585
- throw new Error(msg);
503
+ throw new Error(formatMessage(message || constants.ShouldHaveValidPositions, template));
586
504
  }
587
505
  return this;
588
506
  }
589
507
  }
590
508
 
591
- module.exports = SingletonValidator;
509
+ export default SingletonValidator;
@@ -1,6 +1,4 @@
1
- "use strict";
2
-
3
- const Errr = require("errr");
1
+ import Errr from "errr";
4
2
 
5
3
  /**
6
4
  * Error Builder allows you to use optional functions to build an error object. The error can have appended stack traces and debug params to assist with debugging.
@@ -61,7 +59,7 @@ class ErrrDecorator {
61
59
  setAll(object) {
62
60
  const keys = Object.keys(object);
63
61
 
64
- for (let key of keys) {
62
+ for (const key of keys) {
65
63
  this._setValues_.push({ key, value: object[key] });
66
64
  }
67
65
 
@@ -84,7 +82,7 @@ class ErrrDecorator {
84
82
  */
85
83
  test() {
86
84
  if (this._failsTest_()) {
87
- let errr = Errr.newError(this._message_, this._templateParams_)
85
+ const errr = Errr.newError(this._message_, this._templateParams_)
88
86
  .debug(this._debugParams_, this._shouldDebug_)
89
87
  .appendTo(this._appendTo_);
90
88
 
@@ -99,9 +97,9 @@ class ErrrDecorator {
99
97
  /**
100
98
  * Synonym for the test function.
101
99
  */
102
- t() { // eslint-disable-line
100
+ t() {
103
101
  this.test();
104
102
  }
105
103
  }
106
104
 
107
- module.exports = ErrrDecorator;
105
+ export default ErrrDecorator;
@@ -1,8 +1,6 @@
1
- "use strict";
2
-
3
- var constants = require("./../constants"),
4
- ErrrDecorator = require("./decorator"),
5
- CoreUtilIs = require("core-util-is");
1
+ import * as constants from "../constants.js";
2
+ import ErrrDecorator from "./decorator.js";
3
+ import * as typeChecks from "../util/type-checks.js";
6
4
 
7
5
  /**
8
6
  * Validate single value with a buildable interface on top of the errr node module.
@@ -23,7 +21,7 @@ class ErrrValidator {
23
21
  */
24
22
  static shouldBeDefined(val, message, template) {
25
23
  function doesFail() {
26
- return CoreUtilIs.isUndefined(val);
24
+ return typeChecks.isUndefined(val);
27
25
  }
28
26
 
29
27
  message = message || constants.ShouldBeDefined;
@@ -39,7 +37,7 @@ class ErrrValidator {
39
37
  */
40
38
  static shouldBeUndefined(val, message, template) {
41
39
  function doesFail() {
42
- return !CoreUtilIs.isUndefined(val);
40
+ return !typeChecks.isUndefined(val);
43
41
  }
44
42
 
45
43
  message = message || constants.ShouldBeUndefined;
@@ -56,7 +54,7 @@ class ErrrValidator {
56
54
  */
57
55
  static shouldBeArray(val, message, template) {
58
56
  function doesFail() {
59
- return !CoreUtilIs.isArray(val);
57
+ return !typeChecks.isArray(val);
60
58
  }
61
59
 
62
60
  message = message || constants.ShouldBeArray;
@@ -72,7 +70,7 @@ class ErrrValidator {
72
70
  */
73
71
  static shouldNotBeArray(val, message, template) {
74
72
  function doesFail() {
75
- return CoreUtilIs.isArray(val);
73
+ return typeChecks.isArray(val);
76
74
  }
77
75
 
78
76
  message = message || constants.ShouldNotBeArray;
@@ -89,7 +87,7 @@ class ErrrValidator {
89
87
  */
90
88
  static shouldBeObject(val, message, template) {
91
89
  function doesFail() {
92
- return !CoreUtilIs.isObject(val);
90
+ return !(val !== null && (typeof val === "object" || typeof val === "function"));
93
91
  }
94
92
 
95
93
  message = message || constants.ShouldBeObject;
@@ -105,7 +103,7 @@ class ErrrValidator {
105
103
  */
106
104
  static shouldNotBeObject(val, message, template) {
107
105
  function doesFail() {
108
- return CoreUtilIs.isObject(val);
106
+ return val !== null && (typeof val === "object" || typeof val === "function");
109
107
  }
110
108
 
111
109
  message = message || constants.ShouldNotBeObject;
@@ -122,7 +120,7 @@ class ErrrValidator {
122
120
  */
123
121
  static shouldBeEmpty(val, message, template) {
124
122
  function doesFail() {
125
- return !CoreUtilIs.isEmpty(val);
123
+ return !typeChecks.isEmpty(val);
126
124
  }
127
125
 
128
126
  message = message || constants.ShouldBeEmpty;
@@ -138,7 +136,7 @@ class ErrrValidator {
138
136
  */
139
137
  static shouldNotBeEmpty(val, message, template) {
140
138
  function doesFail() {
141
- return CoreUtilIs.isEmpty(val);
139
+ return typeChecks.isEmpty(val);
142
140
  }
143
141
 
144
142
  message = message || constants.ShouldNotBeEmpty;
@@ -155,7 +153,7 @@ class ErrrValidator {
155
153
  */
156
154
  static shouldBeFunction(val, message, template) {
157
155
  function doesFail() {
158
- return !CoreUtilIs.isFunction(val);
156
+ return !typeChecks.isFunction(val);
159
157
  }
160
158
 
161
159
  message = message || constants.ShouldBeFunction;
@@ -171,7 +169,7 @@ class ErrrValidator {
171
169
  */
172
170
  static shouldNotBeFunction(val, message, template) {
173
171
  function doesFail() {
174
- return CoreUtilIs.isFunction(val);
172
+ return typeChecks.isFunction(val);
175
173
  }
176
174
 
177
175
  message = message || constants.ShouldNotBeFunction;
@@ -188,7 +186,7 @@ class ErrrValidator {
188
186
  */
189
187
  static shouldBeString(val, message, template) {
190
188
  function doesFail() {
191
- return !CoreUtilIs.isString(val);
189
+ return !typeChecks.isString(val);
192
190
  }
193
191
 
194
192
  message = message || constants.ShouldBeString;
@@ -204,7 +202,7 @@ class ErrrValidator {
204
202
  */
205
203
  static shouldNotBeString(val, message, template) {
206
204
  function doesFail() {
207
- return CoreUtilIs.isString(val);
205
+ return typeChecks.isString(val);
208
206
  }
209
207
 
210
208
  message = message || constants.ShouldNotBeString;
@@ -221,7 +219,7 @@ class ErrrValidator {
221
219
  */
222
220
  static shouldBeNumber(val, message, template) {
223
221
  function doesFail() {
224
- return !CoreUtilIs.isNumber(val);
222
+ return !typeChecks.isNumber(val);
225
223
  }
226
224
 
227
225
  message = message || constants.ShouldBeNumber;
@@ -237,7 +235,7 @@ class ErrrValidator {
237
235
  */
238
236
  static shouldNotBeNumber(val, message, template) {
239
237
  function doesFail() {
240
- return CoreUtilIs.isNumber(val);
238
+ return typeChecks.isNumber(val);
241
239
  }
242
240
 
243
241
  message = message || constants.ShouldNotBeNumber;
@@ -254,7 +252,7 @@ class ErrrValidator {
254
252
  */
255
253
  static shouldBeFinite(val, message, template) {
256
254
  function doesFail() {
257
- return !CoreUtilIs.isFinite(val);
255
+ return !typeChecks.isFinite(val);
258
256
  }
259
257
 
260
258
  message = message || constants.ShouldBeFinite;
@@ -270,7 +268,7 @@ class ErrrValidator {
270
268
  */
271
269
  static shouldBeInfinite(val, message, template) {
272
270
  function doesFail() {
273
- return CoreUtilIs.isFinite(val);
271
+ return typeChecks.isFinite(val);
274
272
  }
275
273
 
276
274
  message = message || constants.ShouldBeInfinite;
@@ -287,7 +285,7 @@ class ErrrValidator {
287
285
  */
288
286
  static shouldBeBoolean(val, message, template) {
289
287
  function doesFail() {
290
- return !CoreUtilIs.isBoolean(val);
288
+ return !typeChecks.isBoolean(val);
291
289
  }
292
290
 
293
291
  message = message || constants.ShouldBeBoolean;
@@ -303,7 +301,7 @@ class ErrrValidator {
303
301
  */
304
302
  static shouldNotBeBoolean(val, message, template) {
305
303
  function doesFail() {
306
- return CoreUtilIs.isBoolean(val);
304
+ return typeChecks.isBoolean(val);
307
305
  }
308
306
 
309
307
  message = message || constants.ShouldNotBeBoolean;
@@ -320,7 +318,7 @@ class ErrrValidator {
320
318
  */
321
319
  static shouldBeDate(val, message, template) {
322
320
  function doesFail() {
323
- return !CoreUtilIs.isDate(val);
321
+ return !typeChecks.isDate(val);
324
322
  }
325
323
 
326
324
  message = message || constants.ShouldBeDate;
@@ -336,7 +334,7 @@ class ErrrValidator {
336
334
  */
337
335
  static shouldNotBeDate(val, message, template) {
338
336
  function doesFail() {
339
- return CoreUtilIs.isDate(val);
337
+ return typeChecks.isDate(val);
340
338
  }
341
339
 
342
340
  message = message || constants.ShouldNotBeDate;
@@ -353,7 +351,7 @@ class ErrrValidator {
353
351
  */
354
352
  static shouldBeRegExp(val, message, template) {
355
353
  function doesFail() {
356
- return !CoreUtilIs.isRegExp(val);
354
+ return !typeChecks.isRegExp(val);
357
355
  }
358
356
 
359
357
  message = message || constants.ShouldBeRegExp;
@@ -369,7 +367,7 @@ class ErrrValidator {
369
367
  */
370
368
  static shouldNotBeRegExp(val, message, template) {
371
369
  function doesFail() {
372
- return CoreUtilIs.isRegExp(val);
370
+ return typeChecks.isRegExp(val);
373
371
  }
374
372
 
375
373
  message = message || constants.ShouldNotBeRegExp;
@@ -541,4 +539,4 @@ class ErrrValidator {
541
539
  }
542
540
  }
543
541
 
544
- module.exports = ErrrValidator;
542
+ export default ErrrValidator;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ const mod = require("./preconditions.js");
4
+
5
+ module.exports = mod.default ?? mod;
@@ -1,8 +1,6 @@
1
- "use strict";
2
-
3
- var InstanceValidator = require("./err/instance-validator"),
4
- SingletonValidator = require("./err/singleton-validator"),
5
- ErrrValidator = require("./errr/validator");
1
+ import InstanceValidator from "./err/instance-validator.js";
2
+ import SingletonValidator from "./err/singleton-validator.js";
3
+ import ErrrValidator from "./errr/validator.js";
6
4
 
7
5
  /**
8
6
  * Preconditions entry point interface.
@@ -51,4 +49,4 @@ class Preconditions {
51
49
  }
52
50
  }
53
51
 
54
- module.exports = Preconditions;
52
+ export default Preconditions;
@@ -0,0 +1,45 @@
1
+ export function isUndefined(val) {
2
+ return val === undefined;
3
+ }
4
+
5
+ export function isArray(val) {
6
+ return Array.isArray(val);
7
+ }
8
+
9
+ export function isEmpty(val) {
10
+ if (!val) {
11
+ return true;
12
+ }
13
+ if (Array.isArray(val) || typeof val === "string") {
14
+ return val.length === 0;
15
+ }
16
+ return Object.keys(val).length === 0;
17
+ }
18
+
19
+ export function isFunction(val) {
20
+ return typeof val === "function";
21
+ }
22
+
23
+ export function isString(val) {
24
+ return typeof val === "string";
25
+ }
26
+
27
+ export function isNumber(val) {
28
+ return typeof val === "number";
29
+ }
30
+
31
+ export function isFinite(val) {
32
+ return typeof val === "number" && globalThis.isFinite(val);
33
+ }
34
+
35
+ export function isBoolean(val) {
36
+ return typeof val === "boolean";
37
+ }
38
+
39
+ export function isDate(val) {
40
+ return val instanceof Date;
41
+ }
42
+
43
+ export function isRegExp(val) {
44
+ return val instanceof RegExp;
45
+ }
@@ -1,108 +1,106 @@
1
- "use strict";
1
+ import * as typeChecks from "../util/type-checks.js";
2
2
 
3
- var CoreUtilIs = require("core-util-is");
4
-
5
- var validate = {
6
- shouldBeDefined: function (val) {
7
- return CoreUtilIs.isUndefined(val);
3
+ const validate = {
4
+ shouldBeDefined(val) {
5
+ return typeChecks.isUndefined(val);
8
6
  },
9
- shouldBeUndefined: function (val) {
10
- return !CoreUtilIs.isUndefined(val);
7
+ shouldBeUndefined(val) {
8
+ return !typeChecks.isUndefined(val);
11
9
  },
12
10
 
13
- shouldBeArray: function (val) {
14
- return !CoreUtilIs.isArray(val);
11
+ shouldBeArray(val) {
12
+ return !typeChecks.isArray(val);
15
13
  },
16
- shouldNotBeArray: function (val) {
17
- return CoreUtilIs.isArray(val);
14
+ shouldNotBeArray(val) {
15
+ return typeChecks.isArray(val);
18
16
  },
19
17
 
20
- shouldBeObject: function (val) {
21
- return !CoreUtilIs.isObject(val);
18
+ shouldBeObject(val) {
19
+ return !(val !== null && (typeof val === "object" || typeof val === "function"));
22
20
  },
23
- shouldNotBeObject: function (val) {
24
- return CoreUtilIs.isObject(val);
21
+ shouldNotBeObject(val) {
22
+ return (val !== null && (typeof val === "object" || typeof val === "function"));
25
23
  },
26
24
 
27
- shouldBeEmpty: function (val) {
28
- return !CoreUtilIs.isEmpty(val);
25
+ shouldBeEmpty(val) {
26
+ return !typeChecks.isEmpty(val);
29
27
  },
30
- shouldNotBeEmpty: function (val) {
31
- return CoreUtilIs.isEmpty(val);
28
+ shouldNotBeEmpty(val) {
29
+ return typeChecks.isEmpty(val);
32
30
  },
33
31
 
34
- shouldBeFunction: function (val) {
35
- return !CoreUtilIs.isFunction(val);
32
+ shouldBeFunction(val) {
33
+ return !typeChecks.isFunction(val);
36
34
  },
37
- shouldNotBeFunction: function (val) {
38
- return CoreUtilIs.isFunction(val);
35
+ shouldNotBeFunction(val) {
36
+ return typeChecks.isFunction(val);
39
37
  },
40
38
 
41
- shouldBeString: function (val) {
42
- return !CoreUtilIs.isString(val);
39
+ shouldBeString(val) {
40
+ return !typeChecks.isString(val);
43
41
  },
44
- shouldNotBeString: function (val) {
45
- return CoreUtilIs.isString(val);
42
+ shouldNotBeString(val) {
43
+ return typeChecks.isString(val);
46
44
  },
47
45
 
48
- shouldBeNumber: function (val) {
49
- return !CoreUtilIs.isNumber(val);
46
+ shouldBeNumber(val) {
47
+ return !typeChecks.isNumber(val);
50
48
  },
51
- shouldNotBeNumber: function (val) {
52
- return CoreUtilIs.isNumber(val);
49
+ shouldNotBeNumber(val) {
50
+ return typeChecks.isNumber(val);
53
51
  },
54
52
 
55
- shouldBeFinite: function (val) {
56
- return !CoreUtilIs.isFinite(val);
53
+ shouldBeFinite(val) {
54
+ return !typeChecks.isFinite(val);
57
55
  },
58
- shouldBeInfinite: function (val) {
59
- return CoreUtilIs.isFinite(val);
56
+ shouldBeInfinite(val) {
57
+ return typeChecks.isFinite(val);
60
58
  },
61
59
 
62
- shouldBeBoolean: function (val) {
63
- return !CoreUtilIs.isBoolean(val);
60
+ shouldBeBoolean(val) {
61
+ return !typeChecks.isBoolean(val);
64
62
  },
65
- shouldNotBeBoolean: function (val) {
66
- return CoreUtilIs.isBoolean(val);
63
+ shouldNotBeBoolean(val) {
64
+ return typeChecks.isBoolean(val);
67
65
  },
68
66
 
69
- shouldBeDate: function (val) {
70
- return !CoreUtilIs.isDate(val);
67
+ shouldBeDate(val) {
68
+ return !typeChecks.isDate(val);
71
69
  },
72
- shouldNotBeDate: function (val) {
73
- return CoreUtilIs.isDate(val);
70
+ shouldNotBeDate(val) {
71
+ return typeChecks.isDate(val);
74
72
  },
75
73
 
76
- shouldBeRegExp: function (val) {
77
- return !CoreUtilIs.isRegExp(val);
74
+ shouldBeRegExp(val) {
75
+ return !typeChecks.isRegExp(val);
78
76
  },
79
- shouldNotBeRegExp: function (val) {
80
- return CoreUtilIs.isRegExp(val);
77
+ shouldNotBeRegExp(val) {
78
+ return typeChecks.isRegExp(val);
81
79
  },
82
80
 
83
- shouldBeFalsey: function (val) {
81
+ shouldBeFalsey(val) {
84
82
  return !!val;
85
83
  },
86
- shouldNotBeFalsey: function (val) {
84
+ shouldNotBeFalsey(val) {
87
85
  return !val;
88
86
  },
89
87
 
90
- checkArgument: function (val) {
88
+ checkArgument(val) {
91
89
  return !val;
92
90
  },
93
- checkState: function (val) {
91
+ checkState(val) {
94
92
  return !val;
95
93
  },
96
94
 
97
- checkElementIndex: function (index, size) {
95
+ checkElementIndex(index, size) {
98
96
  return (index < 0 || index >= size);
99
97
  },
100
- checkPositionIndex: function (index, size) {
98
+ checkPositionIndex(index, size) {
101
99
  return (index < 0 || index > size);
102
100
  },
103
- checkPositionIndexes: function (start, end, size) {
101
+ checkPositionIndexes(start, end, size) {
104
102
  return ((end < start) || (start < 0 || end > size));
105
103
  }
106
104
  };
107
105
 
108
- module.exports = validate;
106
+ export default validate;
package/package.json CHANGED
@@ -1,44 +1,35 @@
1
1
  {
2
2
  "name": "preconditions",
3
3
  "author": "Cory Parrish",
4
- "main": "./lib/preconditions.js",
5
- "version": "3.0.1",
4
+ "type": "module",
5
+ "main": "./lib/preconditions.cjs",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./lib/preconditions.js",
9
+ "require": "./lib/preconditions.cjs",
10
+ "default": "./lib/preconditions.js"
11
+ }
12
+ },
13
+ "version": "4.0.0",
6
14
  "description": "Support for Precondition error checking in Node.js.",
7
15
  "homepage": "https://github.com/corybill/preconditions",
8
16
  "bugs": {
9
17
  "url": "https://github.com/corybill/preconditions/issues"
10
18
  },
19
+ "engines": {
20
+ "node": ">=24.0.0"
21
+ },
11
22
  "scripts": {
12
23
  "test": "npm run ut && npm run lint",
13
- "ut": "./node_modules/mocha/bin/_mocha ./spec/unit",
24
+ "ut": "mocha ./spec/unit",
14
25
  "perf": "env perf=true env test=false maddox ./spec/unit",
15
26
  "uap": "env perf=true test=true maddox ./spec/unit",
16
- "coverage": "./bin/maddox-cov.js",
17
- "lint": "./node_modules/eslint/bin/eslint.js ./spec/ ./lib",
18
- "docs": " ./node_modules/jsdoc-to-markdown/bin/cli.js \"./lib/**/*.js\" > api.md"
27
+ "lint": "eslint ./spec/ ./lib",
28
+ "docs": "jsdoc-to-markdown \"./lib/**/*.js\" > api.md"
19
29
  },
20
30
  "keywords": [
21
- "StriveNine",
22
- "Strive9",
23
31
  "preconditions",
24
32
  "Guava",
25
- "Throw Error",
26
- "Errr",
27
- "Error",
28
- "Error Factory",
29
- "Error Builder",
30
- "Stack Trace",
31
- "Appendable stack trace",
32
- "append stack trace",
33
- "concat strack trace",
34
- "concatenate strack trace",
35
- "Appendable error",
36
- "append error",
37
- "concat error",
38
- "concatenate error",
39
- "Debug Params",
40
- "Promise",
41
- "Promise Chain",
42
33
  "errr"
43
34
  ],
44
35
  "license": "MIT",
@@ -47,15 +38,26 @@
47
38
  "url": "https://github.com/corybill/preconditions.git"
48
39
  },
49
40
  "dependencies": {
50
- "core-util-is": "1.x",
51
- "errr": "2.x"
41
+ "errr": "^5.0.0"
52
42
  },
53
43
  "devDependencies": {
54
- "chai": "3.x",
55
- "chance": "1.x",
56
- "eslint": "7.x",
57
- "jsdoc-to-markdown": "7.x",
58
- "maddox": "2.x",
59
- "mocha": "9.x"
44
+ "@eslint/js": "^9.39.1",
45
+ "chai": "^5.2.0",
46
+ "chance": "^1.1.13",
47
+ "eslint": "^9.39.1",
48
+ "globals": "^16.5.0",
49
+ "jsdoc-to-markdown": "^9.1.3",
50
+ "maddox": "^4.0.4",
51
+ "mocha": "^11.7.5"
52
+ },
53
+ "overrides": {
54
+ "maddox": {
55
+ "mocha": "$mocha"
56
+ },
57
+ "debug": "^4.4.0",
58
+ "diff": "^8.0.3",
59
+ "js-yaml": "^4.1.0",
60
+ "minimatch": "^9.0.5",
61
+ "serialize-javascript": "^7.0.5"
60
62
  }
61
63
  }
package/.eslintrc DELETED
@@ -1,145 +0,0 @@
1
- {
2
- "rules": {
3
- // common
4
- "indent": [2, 2, {"SwitchCase": 1}], // specify tab or space width for your code
5
- "quotes": [2, "double"], // specify whether backticks, double or single quotes should be used
6
- "linebreak-style": [2, "unix"], // disallow mixed 'LF' and 'CRLF' as linebreaks
7
- "semi": [2, "always"], // require or disallow use of semicolons instead of ASI
8
- // errors
9
- "no-extra-parens": [2, "functions"], // disallow unnecessary parentheses
10
- "no-unexpected-multiline": [2], // Avoid code that looks like two expressions but is actually one
11
- "valid-jsdoc": [0], // Ensure JSDoc comments are valid
12
- // best practices
13
- "accessor-pairs": [0], // Enforces getter/setter pairs in objects
14
- "block-scoped-var": [2], // treat var statements as if they were block scoped
15
- "complexity": [0], // specify the maximum cyclomatic complexity allowed in a program
16
- "consistent-return": [2], // require return statements to either always or never specify values
17
- "curly": [2, "all"], // specify curly brace conventions for all control statements
18
- "default-case": [2], // require default case in switch statements
19
- "dot-notation": [2], // encourages use of dot notation whenever possible
20
- "dot-location": [2, "property"], // enforces consistent newlines before or after dots
21
- "eqeqeq": [2, "smart"], // require the use of === and !==
22
- "guard-for-in": [2], // make sure for-in loops have an if statement
23
- "no-alert": [2], // disallow the use of alert, confirm, and prompt
24
- "no-caller": [2], // disallow use of arguments.caller or arguments.callee
25
- "no-div-regex": [0], // disallow division operators explicitly at beginning of regular expression
26
- "no-else-return": [0], // disallow else after a return in an if
27
- "no-eq-null": [2], // disallow comparisons to null without a type-checking operator
28
- "no-eval": [2], // disallow use of eval()
29
- "no-extend-native": [2], // disallow adding to native types
30
- "no-extra-bind": [2], // disallow unnecessary function binding
31
- "no-fallthrough": [2], // disallow fallthrough of case statements (recommended)
32
- "no-floating-decimal": [2], // disallow the use of leading or trailing decimal points in numeric literals
33
- "no-implicit-coercion": [0], // disallow the type conversions with shorter notations
34
- "no-implied-eval": [2], // disallow use of eval()-like methods
35
- "no-invalid-this": [0], // disallow this keywords outside of classes or class-like objects
36
- "no-iterator": [2], // disallow usage of __iterator__ property
37
- "no-labels": [2], // disallow use of labeled statements
38
- "no-lone-blocks": [2], // disallow unnecessary nested blocks
39
- "no-loop-func": [2], // disallow creation of functions within loops
40
- "no-multi-spaces": [2], // disallow use of multiple spaces
41
- "no-multi-str": [2], // disallow use of multiline strings
42
- "no-native-reassign": [2], // disallow reassignments of native objects
43
- "no-new-func": [2], // disallow use of new operator for Function object
44
- "no-new-wrappers": [0], // disallows creating new instances of String,Number, and Boolean
45
- "no-new": [2], // disallow use of the new operator when not part of an assignment or comparison
46
- "no-octal-escape": [2], // disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
47
- "no-octal": [2], // disallow use of octal literals (recommended)
48
- "no-param-reassign": [0, {"props": false}], // disallow reassignment of function parameters
49
- "no-process-env": [0], // disallow use of process.env
50
- "no-proto": [2], // disallow usage of __proto__ property
51
- "no-redeclare": [2, {"builtinGlobals": true}], // disallow declaring the same variable more than once (recommended)
52
- "no-return-assign": [0], // disallow use of assignment in return statement
53
- "no-script-url": [2], // disallow use of javascript: urls.
54
- "no-self-compare": [2], // disallow comparisons where both sides are exactly the same
55
- "no-sequences": [2], // disallow use of the comma operator
56
- "no-throw-literal": [1], // restrict what can be thrown as an exception
57
- "no-unused-expressions": [2], // disallow usage of expressions in statement position
58
- "no-useless-call": [2], // disallow unnecessary .call() and .apply()
59
- "no-useless-concat": [2], // disallow unnecessary concatenation of literals or template literals
60
- "no-void": [2], // disallow use of the void operator
61
- "no-warning-comments": [0, {"terms": ["todo", "fixme"], "location": "start"}], // disallow usage of configurable warning terms in comments": [2], // e.g. TODO or FIXME
62
- "no-with": [2], // disallow use of the with statement
63
- "radix": [2], // require use of the second argument for parseInt()
64
- "vars-on-top": [0], // require declaration of all vars at the top of their containing scope
65
- "wrap-iife": [2], // require immediate function invocation to be wrapped in parentheses
66
- "yoda": [0, "never"], // require or disallow Yoda conditions
67
- // Variables
68
- "init-declarations": [0], // enforce or disallow variable initializations at definition
69
- "no-catch-shadow": [0], // disallow the catch clause parameter name being the same as a variable in the outer scope
70
- "no-delete-var": [2], // disallow deletion of variables (recommended)
71
- "no-label-var": [2], // disallow labels that share a name with a variable
72
- "no-shadow-restricted-names": [2], // disallow shadowing of names such as arguments
73
- "no-shadow": [2], // disallow declaration of variables already declared in the outer scope
74
- "no-undef-init": [2], // disallow use of undefined when initializing variables
75
- "no-undef": [2], // disallow use of undeclared variables unless mentioned in a /*global */ block (recommended)
76
- "no-undefined": [0], // disallow use of undefined variable
77
- "no-unused-vars": [2], // disallow declaration of variables that are not used in the code (recommended)
78
- "no-use-before-define": [2, "nofunc"], // disallow use of variables before they are defined
79
- // nodejs
80
- "callback-return": [2, ["callback", "cb", "next"]], // enforce return after a callback
81
- "handle-callback-err": [2, "^(err\\d?|error\\d?|^.+Err$|^.+Error$)$"], // enforce error handling in callbacks
82
- "no-mixed-requires": [2, false], // disallow mixing regular variable and require declarations
83
- "no-new-require": [2], // disallow use of new operator with the require function
84
- "no-path-concat": [2], // disallow string concatenation with __dirname and __filename
85
- "no-process-exit": [0], // disallow process.exit()
86
- "no-restricted-modules": [0], // restrict usage of specified node modules
87
- "no-sync": [2], // disallow use of synchronous methods
88
- // Stylistic
89
- "array-bracket-spacing": [2, "never"], // enforce spacing inside array brackets
90
- "block-spacing": [2, "never"], // disallow or enforce spaces inside of single line blocks
91
- "brace-style": [2, "1tbs", { "allowSingleLine": true }], // enforce one true brace style
92
- "camelcase": [2, {"properties": "always"}], // require camel case names
93
- "comma-spacing": [2, {"before": false, "after": true}], // enforce spacing before and after comma
94
- "comma-style": [2, "last"], // enforce one true comma style
95
- "computed-property-spacing": [2, "never"], // require or disallow padding inside computed properties
96
- "consistent-this": [2, "self"], // enforce consistent naming when capturing the current execution context
97
- "eol-last": [2], // enforce newline at the end of file, with no multiple empty lines
98
- "func-names": [0], // require function expressions to have a name
99
- "func-style": [2, "declaration"], // enforce use of function declarations or expressions
100
- "id-length": [2, {"min": 3, "properties": "never", "exceptions": ["Q", "q", "_", "cb", "id", "i", "j"]}], // this option enforces minimum and maximum identifier lengths (variable names, property names etc.)
101
- "id-match": [0], // require identifiers to match the provided regular expression
102
- "key-spacing": [2, {"beforeColon": false, "afterColon": true}], // enforce spacing between keys and values in object literal properties
103
- "keyword-spacing": [2, {}], // require a space after certain keywords
104
- "lines-around-comment": [0], // enforce empty lines around comments
105
- "max-nested-callbacks": [2, 6], // specify the maximum depth callbacks can be nested
106
- "new-cap": [2, {"capIsNewExceptions": ["Router"]}], // require a capital letter for constructors
107
- "new-parens": [2], // disallow the omission of parentheses when invoking a constructor with no arguments
108
- "newline-after-var": [2, "always"], // require or disallow an empty newline after variable declarations
109
- "no-array-constructor": [2], // disallow use of the Array constructor
110
- "no-continue": [2], // disallow use of the continue statement
111
- "no-inline-comments": [0], // disallow comments inline after code
112
- "no-lonely-if": [0], // disallow if as the only statement in an else block
113
- "no-mixed-spaces-and-tabs": [2], // disallow mixed spaces and tabs for indentation (recommended)
114
- "no-multiple-empty-lines": [2, {"max": 1}], // disallow multiple empty lines
115
- "no-nested-ternary": [2], // disallow nested ternary expressions
116
- "no-new-object": [2], // disallow the use of the Object constructor
117
- "no-spaced-func": [2], // disallow space between function identifier and application
118
- "no-ternary": [0], // disallow the use of ternary operators
119
- "no-trailing-spaces": [2, { "skipBlankLines": true }], // disallow trailing whitespace at the end of lines
120
- "no-underscore-dangle": [0], // disallow dangling underscores in identifiers
121
- "no-unneeded-ternary": [2], // disallow the use of Boolean literals in conditional expressions
122
- "object-curly-spacing": [2, "always"], // require or disallow padding inside curly braces
123
- "one-var": [0], // require or disallow one variable declaration per function
124
- "operator-assignment": [0], // require assignment operator shorthand where possible or prohibit it entirely
125
- "operator-linebreak": [2, "after"], // enforce operators to be placed before or after line breaks
126
- "padded-blocks": [0, "never"], // enforce padding within blocks
127
- "quote-props": [2, "consistent"], // require quotes around object literal property names
128
- "semi-spacing": [2, {"before": false, "after": true}], // enforce spacing before and after semicolons
129
- "sort-vars": [0], // sort variables within the same declaration block
130
- "space-before-blocks": [2, "always"], // require or disallow a space before blocks
131
- "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], // require or disallow a space before function opening parenthesis
132
- "space-in-parens": [2, "never"], // require or disallow spaces inside parentheses
133
- "space-infix-ops": [2, {"int32Hint": false}], // require spaces around operators
134
- "space-return-throw-case": [0], // require a space after return, throw, and case
135
- "space-unary-ops": [2, {"words": true, "nonwords": false}], // require or disallow spaces before/after unary operators
136
- "spaced-comment": [2, "always"], // require or disallow a space immediately following the // or /* in a comment
137
- "wrap-regex": [2] // require regex literals to be wrapped in parentheses
138
- },
139
- "env": {
140
- "node": true,
141
- "es6": true,
142
- "mocha": true
143
- },
144
- "extends": "eslint:recommended"
145
- }
package/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: node_js
2
- os:
3
- - linux
4
- dist: xenial
5
- node_js:
6
- - lts/*
7
- - 16.0
8
- - 14.0
9
- - 12.0
10
- notifications:
11
- webhooks:
12
- urls:
13
- - https://webhooks.gitter.im/e/c27fddacc09aaa988b05
14
- on_success: change # options: [always|never|change] default: always
15
- on_failure: always # options: [always|never|change] default: always
16
- on_start: never # options: [always|never|change] default: always