-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathtypes.js
92 lines (82 loc) · 2.16 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*!
* Copyright (c) 2017-2023 Digital Bazaar, Inc. All rights reserved.
*/
'use strict';
const api = {};
module.exports = api;
/**
* Returns true if the given value is an Array.
*
* @param v the value to check.
*
* @return true if the value is an Array, false if not.
*/
api.isArray = Array.isArray;
/**
* Returns true if the given value is a Boolean.
*
* @param v the value to check.
*
* @return true if the value is a Boolean, false if not.
*/
api.isBoolean = v => (typeof v === 'boolean' ||
Object.prototype.toString.call(v) === '[object Boolean]');
/**
* Returns true if the given value is a double.
*
* @param v the value to check.
*
* @return true if the value is a double, false if not.
*/
api.isDouble = v => api.isNumber(v) &&
(String(v).indexOf('.') !== -1 || Math.abs(v) >= 1e21);
/**
* Returns true if the given value is an empty Object.
*
* @param v the value to check.
*
* @return true if the value is an empty Object, false if not.
*/
api.isEmptyObject = v => api.isObject(v) && Object.keys(v).length === 0;
/**
* Returns true if the given value is a Number.
*
* @param v the value to check.
*
* @return true if the value is a Number, false if not.
*/
api.isNumber = v => (typeof v === 'number' ||
Object.prototype.toString.call(v) === '[object Number]');
/**
* Returns true if the given value is numeric.
*
* @param v the value to check.
*
* @return true if the value is numeric, false if not.
*/
api.isNumeric = v => !isNaN(parseFloat(v)) && isFinite(v);
/**
* Returns true if the given value is an Object.
*
* @param v the value to check.
*
* @return true if the value is an Object, false if not.
*/
api.isObject = v => v !== null && typeof v === 'object' && !Array.isArray(v);
/**
* Returns true if the given value is a String.
*
* @param v the value to check.
*
* @return true if the value is a String, false if not.
*/
api.isString = v => (typeof v === 'string' ||
Object.prototype.toString.call(v) === '[object String]');
/**
* Returns true if the given value is undefined.
*
* @param v the value to check.
*
* @return true if the value is undefined, false if not.
*/
api.isUndefined = v => typeof v === 'undefined';