FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leanplum-JavaScript-SDK/src/ValueTransforms.ts at develop · Leanplum/Leanplum-JavaScript-SDK · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Leanplum
/
Leanplum-JavaScript-SDK
Public
Notifications
You must be signed in to change notification settings
Fork
14
Star
7
Code
Issues
1
Pull requests
10
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
Leanplum-JavaScript-SDK
/
src
/
ValueTransforms.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (34 loc) · 1.15 KB
Breadcrumbs
Leanplum-JavaScript-SDK
/
src
/
ValueTransforms.ts
Copy path
File metadata and controls
40 lines (34 loc) · 1.15 KB
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export
default
class
ValueTransforms
{
public
static
decodeColor
(
color
:
number
)
:
string
{
const
b
=
color
&
0xff
;
color
>>=
8
const
g
=
color
&
0xff
;
color
>>=
8
const
r
=
color
&
0xff
;
color
>>=
8
const
a
=
(
color
&
0xff
)
/
255
return
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
}
)`
}
public
static
encodeColor
(
color
:
string
|
number
)
:
number
{
if
(
typeof
color
===
'number'
)
{
return
color
}
// rgba -> number
const
rgbaRe
=
/
^
r
g
b
a
\(
(
\d
+
)
,
(
\d
+
)
,
(
\d
+
)
,
(
\d
+
(
\.
\d
+
)
?
)
\)
$
/
const
rgba
=
rgbaRe
.
exec
(
color
)
if
(
rgba
)
{
const
a
=
parseInt
(
rgba
[
4
]
,
10
)
*
255
const
r
=
parseInt
(
rgba
[
1
]
,
10
)
&
0xff
const
g
=
parseInt
(
rgba
[
2
]
,
10
)
&
0xff
const
b
=
parseInt
(
rgba
[
3
]
,
10
)
&
0xff
return
(
a
<<
24
)
+
(
r
<<
16
)
+
(
g
<<
8
)
+
b
}
// hex -> number
const
hexRe
=
/
^
#
(
[
0
-
9
a
-
f
]
{
2
}
)
(
[
0
-
9
a
-
f
]
{
2
}
)
(
[
0
-
9
a
-
f
]
{
2
}
)
$
/
i
const
hex
=
hexRe
.
exec
(
color
)
if
(
hex
)
{
const
r
=
parseInt
(
hex
[
1
]
,
16
)
&
0xff
const
g
=
parseInt
(
hex
[
2
]
,
16
)
&
0xff
const
b
=
parseInt
(
hex
[
3
]
,
16
)
&
0xff
return
(
255
<<
24
)
+
(
r
<<
16
)
+
(
g
<<
8
)
+
b
}
throw
new
Error
(
`Could not parse color "
${
color
}
"`
)
}
}
Back
|
FazBrowse Home
|
New Git URL