blob: be16d0ef81a0dfe8a3a7fef9ed6faeacd4f671f3 (
plain)
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
|
let format_float precision f =
let str = Js.Float.toString f in
match Js.String.split "." str with
| [| a ; b |] -> a ^ "." ^ (Js.String.substring ~from:0 ~to_:precision b)
| _ -> str
external btoa : string -> string = "btoa"
[@@bs.val] [@@bs.scope "window"]
external atob : string -> string = "atob"
[@@bs.val] [@@bs.scope "window"]
external unescape : string -> string = "unescape"
[@@bs.val]
external escape : string -> string = "escape"
[@@bs.val]
external encodeURIComponent : string -> string = "encodeURIComponent"
[@@bs.val]
external decodeURIComponent : string -> string = "decodeURIComponent"
[@@bs.val]
let encode str =
str
|> encodeURIComponent
|> unescape
|> btoa
let decode str =
str
|> atob
|> escape
|> decodeURIComponent
|