-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
36 lines (33 loc) · 1.05 KB
/
util.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
exports.toString = function toString(o) {
if (typeof o === 'undefined') {
return 'undefined';
} else if (o !== o) {
return 'NaN';
} else if (Array.isArray(o)) {
return `[${o.toString()}]`;
} else if (o === null) {
return 'null';
} else {
return o !== null ? o.toString() : Object.prototype.toString.call(o);
}
};
exports.dashToCamelCase = function dashToCamelCase(str) {
const parts = str.split('-');
let newStr = '';
parts.forEach((part, i) => {
newStr += i === 0 ? part : part.substr(0, 1).toUpperCase() + part.substr(1);
});
return newStr;
};
// The "is" functions are slight mods on underscore.js's (Jeremy Ashkenas - @jashkenas)
const types = [ 'Function', 'String', 'Number' ];
types.forEach(type => {
exports[`is${type}`] = function (o) {
return Object.prototype.toString.call(o) === `[object ${type}]`;
};
});
exports.isArray = Array.isArray;
exports.isObject = function (o) { return o === Object(o); };
exports.isBoolean = function (o) {
return o === true || o === false || Object.prototype.toString.call(o) === '[object Boolean]';
};