-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathutils.js
35 lines (30 loc) · 796 Bytes
/
utils.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
export const calculateRgba = (input, opacity) => {
let color
if (input[0] === `#`) {
color = input.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]))