FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interface/src/theme/utils.ts at main · lineCode/interface · GitHub
lineCode
interface
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
interface
/
src
/
theme
/
utils.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (19 loc) · 698 Bytes
Breadcrumbs
interface
/
src
/
theme
/
utils.ts
Copy path
File metadata and controls
23 lines (19 loc) · 698 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Add opacity information to a hex color
*
@param
amount opacity value from 0 to 100
*
@param
hexColor
*/
export
function
opacify
(
amount
:
number
,
hexColor
:
string
)
:
string
{
if
(
!
hexColor
.
startsWith
(
'#'
)
)
{
return
hexColor
}
if
(
hexColor
.
length
!==
7
)
{
throw
new
Error
(
`opacify: provided color
${
hexColor
}
was not in hexadecimal format (e.g. #000000)`
)
}
if
(
amount
<
0
||
amount
>
100
)
{
throw
new
Error
(
'opacify: provided amount should be between 0 and 100'
)
}
const
opacityHex
=
Math
.
round
(
(
amount
/
100
)
*
255
)
.
toString
(
16
)
const
opacifySuffix
=
opacityHex
.
length
<
2
?
`0
${
opacityHex
}
`
:
opacityHex
return
`
${
hexColor
.
slice
(
0
,
7
)
}
${
opacifySuffix
}
`
}
Back
|
FazBrowse Home
|
New Git URL