-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
54 lines (46 loc) · 812 Bytes
/
utils.js
File metadata and controls
54 lines (46 loc) · 812 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
44
45
46
47
48
49
50
51
52
53
54
function toInt(str) {
return parseInt(str, 10)
}
function times(n) {
const arr = []
for (let i = 0; i < n; i++) {
arr.push(i)
}
return arr
}
function last(arr) {
return arr[arr.length - 1]
}
function cls(def, separator = ' ') {
let classes
for (const cls in def) {
if (def[cls]) {
classes = classes == null ? cls : classes + separator + cls
}
}
return classes || ''
}
function clamp(min, max, x) {
if (x < min) return min
if (x > max) return max
return x
}
function min(...args) {
return Math.min(...args.filter(a => a != null))
}
function max(...args) {
return Math.max(...args.filter(a => a != null))
}
function isFunction(a) {
return typeof a === 'function'
}
module.exports = {
clamp,
cls,
isFunction,
last,
max,
min,
times,
toInt,
}