-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutls.js
More file actions
43 lines (41 loc) · 869 Bytes
/
utls.js
File metadata and controls
43 lines (41 loc) · 869 Bytes
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
/**
* Redis Objects - Utils
* @module redis-objects
* @license MIT
* @author Corey S. McFadden <coreymcf@gmail.com>
*/
/**
* Test input value for data type
* @param {*} value - Input value
* @returns String - Type
*/
exports.getValueType = (value) => {
const type = typeof value;
return value === null
? "null"
: Array.isArray(value)
? "array"
: value instanceof Map
? "map"
: value instanceof Set
? "set"
: value instanceof Date
? "date"
: type === "string" && this.isJSON(value)
? "json"
: type;
};
/**
* Identify a string as containing a JSON object
* @param {string} str
* @returns
*/
exports.isJSON = (str) => {
try {
if (typeof str !== "string") return false;
const obj = JSON.parse(str);
return typeof obj === "object" && obj !== null;
} catch (e) {
return false;
}
};