forked from Schum123/svelte-loading-spinners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
36 lines (29 loc) · 877 Bytes
/
utils.ts
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
export const durationUnitRegex = /[a-zA-Z]/;
export const calculateRgba = (color, opacity) => {
if (color[0] === "#") {
color = color.slice(1);
}
if (color.length === 3) {
let res = "";
color.split("").forEach((c) => {
res += c;
res += c;
});
color = res;
}
const rgbValues = (color.match(/.{2}/g) || [])
.map((hex) => parseInt(hex, 16))
.join(", ");
return `rgba(${rgbValues}, ${opacity})`;
};
export const range = (size, startAt = 0) =>
[...Array(size).keys()].map(i => i + startAt);
// export const characterRange = (startChar, endChar) =>
// String.fromCharCode(
// ...range(
// endChar.charCodeAt(0) - startChar.charCodeAt(0),
// startChar.charCodeAt(0)
// )
// );
// export const zip = (arr, ...arrs) =>
// arr.map((val, i) => arrs.reduce((list, curr) => [...list, curr[i]], [val]));