whet 0.0.15 → 0.0.18

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.
@@ -1,217 +0,0 @@
1
- import {Register} from "../../genes/Register.js"
2
- import {HxOverrides} from "../../HxOverrides.js"
3
-
4
- const $global = Register.$global
5
-
6
- /**
7
- This class provides a convenient way of working with paths. It supports the
8
- common path formats:
9
-
10
- - `directory1/directory2/filename.extension`
11
- - `directory1\directory2\filename.extension`
12
- */
13
- export const Path = Register.global("$hxClasses")["haxe.io.Path"] =
14
- class Path extends Register.inherits() {
15
- new(path) {
16
- switch (path) {
17
- case ".":case "..":
18
- this.dir = path;
19
- this.file = "";
20
- return;
21
- break
22
-
23
- };
24
- var c1 = path.lastIndexOf("/");
25
- var c2 = path.lastIndexOf("\\");
26
- if (c1 < c2) {
27
- this.dir = HxOverrides.substr(path, 0, c2);
28
- path = HxOverrides.substr(path, c2 + 1, null);
29
- this.backslash = true;
30
- } else if (c2 < c1) {
31
- this.dir = HxOverrides.substr(path, 0, c1);
32
- path = HxOverrides.substr(path, c1 + 1, null);
33
- } else {
34
- this.dir = null;
35
- };
36
- var cp = path.lastIndexOf(".");
37
- if (cp != -1) {
38
- this.ext = HxOverrides.substr(path, cp + 1, null);
39
- this.file = HxOverrides.substr(path, 0, cp);
40
- } else {
41
- this.ext = null;
42
- this.file = path;
43
- };
44
- }
45
-
46
- /**
47
- Returns a String representation of `this` path.
48
-
49
- If `this.backslash` is `true`, backslash is used as directory separator,
50
- otherwise slash is used. This only affects the separator between
51
- `this.dir` and `this.file`.
52
-
53
- If `this.directory` or `this.extension` is `null`, their representation
54
- is the empty String `""`.
55
- */
56
- toString() {
57
- return ((this.dir == null) ? "" : this.dir + ((this.backslash) ? "\\" : "/")) + this.file + ((this.ext == null) ? "" : "." + this.ext);
58
- }
59
-
60
- /**
61
- Returns the String representation of `path` without the directory.
62
-
63
- If `path` is `null`, the result is unspecified.
64
- */
65
- static withoutDirectory(path) {
66
- var s = new Path(path);
67
- s.dir = null;
68
- return s.toString();
69
- }
70
-
71
- /**
72
- Returns the directory of `path`.
73
-
74
- If the directory is `null`, the empty String `""` is returned.
75
-
76
- If `path` is `null`, the result is unspecified.
77
- */
78
- static directory(path) {
79
- var s = new Path(path);
80
- if (s.dir == null) {
81
- return "";
82
- };
83
- return s.dir;
84
- }
85
-
86
- /**
87
- Returns the extension of `path`.
88
-
89
- If `path` has no extension, the empty String `""` is returned.
90
-
91
- If `path` is `null`, the result is unspecified.
92
- */
93
- static extension(path) {
94
- var s = new Path(path);
95
- if (s.ext == null) {
96
- return "";
97
- };
98
- return s.ext;
99
- }
100
-
101
- /**
102
- Normalize a given `path` (e.g. turn `'/usr/local/../lib'` into `'/usr/lib'`).
103
-
104
- Also replaces backslashes `\` with slashes `/` and afterwards turns
105
- multiple slashes into a single one.
106
-
107
- If `path` is `null`, the result is unspecified.
108
- */
109
- static normalize(path) {
110
- var slash = "/";
111
- path = path.split("\\").join(slash);
112
- if (path == slash) {
113
- return slash;
114
- };
115
- var target = [];
116
- var _g = 0;
117
- var _g1 = path.split(slash);
118
- while (_g < _g1.length) {
119
- var token = _g1[_g];
120
- ++_g;
121
- if (token == ".." && target.length > 0 && target[target.length - 1] != "..") {
122
- target.pop();
123
- } else if (token == "") {
124
- if (target.length > 0 || HxOverrides.cca(path, 0) == 47) {
125
- target.push(token);
126
- };
127
- } else if (token != ".") {
128
- target.push(token);
129
- };
130
- };
131
- var acc_b = "";
132
- var colon = false;
133
- var slashes = false;
134
- var _g2_offset = 0;
135
- var _g2_s = target.join(slash);
136
- while (_g2_offset < _g2_s.length) {
137
- var s = _g2_s;
138
- var index = _g2_offset++;
139
- var c = s.charCodeAt(index);
140
- if (c >= 55296 && c <= 56319) {
141
- c = c - 55232 << 10 | s.charCodeAt(index + 1) & 1023;
142
- };
143
- var c1 = c;
144
- if (c1 >= 65536) {
145
- ++_g2_offset;
146
- };
147
- var c2 = c1;
148
- switch (c2) {
149
- case 47:
150
- if (!colon) {
151
- slashes = true;
152
- } else {
153
- var i = c2;
154
- colon = false;
155
- if (slashes) {
156
- acc_b += "/";
157
- slashes = false;
158
- };
159
- acc_b += String.fromCodePoint(i);
160
- };
161
- break
162
- case 58:
163
- acc_b += ":";
164
- colon = true;
165
- break
166
- default:
167
- var i1 = c2;
168
- colon = false;
169
- if (slashes) {
170
- acc_b += "/";
171
- slashes = false;
172
- };
173
- acc_b += String.fromCodePoint(i1);
174
-
175
- };
176
- };
177
- return acc_b;
178
- }
179
-
180
- /**
181
- Adds a trailing slash to `path`, if it does not have one already.
182
-
183
- If the last slash in `path` is a backslash, a backslash is appended to
184
- `path`.
185
-
186
- If the last slash in `path` is a slash, or if no slash is found, a slash
187
- is appended to `path`. In particular, this applies to the empty String
188
- `""`.
189
-
190
- If `path` is `null`, the result is unspecified.
191
- */
192
- static addTrailingSlash(path) {
193
- if (path.length == 0) {
194
- return "/";
195
- };
196
- var c1 = path.lastIndexOf("/");
197
- var c2 = path.lastIndexOf("\\");
198
- if (c1 < c2) {
199
- if (c2 != path.length - 1) {
200
- return path + "\\";
201
- } else {
202
- return path;
203
- };
204
- } else if (c1 != path.length - 1) {
205
- return path + "/";
206
- } else {
207
- return path;
208
- };
209
- }
210
- static get __name__() {
211
- return "haxe.io.Path"
212
- }
213
- get __class__() {
214
- return Path
215
- }
216
- }
217
-
@@ -1,13 +0,0 @@
1
- import {RouteResult} from "../route/RouteResult"
2
- import {Route, RouteData} from "../route/Route"
3
- import {MaybeArray} from "./MaybeArray"
4
- import {AnyStone} from "../Stone"
5
-
6
- /**
7
- * Anything that can be transformed into `Route`.
8
- */
9
- export type RouteType = Route | MaybeArray<MaybeArray<BaseRouteType>>
10
-
11
- export type BaseRouteType = RouteResult | string | AnyStone
12
-
13
- export const makeRoute: (routeType: RouteType) => Route
@@ -1,104 +0,0 @@
1
- import {Files} from "../stones/Files.js"
2
- import {RouteResult} from "../route/RouteResult.js"
3
- import {Route} from "../route/Route.js"
4
- import {MaybeArray_Fields_} from "./MaybeArray.js"
5
- import {Stone} from "../Stone.js"
6
- import {SourceId} from "../SourceId.js"
7
- import * as Path from "path"
8
- import {Register} from "../../genes/Register.js"
9
- import {StringTools} from "../../StringTools.js"
10
- import {Std} from "../../Std.js"
11
- import {HxOverrides} from "../../HxOverrides.js"
12
-
13
- const $global = Register.$global
14
-
15
- export const RouteType_Fields_ = Register.global("$hxClasses")["whet.magic._RouteType.RouteType_Fields_"] =
16
- class RouteType_Fields_ {
17
- static makeRoute(routeType) {
18
- if (((routeType) instanceof Route)) {
19
- return routeType;
20
- } else {
21
- return new Route(routeType);
22
- };
23
- }
24
- static makeRouteRoutes(routeType) {
25
- var _g = [];
26
- var _g1 = 0;
27
- var _g2 = MaybeArray_Fields_.makeArray(routeType);
28
- while (_g1 < _g2.length) {
29
- var tinner = MaybeArray_Fields_.makeArray(_g2[_g1++]);
30
- if (tinner.length == 1) {
31
- _g.push(RouteType_Fields_.getRoute(tinner[0]));
32
- } else if (tinner.length == 2) {
33
- if (typeof(tinner[1]) != "string") {
34
- throw new Error("Array-defined route's second element should be path (a string).");
35
- };
36
- var tinner1 = tinner[0];
37
- var s = tinner[1];
38
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
39
- if (str.length > 0) {
40
- str = Path.posix.normalize(str);
41
- str = StringTools.replace(str, "\\", "/");
42
- };
43
- s = str;
44
- _g.push(RouteType_Fields_.getRoute(tinner1, (HxOverrides.cca(s, 0) == 47) ? s : "/" + s));
45
- };
46
- };
47
- return _g;
48
- }
49
- static getRoute(t, path) {
50
- if (typeof(t) == "string") {
51
- var tmp = new Files({"paths": [t]});
52
- var tmp1;
53
- if (path != null) {
54
- tmp1 = path;
55
- } else {
56
- var s = t;
57
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
58
- if (str.length > 0) {
59
- str = Path.posix.normalize(str);
60
- str = StringTools.replace(str, "\\", "/");
61
- };
62
- s = str;
63
- var p = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
64
- var s = p.substring(0, p.lastIndexOf("/") + 1);
65
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
66
- if (str.length > 0) {
67
- str = Path.posix.normalize(str);
68
- str = StringTools.replace(str, "\\", "/");
69
- };
70
- s = str;
71
- tmp1 = SourceId.relativeTo(p, (HxOverrides.cca(s, 0) == 47) ? s : "/" + s);
72
- };
73
- return {"stone": tmp, "path": tmp1};
74
- } else if (((t) instanceof Stone)) {
75
- var tmp;
76
- if (path != null) {
77
- tmp = path;
78
- } else {
79
- var s = "/";
80
- var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
81
- if (str.length > 0) {
82
- str = Path.posix.normalize(str);
83
- str = StringTools.replace(str, "\\", "/");
84
- };
85
- s = str;
86
- tmp = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
87
- };
88
- return {"stone": t, "path": tmp};
89
- } else if (((t) instanceof RouteResult)) {
90
- return {"stone": t.source, "path": t.sourceId};
91
- } else {
92
- throw new Error("Unsupported type for Route. Expected String, Stone or RouteResult, but got " + Std.string(t.constructor?.name) + ".");
93
- };
94
- }
95
- static get __name__() {
96
- return "whet.magic._RouteType.RouteType_Fields_"
97
- }
98
- get __class__() {
99
- return RouteType_Fields_
100
- }
101
- }
102
-
103
-
104
- export const makeRoute = RouteType_Fields_.makeRoute
@@ -1,19 +0,0 @@
1
- import {RouteResult} from "./RouteResult"
2
- import {RouteType} from "../magic/RouteType"
3
- import {AnyStone} from "../Stone"
4
- import {SourceHash} from "../SourceHash"
5
- import {SourceData} from "../Source"
6
-
7
- export declare class Route {
8
- constructor(route: RouteType)
9
- protected routes: RouteData[]
10
- add(r: RouteType): Route
11
- getHash(): Promise<SourceHash>
12
- list(): Promise<RouteResult[]>
13
- getData(): Promise<SourceData[]>
14
- }
15
-
16
- export type RouteData = {
17
- path: string,
18
- stone: AnyStone
19
- }
@@ -1,121 +0,0 @@
1
- import {RouteResult} from "./RouteResult.js"
2
- import {RouteType_Fields_} from "../magic/RouteType.js"
3
- import {SourceId} from "../SourceId.js"
4
- import {SourceHash} from "../SourceHash.js"
5
- import * as Path from "path"
6
- import {Register} from "../../genes/Register.js"
7
- import {StringTools} from "../../StringTools.js"
8
- import {HxOverrides} from "../../HxOverrides.js"
9
-
10
- const $global = Register.$global
11
-
12
- export const Route = Register.global("$hxClasses")["whet.route.Route"] =
13
- class Route extends Register.inherits() {
14
- new(route) {
15
- this.routes = (((route) instanceof Route)) ? route.routes.slice() : RouteType_Fields_.makeRouteRoutes(route);
16
- }
17
- add(r) {
18
- var _g = 0;
19
- var _g1 = RouteType_Fields_.makeRoute(r).routes;
20
- while (_g < _g1.length) this.routes.push(_g1[_g++]);
21
- return this;
22
- }
23
- getHash() {
24
- var _this = this.routes;
25
- var result = new Array(_this.length);
26
- var _g = 0;
27
- var _g1 = _this.length;
28
- while (_g < _g1) {
29
- var i = _g++;
30
- result[i] = _this[i].stone.getHash();
31
- };
32
- return Promise.all(result).then(function (hashes) {
33
- return SourceHash.merge(...hashes);
34
- });
35
- }
36
- list() {
37
- var _g = [];
38
- var _g1 = 0;
39
- var _g2 = this.routes;
40
- while (_g1 < _g2.length) {
41
- var r = [_g2[_g1]];
42
- ++_g1;
43
- _g.push(r[0].stone.list().then((function (r) {
44
- return function (list) {
45
- var arr = [];
46
- var this1 = r[0].path;
47
- if (HxOverrides.cca(this1, this1.length - 1) == 47) {
48
- var _g = 0;
49
- while (_g < list.length) {
50
- var path = list[_g];
51
- ++_g;
52
- var directory = r[0].path;
53
- if (HxOverrides.cca(directory, directory.length - 1) != 47) {
54
- throw new Error("\"" + directory + "\" is not a directory.");
55
- };
56
- var tmp;
57
- var s = path.substring(0, path.lastIndexOf("/") + 1);
58
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
59
- if (str.length > 0) {
60
- str = Path.posix.normalize(str);
61
- str = StringTools.replace(str, "\\", "/");
62
- };
63
- s = str;
64
- tmp = ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s).indexOf(directory) == 0;
65
- if (tmp) {
66
- var _g1 = r[0].stone;
67
- arr.push(new RouteResult(SourceId.relativeTo(path, r[0].path), path, _g1));
68
- };
69
- };
70
- } else {
71
- var _g = 0;
72
- while (_g < list.length) {
73
- var path = list[_g];
74
- ++_g;
75
- if (path == r[0].path) {
76
- var _g1 = r[0].stone;
77
- var s = path.substring(path.lastIndexOf("/"));
78
- var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
79
- if (str.length > 0) {
80
- str = Path.posix.normalize(str);
81
- str = StringTools.replace(str, "\\", "/");
82
- };
83
- s = str;
84
- arr.push(new RouteResult((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, path, _g1));
85
- };
86
- };
87
- };
88
- return arr;
89
- };
90
- })(r)));
91
- };
92
- return Promise.all(_g).then(function (data) {
93
- var _g = [];
94
- var _g_current = 0;
95
- while (_g_current < data.length) {
96
- var x = Register.iter(data[_g_current++]);
97
- while (x.hasNext()) _g.push(x.next());
98
- };
99
- return _g;
100
- });
101
- }
102
- getData() {
103
- return this.list().then(function (l) {
104
- var result = new Array(l.length);
105
- var _g = 0;
106
- var _g1 = l.length;
107
- while (_g < _g1) {
108
- var i = _g++;
109
- result[i] = l[i].get();
110
- };
111
- return Promise.all(result);
112
- });
113
- }
114
- static get __name__() {
115
- return "whet.route.Route"
116
- }
117
- get __class__() {
118
- return Route
119
- }
120
- }
121
-