node-switchbot 1.2.1-beta.8 → 1.4.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.
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  class ParameterChecker {
4
4
  constructor() {
@@ -12,55 +12,55 @@ class ParameterChecker {
12
12
  // code: 'TYPE_INVALID',
13
13
  // message: 'The `age` must be an integer.'
14
14
  // name: 'age',
15
- // }
15
+ // }
16
16
  // ---------------------------------
17
17
  return this._error;
18
18
  }
19
19
 
20
20
  isSpecified(value) {
21
- return (value === void 0) ? false : true;
21
+ return value === void 0 ? false : true;
22
22
  }
23
23
 
24
24
  /* ------------------------------------------------------------------
25
- * check(obj, rule, required)
26
- * - Check if the specified object contains valid values
27
- *
28
- * [Arguments]
29
- * - obj | Object | Required | Object including parameters you want to check
30
- * - rules | Object | Required | Object including rules for the parameters
31
- * - required | Boolean | Optional | Flag whther the `obj` is required or not.
32
- * | | | The default is `false`
33
- *
34
- * [Return value]
35
- * - If the value is valid, this method will return `true`.
36
- * - If the value is invalid, this method will return `false` and
37
- * an `Error` object will be set to `this._error`.
38
- *
39
- * [Usage]
40
- * let valid = parameterChecker.check(params, {
41
- * level: {
42
- * required: false,
43
- * type: 'integer',
44
- * max: 100
45
- * },
46
- * greeting: {
47
- * required: true, // But an empty string is allowed.
48
- * type: 'string',
49
- * max: 20 // the number of characters must be up to 20.
50
- * }
51
- * });
52
- * if(!valid) {
53
- * let e = parameterChecker.error.message;
54
- * throw new Error(message);
55
- * }
56
- * ---------------------------------------------------------------- */
25
+ * check(obj, rule, required)
26
+ * - Check if the specified object contains valid values
27
+ *
28
+ * [Arguments]
29
+ * - obj | Object | Required | Object including parameters you want to check
30
+ * - rules | Object | Required | Object including rules for the parameters
31
+ * - required | Boolean | Optional | Flag whther the `obj` is required or not.
32
+ * | | | The default is `false`
33
+ *
34
+ * [Return value]
35
+ * - If the value is valid, this method will return `true`.
36
+ * - If the value is invalid, this method will return `false` and
37
+ * an `Error` object will be set to `this._error`.
38
+ *
39
+ * [Usage]
40
+ * let valid = parameterChecker.check(params, {
41
+ * level: {
42
+ * required: false,
43
+ * type: 'integer',
44
+ * max: 100
45
+ * },
46
+ * greeting: {
47
+ * required: true, // But an empty string is allowed.
48
+ * type: 'string',
49
+ * max: 20 // the number of characters must be up to 20.
50
+ * }
51
+ * });
52
+ * if(!valid) {
53
+ * let e = parameterChecker.error.message;
54
+ * throw new Error(message);
55
+ * }
56
+ * ---------------------------------------------------------------- */
57
57
  check(obj, rules, required = false) {
58
58
  this._error = null;
59
59
  if (required) {
60
60
  if (!this.isSpecified(obj)) {
61
61
  this._error = {
62
- code: 'MISSING_REQUIRED',
63
- message: 'The first argument is missing.'
62
+ code: "MISSING_REQUIRED",
63
+ message: "The first argument is missing.",
64
64
  };
65
65
  return false;
66
66
  }
@@ -72,8 +72,8 @@ class ParameterChecker {
72
72
 
73
73
  if (!this.isObject(obj)) {
74
74
  this._error = {
75
- code: 'MISSING_REQUIRED',
76
- message: 'The first argument is missing.'
75
+ code: "MISSING_REQUIRED",
76
+ message: "The first argument is missing.",
77
77
  };
78
78
  return false;
79
79
  }
@@ -93,8 +93,8 @@ class ParameterChecker {
93
93
  if (rule.required) {
94
94
  result = false;
95
95
  this._error = {
96
- code: 'MISSING_REQUIRED',
97
- message: 'The `' + name + '` is required.'
96
+ code: "MISSING_REQUIRED",
97
+ message: "The `" + name + "` is required.",
98
98
  };
99
99
  break;
100
100
  } else {
@@ -102,23 +102,27 @@ class ParameterChecker {
102
102
  }
103
103
  }
104
104
 
105
- if (rule.type === 'float') {
105
+ if (rule.type === "float") {
106
106
  result = this.isFloat(v, rule, name);
107
- } else if (rule.type === 'integer') {
107
+ } else if (rule.type === "integer") {
108
108
  result = this.isInteger(v, rule, name);
109
- } else if (rule.type === 'boolean') {
109
+ } else if (rule.type === "boolean") {
110
110
  result = this.isBoolean(v, rule, name);
111
- } else if (rule.type === 'array') {
111
+ } else if (rule.type === "array") {
112
112
  result = this.isArray(v, rule, name);
113
- } else if (rule.type === 'object') {
113
+ } else if (rule.type === "object") {
114
114
  result = this.isObject(v, rule, name);
115
- } else if (rule.type === 'string') {
115
+ } else if (rule.type === "string") {
116
116
  result = this.isString(v, rule, name);
117
117
  } else {
118
118
  result = false;
119
119
  this._error = {
120
- code: 'TYPE_UNKNOWN',
121
- message: 'The rule specified for the `' + name + '` includes an unknown type: ' + rule.type,
120
+ code: "TYPE_UNKNOWN",
121
+ message:
122
+ "The rule specified for the `" +
123
+ name +
124
+ "` includes an unknown type: " +
125
+ rule.type,
122
126
  };
123
127
  }
124
128
 
@@ -132,55 +136,65 @@ class ParameterChecker {
132
136
  }
133
137
 
134
138
  /* ------------------------------------------------------------------
135
- * isFloat(value, rule, name)
136
- * - Check if the value is a float
137
- *
138
- * [Arguments]
139
- * - value | Any | Required | The value you want to check
140
- * - rule | Object | Optional |
141
- * - required | Boolean | Optional | Required or not. Default is `false`.
142
- * - min | Float | Optional | Minimum number
143
- * - max | Float | Optional | Maximum number
144
- * - enum | Array | Optional | list of possible values
145
- * - name | String | Optional | Parameter name
146
- *
147
- * If non-number value is specified to the `min` or `max`,
148
- * they will be ignored.
149
- *
150
- * [Return value]
151
- * - If the value is valid, this method will return `true`.
152
- * - If the value is invalid, this method will return `false` and
153
- * an `Error` object will be set to `this._error`.
154
- * ---------------------------------------------------------------- */
155
- isFloat(value, rule = {}, name = 'value') {
139
+ * isFloat(value, rule, name)
140
+ * - Check if the value is a float
141
+ *
142
+ * [Arguments]
143
+ * - value | Any | Required | The value you want to check
144
+ * - rule | Object | Optional |
145
+ * - required | Boolean | Optional | Required or not. Default is `false`.
146
+ * - min | Float | Optional | Minimum number
147
+ * - max | Float | Optional | Maximum number
148
+ * - enum | Array | Optional | list of possible values
149
+ * - name | String | Optional | Parameter name
150
+ *
151
+ * If non-number value is specified to the `min` or `max`,
152
+ * they will be ignored.
153
+ *
154
+ * [Return value]
155
+ * - If the value is valid, this method will return `true`.
156
+ * - If the value is invalid, this method will return `false` and
157
+ * an `Error` object will be set to `this._error`.
158
+ * ---------------------------------------------------------------- */
159
+ isFloat(value, rule = {}, name = "value") {
156
160
  this._error = null;
157
161
 
158
162
  if (!rule.required && !this.isSpecified(value)) {
159
163
  return true;
160
164
  }
161
165
 
162
- if (typeof (value) !== 'number') {
166
+ if (typeof value !== "number") {
163
167
  this._error = {
164
- code: 'TYPE_INVALID',
165
- message: 'The `' + name + '` must be a number (integer or float).'
168
+ code: "TYPE_INVALID",
169
+ message: "The `" + name + "` must be a number (integer or float).",
166
170
  };
167
171
  return false;
168
172
  }
169
173
 
170
- if (typeof (rule.min) === 'number') {
174
+ if (typeof rule.min === "number") {
171
175
  if (value < rule.min) {
172
176
  this._error = {
173
- code: 'VALUE_UNDERFLOW',
174
- message: 'The `' + name + '` must be grater than or equal to ' + rule.min + '.'
177
+ code: "VALUE_UNDERFLOW",
178
+ message:
179
+ "The `" +
180
+ name +
181
+ "` must be grater than or equal to " +
182
+ rule.min +
183
+ ".",
175
184
  };
176
185
  return false;
177
186
  }
178
187
  }
179
- if (typeof (rule.max) === 'number') {
188
+ if (typeof rule.max === "number") {
180
189
  if (value > rule.max) {
181
190
  this._error = {
182
- code: 'VALUE_OVERFLOW',
183
- message: 'The `' + name + '` must be less than or equal to ' + rule.max + '.'
191
+ code: "VALUE_OVERFLOW",
192
+ message:
193
+ "The `" +
194
+ name +
195
+ "` must be less than or equal to " +
196
+ rule.max +
197
+ ".",
184
198
  };
185
199
  return false;
186
200
  }
@@ -188,8 +202,13 @@ class ParameterChecker {
188
202
  if (Array.isArray(rule.enum) && rule.enum.length > 0) {
189
203
  if (rule.enum.indexOf(value) === -1) {
190
204
  this._error = {
191
- code: 'ENUM_UNMATCH',
192
- message: 'The `' + name + '` must be any one of ' + JSON.stringify(rule.enum) + '.'
205
+ code: "ENUM_UNMATCH",
206
+ message:
207
+ "The `" +
208
+ name +
209
+ "` must be any one of " +
210
+ JSON.stringify(rule.enum) +
211
+ ".",
193
212
  };
194
213
  return false;
195
214
  }
@@ -199,27 +218,27 @@ class ParameterChecker {
199
218
  }
200
219
 
201
220
  /* ------------------------------------------------------------------
202
- * isInteger(value, rule)
203
- * - Check if the value is an integer
204
- *
205
- * [Arguments]
206
- * - value | Any | Required | The value you want to check
207
- * - rule | Object | Optional |
208
- * - required | Boolean | Optional | Required or not. Default is `false`.|
209
- * - min | Float | Optional | Minimum number
210
- * - max | Float | Optional | Maximum number
211
- * - enum | Array | Optional | list of possible values
212
- * - name | String | Optional | Parameter name
213
- *
214
- * If non-number value is specified to the `min` or `max`,
215
- * they will be ignored.
216
- *
217
- * [Return value]
218
- * - If the value is valid, this method will return `true`.
219
- * - If the value is invalid, this method will return `false` and
220
- * an `Error` object will be set to `this._error`.
221
- * ---------------------------------------------------------------- */
222
- isInteger(value, rule = {}, name = 'value') {
221
+ * isInteger(value, rule)
222
+ * - Check if the value is an integer
223
+ *
224
+ * [Arguments]
225
+ * - value | Any | Required | The value you want to check
226
+ * - rule | Object | Optional |
227
+ * - required | Boolean | Optional | Required or not. Default is `false`.|
228
+ * - min | Float | Optional | Minimum number
229
+ * - max | Float | Optional | Maximum number
230
+ * - enum | Array | Optional | list of possible values
231
+ * - name | String | Optional | Parameter name
232
+ *
233
+ * If non-number value is specified to the `min` or `max`,
234
+ * they will be ignored.
235
+ *
236
+ * [Return value]
237
+ * - If the value is valid, this method will return `true`.
238
+ * - If the value is invalid, this method will return `false` and
239
+ * an `Error` object will be set to `this._error`.
240
+ * ---------------------------------------------------------------- */
241
+ isInteger(value, rule = {}, name = "value") {
223
242
  this._error = null;
224
243
 
225
244
  if (!rule.required && !this.isSpecified(value)) {
@@ -231,8 +250,8 @@ class ParameterChecker {
231
250
  return true;
232
251
  } else {
233
252
  this._error = {
234
- code: 'TYPE_INVALID',
235
- message: 'The `' + name + '` must be an integer.'
253
+ code: "TYPE_INVALID",
254
+ message: "The `" + name + "` must be an integer.",
236
255
  };
237
256
  return false;
238
257
  }
@@ -242,31 +261,31 @@ class ParameterChecker {
242
261
  }
243
262
 
244
263
  /* ------------------------------------------------------------------
245
- * isBoolean(value, rule, name)
246
- * - Check if the value is a boolean.
247
- *
248
- * [Arguments]
249
- * - value | Any | Required | The value you want to check
250
- * - rule | Object | Optional |
251
- * - required | Boolean | Optional | Required or not. Default is `false`.
252
- * - name | String | Optional | Parameter name
253
- *
254
- * [Return value]
255
- * - If the value is valid, this method will return `true`.
256
- * - If the value is invalid, this method will return `false` and
257
- * an `Error` object will be set to `this._error`.
258
- * ---------------------------------------------------------------- */
259
- isBoolean(value, rule = {}, name = 'value') {
264
+ * isBoolean(value, rule, name)
265
+ * - Check if the value is a boolean.
266
+ *
267
+ * [Arguments]
268
+ * - value | Any | Required | The value you want to check
269
+ * - rule | Object | Optional |
270
+ * - required | Boolean | Optional | Required or not. Default is `false`.
271
+ * - name | String | Optional | Parameter name
272
+ *
273
+ * [Return value]
274
+ * - If the value is valid, this method will return `true`.
275
+ * - If the value is invalid, this method will return `false` and
276
+ * an `Error` object will be set to `this._error`.
277
+ * ---------------------------------------------------------------- */
278
+ isBoolean(value, rule = {}, name = "value") {
260
279
  this._error = null;
261
280
 
262
281
  if (!rule.required && !this.isSpecified(value)) {
263
282
  return true;
264
283
  }
265
284
 
266
- if (typeof (value) !== 'boolean') {
285
+ if (typeof value !== "boolean") {
267
286
  this._error = {
268
- code: 'TYPE_INVALID',
269
- message: 'The `' + name + '` must be boolean.'
287
+ code: "TYPE_INVALID",
288
+ message: "The `" + name + "` must be boolean.",
270
289
  };
271
290
  return false;
272
291
  }
@@ -274,30 +293,30 @@ class ParameterChecker {
274
293
  }
275
294
 
276
295
  /* ------------------------------------------------------------------
277
- * isObject(value)
278
- * - Check if the value is an object
279
- *
280
- * [Arguments]
281
- * - value | Any | Required | The value you want to check
282
- * - rule | Object | Optional |
283
- * - required | Boolean | Optional | Required or not. Default is `false`.
284
- * - name | String | Optional | Parameter name
285
- *
286
- * [Return value]
287
- * - If the value is valid, this method will return `true`.
288
- * - If the value is invalid, this method will return `false` and
289
- * an `Error` object will be set to `this._error`.
290
- * ---------------------------------------------------------------- */
291
- isObject(value, rule = {}, name = 'value') {
296
+ * isObject(value)
297
+ * - Check if the value is an object
298
+ *
299
+ * [Arguments]
300
+ * - value | Any | Required | The value you want to check
301
+ * - rule | Object | Optional |
302
+ * - required | Boolean | Optional | Required or not. Default is `false`.
303
+ * - name | String | Optional | Parameter name
304
+ *
305
+ * [Return value]
306
+ * - If the value is valid, this method will return `true`.
307
+ * - If the value is invalid, this method will return `false` and
308
+ * an `Error` object will be set to `this._error`.
309
+ * ---------------------------------------------------------------- */
310
+ isObject(value, rule = {}, name = "value") {
292
311
  this._error = null;
293
312
  if (!rule.required && !this.isSpecified(value)) {
294
313
  return true;
295
314
  }
296
315
 
297
- if (typeof (value) !== 'object' || value === null || Array.isArray(value)) {
316
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
298
317
  this._error = {
299
- code: 'TYPE_INVALID',
300
- message: 'The `' + name + '` must be an object.'
318
+ code: "TYPE_INVALID",
319
+ message: "The `" + name + "` must be an object.",
301
320
  };
302
321
  return false;
303
322
  }
@@ -305,26 +324,26 @@ class ParameterChecker {
305
324
  }
306
325
 
307
326
  /* ------------------------------------------------------------------
308
- * isArray(value, rule, name)
309
- * - Check if the value is an `Array` object
310
- *
311
- * [Arguments]
312
- * - value | Any | Required | The value you want to check
313
- * - rule | Object | Optional |
314
- * - required | Boolean | Optional | Required or not. Default is `false`.
315
- * - min | Integer | Optional | Minimum number of elements in the array
316
- * - max | Integer | Optional | Maximum number of elements in the array
317
- * - name | String | Optional | Parameter name
318
- *
319
- * If non-number value is specified to the `min` or `max`,
320
- * they will be ignored.
321
- *
322
- * [Return value]
323
- * - If the value is valid, this method will return `true`.
324
- * - If the value is invalid, this method will return `false` and
325
- * an `Error` object will be set to `this._error`.
326
- * ---------------------------------------------------------------- */
327
- isArray(value, rule = {}, name = 'value') {
327
+ * isArray(value, rule, name)
328
+ * - Check if the value is an `Array` object
329
+ *
330
+ * [Arguments]
331
+ * - value | Any | Required | The value you want to check
332
+ * - rule | Object | Optional |
333
+ * - required | Boolean | Optional | Required or not. Default is `false`.
334
+ * - min | Integer | Optional | Minimum number of elements in the array
335
+ * - max | Integer | Optional | Maximum number of elements in the array
336
+ * - name | String | Optional | Parameter name
337
+ *
338
+ * If non-number value is specified to the `min` or `max`,
339
+ * they will be ignored.
340
+ *
341
+ * [Return value]
342
+ * - If the value is valid, this method will return `true`.
343
+ * - If the value is invalid, this method will return `false` and
344
+ * an `Error` object will be set to `this._error`.
345
+ * ---------------------------------------------------------------- */
346
+ isArray(value, rule = {}, name = "value") {
328
347
  this._error = null;
329
348
 
330
349
  if (!rule.required && !this.isSpecified(value)) {
@@ -333,26 +352,36 @@ class ParameterChecker {
333
352
 
334
353
  if (!Array.isArray(value)) {
335
354
  this._error = {
336
- code: 'TYPE_INVALID',
337
- message: 'The value must be an array.'
355
+ code: "TYPE_INVALID",
356
+ message: "The value must be an array.",
338
357
  };
339
358
  return false;
340
359
  }
341
360
 
342
- if (typeof (rule.min) === 'number') {
361
+ if (typeof rule.min === "number") {
343
362
  if (value.length < rule.min) {
344
363
  this._error = {
345
- code: 'LENGTH_UNDERFLOW',
346
- message: 'The number of characters in the `' + name + '` must be grater than or equal to ' + rule.min + '.'
364
+ code: "LENGTH_UNDERFLOW",
365
+ message:
366
+ "The number of characters in the `" +
367
+ name +
368
+ "` must be grater than or equal to " +
369
+ rule.min +
370
+ ".",
347
371
  };
348
372
  return false;
349
373
  }
350
374
  }
351
- if (typeof (rule.max) === 'number') {
375
+ if (typeof rule.max === "number") {
352
376
  if (value.length > rule.max) {
353
377
  this._error = {
354
- code: 'LENGTH_OVERFLOW',
355
- message: 'The number of characters in the `' + name + '` must be less than or equal to ' + rule.max + '.'
378
+ code: "LENGTH_OVERFLOW",
379
+ message:
380
+ "The number of characters in the `" +
381
+ name +
382
+ "` must be less than or equal to " +
383
+ rule.max +
384
+ ".",
356
385
  };
357
386
  return false;
358
387
  }
@@ -362,78 +391,102 @@ class ParameterChecker {
362
391
  }
363
392
 
364
393
  /* ------------------------------------------------------------------
365
- * isString(value, rule, name)
366
- * - Check if the value is an `Array` object
367
- *
368
- * [Arguments]
369
- * - value | Any | Required | The value you want to check
370
- * - rule | Object | Optional |
371
- * - required | Boolean | Optional | Required or not. Default is `false`.
372
- * - min | Integer | Optional | Minimum number of characters in the string
373
- * - max | Integer | Optional | Maximum number of characters in the string
374
- * - minBytes | Integer | Optional | Minimum bytes of the string (UTF-8)
375
- * - maxBytes | Integer | Optional | Maximum bytes of the string (UTF-8)
376
- * - pattern | RegExp | Optional | Pattern of the string
377
- * - enum | Array | Optional | list of possible values
378
- * - name | String | Optional | Parameter name
379
- *
380
- * If non-number value is specified to the `min` or `max`,
381
- * they will be ignored.
382
- *
383
- * [Return value]
384
- * - If the value is valid, this method will return `true`.
385
- * - If the value is invalid, this method will return `false` and
386
- * an `Error` object will be set to `this._error`.
387
- * ---------------------------------------------------------------- */
388
- isString(value, rule = {}, name = 'value') {
394
+ * isString(value, rule, name)
395
+ * - Check if the value is an `Array` object
396
+ *
397
+ * [Arguments]
398
+ * - value | Any | Required | The value you want to check
399
+ * - rule | Object | Optional |
400
+ * - required | Boolean | Optional | Required or not. Default is `false`.
401
+ * - min | Integer | Optional | Minimum number of characters in the string
402
+ * - max | Integer | Optional | Maximum number of characters in the string
403
+ * - minBytes | Integer | Optional | Minimum bytes of the string (UTF-8)
404
+ * - maxBytes | Integer | Optional | Maximum bytes of the string (UTF-8)
405
+ * - pattern | RegExp | Optional | Pattern of the string
406
+ * - enum | Array | Optional | list of possible values
407
+ * - name | String | Optional | Parameter name
408
+ *
409
+ * If non-number value is specified to the `min` or `max`,
410
+ * they will be ignored.
411
+ *
412
+ * [Return value]
413
+ * - If the value is valid, this method will return `true`.
414
+ * - If the value is invalid, this method will return `false` and
415
+ * an `Error` object will be set to `this._error`.
416
+ * ---------------------------------------------------------------- */
417
+ isString(value, rule = {}, name = "value") {
389
418
  this._error = null;
390
419
 
391
420
  if (!rule.required && !this.isSpecified(value)) {
392
421
  return true;
393
422
  }
394
423
 
395
- if (typeof (value) !== 'string') {
424
+ if (typeof value !== "string") {
396
425
  this._error = {
397
- code: 'TYPE_INVALID',
398
- message: 'The value must be a string.'
426
+ code: "TYPE_INVALID",
427
+ message: "The value must be a string.",
399
428
  };
400
429
  return false;
401
430
  }
402
431
 
403
- if (typeof (rule.min) === 'number') {
432
+ if (typeof rule.min === "number") {
404
433
  if (value.length < rule.min) {
405
434
  this._error = {
406
- code: 'LENGTH_UNDERFLOW',
407
- message: 'The number of characters in the `' + name + '` must be grater than or equal to ' + rule.min + '.'
435
+ code: "LENGTH_UNDERFLOW",
436
+ message:
437
+ "The number of characters in the `" +
438
+ name +
439
+ "` must be grater than or equal to " +
440
+ rule.min +
441
+ ".",
408
442
  };
409
443
  return false;
410
444
  }
411
445
  }
412
- if (typeof (rule.max) === 'number') {
446
+ if (typeof rule.max === "number") {
413
447
  if (value.length > rule.max) {
414
448
  this._error = {
415
- code: 'LENGTH_OVERFLOW',
416
- message: 'The number of characters in the `' + name + '` must be less than or equal to ' + rule.max + '.'
449
+ code: "LENGTH_OVERFLOW",
450
+ message:
451
+ "The number of characters in the `" +
452
+ name +
453
+ "` must be less than or equal to " +
454
+ rule.max +
455
+ ".",
417
456
  };
418
457
  return false;
419
458
  }
420
459
  }
421
- if (typeof (rule.minBytes) === 'number') {
422
- let blen = Buffer.from(value, 'utf8').length;
460
+ if (typeof rule.minBytes === "number") {
461
+ let blen = Buffer.from(value, "utf8").length;
423
462
  if (blen < rule.minBytes) {
424
463
  this._error = {
425
- code: 'LENGTH_UNDERFLOW',
426
- message: 'The byte length of the `' + name + '` (' + blen + ' bytes) must be grater than or equal to ' + rule.minBytes + ' bytes.'
464
+ code: "LENGTH_UNDERFLOW",
465
+ message:
466
+ "The byte length of the `" +
467
+ name +
468
+ "` (" +
469
+ blen +
470
+ " bytes) must be grater than or equal to " +
471
+ rule.minBytes +
472
+ " bytes.",
427
473
  };
428
474
  return false;
429
475
  }
430
476
  }
431
- if (typeof (rule.maxBytes) === 'number') {
432
- let blen = Buffer.from(value, 'utf8').length;
477
+ if (typeof rule.maxBytes === "number") {
478
+ let blen = Buffer.from(value, "utf8").length;
433
479
  if (blen > rule.maxBytes) {
434
480
  this._error = {
435
- code: 'LENGTH_OVERFLOW',
436
- message: 'The byte length of the `' + name + '` (' + blen + ' bytes) must be less than or equal to ' + rule.maxBytes + ' bytes.'
481
+ code: "LENGTH_OVERFLOW",
482
+ message:
483
+ "The byte length of the `" +
484
+ name +
485
+ "` (" +
486
+ blen +
487
+ " bytes) must be less than or equal to " +
488
+ rule.maxBytes +
489
+ " bytes.",
437
490
  };
438
491
  return false;
439
492
  }
@@ -441,8 +494,8 @@ class ParameterChecker {
441
494
  if (rule.pattern instanceof RegExp) {
442
495
  if (!rule.pattern.test(v)) {
443
496
  this._error = {
444
- code: 'PATTERN_UNMATCH',
445
- message: 'The `' + name + '` does not conform with the pattern.'
497
+ code: "PATTERN_UNMATCH",
498
+ message: "The `" + name + "` does not conform with the pattern.",
446
499
  };
447
500
  return false;
448
501
  }
@@ -450,8 +503,13 @@ class ParameterChecker {
450
503
  if (Array.isArray(rule.enum) && rule.enum.length > 0) {
451
504
  if (rule.enum.indexOf(value) === -1) {
452
505
  this._error = {
453
- code: 'ENUM_UNMATCH',
454
- message: 'The `' + name + '` must be any one of ' + JSON.stringify(rule.enum) + '.'
506
+ code: "ENUM_UNMATCH",
507
+ message:
508
+ "The `" +
509
+ name +
510
+ "` must be any one of " +
511
+ JSON.stringify(rule.enum) +
512
+ ".",
455
513
  };
456
514
  return false;
457
515
  }