-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.js
More file actions
executable file
·56 lines (49 loc) · 1.45 KB
/
utility.js
File metadata and controls
executable file
·56 lines (49 loc) · 1.45 KB
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
const CSS_CLASS_SEPARATOR = " ";
/**
* Creates className from attributes joined with class separator.
* @param classes Array
* @param separator string
* @return string
*/
export function createClassName(...classes) {
return classes.filter((item) => item).join(CSS_CLASS_SEPARATOR);
}
export function clamp(number, lowerBound, upperBound) {
number = Math.min(number, upperBound);
number = Math.max(number, lowerBound);
return number;
}
export function omit(object, key) {
const result = Object.assign({}, object);
if (Array.isArray(key)) {
key.forEach((item) => {
delete result[item];
});
} else {
delete result[key];
}
return result;
}
export const without = (array, index) =>
index < 0 ? array : [...array.slice(0, index), ...array.slice(index + 1)];
// get the last 6 digits of this base 36 number (fraction)
export const generateRandomKey = () => Math.random().toString(36).slice(-6);
export const generateRandomKeys = (count, exceptions = []) => {
const keys = [];
while (count) {
const randomKey = generateRandomKey();
if (exceptions.includes(randomKey)) {
continue;
}
keys.push(randomKey);
--count;
}
if (keys.length === 1) {
return keys[0];
}
return keys;
};
export const todoOccurrenceCount = (lists, todoId) =>
Object.keys(lists)
.map((key) => lists[key].todoIds.includes(todoId))
.reduce((sum, value) => sum + value, 0);