binhend 2.3.5 → 2.3.6
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/package.json
CHANGED
|
@@ -287,7 +287,7 @@ function AsyncFunction(input, options = {}) {
|
|
|
287
287
|
return Validator(input, (input) => input instanceof AsyncFunctionConstructor, { ...options, type: 'async function' });
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
const AsyncFunctionConstructor = global.Object.getPrototypeOf(async function() {}).constructor;
|
|
290
|
+
const AsyncFunctionConstructor = global.Object.getPrototypeOf(async function () { }).constructor;
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
293
|
* Validate an input being a date
|
|
@@ -314,30 +314,49 @@ function DateLike(input, options = {}) {
|
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
/**
|
|
317
|
-
* Validate an input being one of
|
|
317
|
+
* Validate an input being one of allowed values
|
|
318
318
|
*
|
|
319
|
+
* @template {string | number | boolean | symbol | bigint} T
|
|
319
320
|
* @param {*} input - Input value needs to be validated.
|
|
320
|
-
* @param {
|
|
321
|
-
* @param {Options} options -
|
|
322
|
-
* @returns {
|
|
323
|
-
* @throws {HttpError} - If validation fails
|
|
321
|
+
* @param {readonly T[]} enumValues - Array of allowed values.
|
|
322
|
+
* @param {Options} options - Options for validation.
|
|
323
|
+
* @returns {T} - The validated input.
|
|
324
|
+
* @throws {HttpError} - If validation fails.
|
|
324
325
|
*/
|
|
325
326
|
function Enum(input, enumValues, options = {}) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (!(validArray || validObject)) {
|
|
330
|
-
throwError('Enum validator requires an array or object of allowed values');
|
|
327
|
+
if (!types.isArray(enumValues)) {
|
|
328
|
+
throwError('Enum validator requires an array of allowed values');
|
|
331
329
|
}
|
|
332
330
|
|
|
333
|
-
var method = validArray ? 'includes' : 'hasOwnProperty';
|
|
334
|
-
|
|
335
331
|
return Validator(
|
|
336
|
-
input, (input) => enumValues
|
|
337
|
-
{ ...options, message: options.message ||
|
|
332
|
+
input, (input) => enumValues.includes(input),
|
|
333
|
+
{ ...options, message: options.message || `Value {${input}} is not defined in enum` }
|
|
338
334
|
);
|
|
339
335
|
}
|
|
340
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Return all keys of an object.
|
|
339
|
+
* Returns an array of names of the enumerable properties and methods of an object.
|
|
340
|
+
*
|
|
341
|
+
* @template {{ [key: PropertyKey]: any }} T
|
|
342
|
+
* @param {T} object - An object with keys and values
|
|
343
|
+
* @returns {(keyof T)[]} - List of all keys
|
|
344
|
+
*/
|
|
345
|
+
function Keys(object) {
|
|
346
|
+
return global.Object.keys(object);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Returns an array of values owned by the enumerable properties of an object.
|
|
351
|
+
*
|
|
352
|
+
* @template {{ [key: PropertyKey]: any }} T
|
|
353
|
+
* @param {T} object
|
|
354
|
+
* @returns {T[keyof T][]}
|
|
355
|
+
*/
|
|
356
|
+
function Values(object) {
|
|
357
|
+
return global.Object.values(object);
|
|
358
|
+
}
|
|
359
|
+
|
|
341
360
|
/**
|
|
342
361
|
* Validate an input being defined (not undefined)
|
|
343
362
|
*
|
|
@@ -425,7 +444,7 @@ module.exports = {
|
|
|
425
444
|
AsyncFunction,
|
|
426
445
|
Date,
|
|
427
446
|
DateLike,
|
|
428
|
-
Enum,
|
|
447
|
+
Enum, Keys, Values,
|
|
429
448
|
Defined,
|
|
430
449
|
NotNull,
|
|
431
450
|
NotNullish,
|