liquidsoap-prettier 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/dune +7 -0
- package/dist/liquidsoap.cjs +220506 -0
- package/dist/web.mjs +1 -0
- package/dune-project +2 -0
- package/package.json +32 -0
- package/src/cli.js +72 -0
- package/src/dune +8 -0
- package/src/index.js +739 -0
- package/src/liquidsoap_js.ml +17 -0
- package/src/regexp_js.ml +57 -0
- package/src/regexp_js.mli +4 -0
- package/webpack.web.cjs +17 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
open Js_of_ocaml
|
|
2
|
+
open Liquidsoap_lang
|
|
3
|
+
|
|
4
|
+
let () =
|
|
5
|
+
Hooks.regexp := Regexp_js.make
|
|
6
|
+
|
|
7
|
+
let parse content =
|
|
8
|
+
let content = Js.to_string content in
|
|
9
|
+
let json = Liquidsoap_tooling.Parsed_json.parse_string content in
|
|
10
|
+
Js._JSON##parse
|
|
11
|
+
(Js.string (Liquidsoap_lang.Json.to_string ~compact:true json))
|
|
12
|
+
|
|
13
|
+
let _ =
|
|
14
|
+
Js.export "lang"
|
|
15
|
+
(object%js
|
|
16
|
+
method parse = parse
|
|
17
|
+
end)
|
package/src/regexp_js.ml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
open Js_of_ocaml
|
|
2
|
+
|
|
3
|
+
type sub = Liquidsoap_lang.Regexp.sub = {
|
|
4
|
+
matches : string option list;
|
|
5
|
+
groups : (string * string) list;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class type match_result =
|
|
9
|
+
object
|
|
10
|
+
inherit Js.match_result
|
|
11
|
+
method groups : Js.Unsafe.any Js.optdef Js.readonly_prop
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let string_of_flag = function `i -> "i" | `g -> "g" | `s -> "s" | `m -> "m"
|
|
15
|
+
|
|
16
|
+
let flags_of_flags flags =
|
|
17
|
+
Js.string (String.concat "" (List.map string_of_flag flags))
|
|
18
|
+
|
|
19
|
+
let make ?(flags = []) s =
|
|
20
|
+
let rex = new%js Js.regExp_withFlags (Js.string s) (flags_of_flags flags) in
|
|
21
|
+
object
|
|
22
|
+
method split s =
|
|
23
|
+
let split = (Js.string s)##split_regExp rex in
|
|
24
|
+
let split = Js.str_array split in
|
|
25
|
+
Array.to_list (Array.map Js.to_string (Js.to_array split))
|
|
26
|
+
|
|
27
|
+
method exec s =
|
|
28
|
+
let s = Js.string s in
|
|
29
|
+
let ret =
|
|
30
|
+
Js.Opt.case (rex##exec s) (fun () -> raise Not_found) (fun x -> x)
|
|
31
|
+
in
|
|
32
|
+
let sub : match_result Js.t = Js.Unsafe.coerce (Js.match_result ret) in
|
|
33
|
+
let matches =
|
|
34
|
+
List.init sub##.length (fun pos ->
|
|
35
|
+
Option.map Js.to_string (Js.Optdef.to_option (Js.array_get sub pos)))
|
|
36
|
+
in
|
|
37
|
+
let groups =
|
|
38
|
+
Js.Optdef.case sub##.groups
|
|
39
|
+
(fun () -> [])
|
|
40
|
+
(fun groups ->
|
|
41
|
+
let names = Js.to_array (Js.object_keys groups) in
|
|
42
|
+
Array.fold_left
|
|
43
|
+
(fun cur key ->
|
|
44
|
+
Js.Optdef.case (Js.Unsafe.get groups key)
|
|
45
|
+
(fun () -> cur)
|
|
46
|
+
(fun value -> (Js.to_string key, Js.to_string value) :: cur))
|
|
47
|
+
[] names)
|
|
48
|
+
in
|
|
49
|
+
{ matches; groups }
|
|
50
|
+
|
|
51
|
+
method test s = Js.to_bool (rex##test (Js.string s))
|
|
52
|
+
|
|
53
|
+
method substitute ~subst s =
|
|
54
|
+
let subst a = Js.string (subst (Js.to_string a)) in
|
|
55
|
+
let subst = Js.wrap_callback subst in
|
|
56
|
+
Js.to_string ((Js.Unsafe.coerce (Js.string s))##replace rex subst)
|
|
57
|
+
end
|
package/webpack.web.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
entry: "./src/index.js",
|
|
3
|
+
mode: "production",
|
|
4
|
+
resolve: {
|
|
5
|
+
fallback: { child_process: false, constants: false, fs: false, tty: false },
|
|
6
|
+
},
|
|
7
|
+
experiments: {
|
|
8
|
+
outputModule: true,
|
|
9
|
+
},
|
|
10
|
+
output: {
|
|
11
|
+
path: __dirname + "/dist",
|
|
12
|
+
filename: "web.mjs",
|
|
13
|
+
library: {
|
|
14
|
+
type: "module",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|