Christian Fraß commited on 2021-03-12 00:49:43
Zeige 8 geänderte Dateien mit 102 Einfügungen und 8128 Löschungen.
... | ... |
@@ -1,43 +0,0 @@ |
1 |
-<!DOCTYPE HTML> |
|
2 |
-<html> |
|
3 |
- <head> |
|
4 |
- <meta charset="utf-8"/> |
|
5 |
- <link rel="stylesheet" type="text/css" href="style.css"/> |
|
6 |
- <script type="text/javascript" src="logic.js"></script> |
|
7 |
- </head> |
|
8 |
- <body> |
|
9 |
- <select name="language_from"> |
|
10 |
- <option value="_">*</option> |
|
11 |
- <option value="afr">afr</option> |
|
12 |
- <option value="dan">dan</option> |
|
13 |
- <option value="deu">deu</option> |
|
14 |
- <option value="eng">eng</option> |
|
15 |
- <option value="flk">flk</option> |
|
16 |
- <option value="gem">gem</option> |
|
17 |
- <option value="isl">isl</option> |
|
18 |
- <option value="nld">nld</option> |
|
19 |
- <option value="nob">nob</option> |
|
20 |
- <option value="swe">swe</option> |
|
21 |
- <option value="yid">yid</option> |
|
22 |
- </select> |
|
23 |
- <select name="language_to"> |
|
24 |
- <option value="_">*</option> |
|
25 |
- <option value="afr">afr</option> |
|
26 |
- <option value="dan">dan</option> |
|
27 |
- <option value="deu">deu</option> |
|
28 |
- <option value="eng">eng</option> |
|
29 |
- <option value="flk">flk</option> |
|
30 |
- <option value="gem">gem</option> |
|
31 |
- <option value="isl">isl</option> |
|
32 |
- <option value="nld">nld</option> |
|
33 |
- <option value="nob">nob</option> |
|
34 |
- <option value="swe">swe</option> |
|
35 |
- <option value="yid">yid</option> |
|
36 |
- </select> |
|
37 |
- <input type="text" name="token"/> |
|
38 |
- <button>query</button> |
|
39 |
- <ul id="result"> |
|
40 |
- </ul> |
|
41 |
- </body> |
|
42 |
-</html> |
|
43 |
- |
... | ... |
@@ -1,8076 +0,0 @@ |
1 |
-var __extends = (this && this.__extends) || (function () { |
|
2 |
- var extendStatics = function (d, b) { |
|
3 |
- extendStatics = Object.setPrototypeOf || |
|
4 |
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
5 |
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
|
6 |
- return extendStatics(d, b); |
|
7 |
- }; |
|
8 |
- return function (d, b) { |
|
9 |
- extendStatics(d, b); |
|
10 |
- function __() { this.constructor = d; } |
|
11 |
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
12 |
- }; |
|
13 |
-})(); |
|
14 |
-/* |
|
15 |
-This file is part of »bacterio-plankton:base«. |
|
16 |
- |
|
17 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
18 |
-<info@greenscale.de> |
|
19 |
- |
|
20 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
21 |
-it under the terms of the GNU Lesser General Public License as published by |
|
22 |
-the Free Software Foundation, either version 3 of the License, or |
|
23 |
-(at your option) any later version. |
|
24 |
- |
|
25 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
26 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28 |
-GNU Lesser General Public License for more details. |
|
29 |
- |
|
30 |
-You should have received a copy of the GNU Lesser General Public License |
|
31 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
32 |
- */ |
|
33 |
-// } |
|
34 |
-/* |
|
35 |
-This file is part of »bacterio-plankton:base«. |
|
36 |
- |
|
37 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
38 |
-<info@greenscale.de> |
|
39 |
- |
|
40 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
41 |
-it under the terms of the GNU Lesser General Public License as published by |
|
42 |
-the Free Software Foundation, either version 3 of the License, or |
|
43 |
-(at your option) any later version. |
|
44 |
- |
|
45 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
46 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
47 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
48 |
-GNU Lesser General Public License for more details. |
|
49 |
- |
|
50 |
-You should have received a copy of the GNU Lesser General Public License |
|
51 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
52 |
- */ |
|
53 |
-/** |
|
54 |
- * @author fenris |
|
55 |
- */ |
|
56 |
-/*export*/ function pseudopointer_null() { |
|
57 |
- return { |
|
58 |
- "value": null |
|
59 |
- }; |
|
60 |
-} |
|
61 |
-/** |
|
62 |
- * @author fenris |
|
63 |
- */ |
|
64 |
-/*export*/ function pseudopointer_make(value) { |
|
65 |
- return { |
|
66 |
- "value": value |
|
67 |
- }; |
|
68 |
-} |
|
69 |
-/** |
|
70 |
- * @author fenris |
|
71 |
- */ |
|
72 |
-/*export*/ function pseudopointer_isset(pseudopointer) { |
|
73 |
- return (pseudopointer.value != null); |
|
74 |
-} |
|
75 |
-/** |
|
76 |
- * @author fenris |
|
77 |
- */ |
|
78 |
-/*export*/ function pseudopointer_read(pseudopointer) { |
|
79 |
- if (pseudopointer.value != null) { |
|
80 |
- return pseudopointer.value; |
|
81 |
- } |
|
82 |
- else { |
|
83 |
- var message = "nullpointer dereferencation"; |
|
84 |
- throw (new Error(message)); |
|
85 |
- } |
|
86 |
-} |
|
87 |
-/** |
|
88 |
- * @author fenris |
|
89 |
- */ |
|
90 |
-/*export*/ function pseudopointer_write(pseudopointer, value) { |
|
91 |
- pseudopointer.value = value; |
|
92 |
-} |
|
93 |
-/* |
|
94 |
-This file is part of »bacterio-plankton:base«. |
|
95 |
- |
|
96 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
97 |
-<info@greenscale.de> |
|
98 |
- |
|
99 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
100 |
-it under the terms of the GNU Lesser General Public License as published by |
|
101 |
-the Free Software Foundation, either version 3 of the License, or |
|
102 |
-(at your option) any later version. |
|
103 |
- |
|
104 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
105 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
106 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
107 |
-GNU Lesser General Public License for more details. |
|
108 |
- |
|
109 |
-You should have received a copy of the GNU Lesser General Public License |
|
110 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
111 |
- */ |
|
112 |
-; |
|
113 |
-var lib_base; |
|
114 |
-(function (lib_base) { |
|
115 |
- /** |
|
116 |
- * @author fenris |
|
117 |
- */ |
|
118 |
- function environment() { |
|
119 |
- var entries = [ |
|
120 |
- { |
|
121 |
- "id": "web", |
|
122 |
- "name": "Web", |
|
123 |
- "predicate": function () { return (typeof (document) !== "undefined"); }, |
|
124 |
- }, |
|
125 |
- { |
|
126 |
- "id": "node", |
|
127 |
- "name": "Node.js", |
|
128 |
- "predicate": function () { return (typeof (process) !== "undefined"); }, |
|
129 |
- }, |
|
130 |
- { |
|
131 |
- "id": "rhino", |
|
132 |
- "name": "Rhino", |
|
133 |
- "predicate": function () { return (typeof (java) !== "undefined"); }, |
|
134 |
- }, |
|
135 |
- { |
|
136 |
- "id": "webworker", |
|
137 |
- "name": "WebWorker", |
|
138 |
- "predicate": function () { return (typeof (self["WorkerNavigator"]) !== "undefined"); } |
|
139 |
- } |
|
140 |
- ]; |
|
141 |
- var id; |
|
142 |
- var found = entries.some(function (entry) { |
|
143 |
- if (entry.predicate()) { |
|
144 |
- id = entry.id; |
|
145 |
- return true; |
|
146 |
- } |
|
147 |
- else { |
|
148 |
- return false; |
|
149 |
- } |
|
150 |
- }); |
|
151 |
- if (found) { |
|
152 |
- return id; |
|
153 |
- } |
|
154 |
- else { |
|
155 |
- throw (new Error("unknown environment")); |
|
156 |
- } |
|
157 |
- } |
|
158 |
- lib_base.environment = environment; |
|
159 |
-})(lib_base || (lib_base = {})); |
|
160 |
-/* |
|
161 |
-This file is part of »bacterio-plankton:base«. |
|
162 |
- |
|
163 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
164 |
-<info@greenscale.de> |
|
165 |
- |
|
166 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
167 |
-it under the terms of the GNU Lesser General Public License as published by |
|
168 |
-the Free Software Foundation, either version 3 of the License, or |
|
169 |
-(at your option) any later version. |
|
170 |
- |
|
171 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
172 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
173 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
174 |
-GNU Lesser General Public License for more details. |
|
175 |
- |
|
176 |
-You should have received a copy of the GNU Lesser General Public License |
|
177 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
178 |
- */ |
|
179 |
-/** |
|
180 |
- * @author fenris |
|
181 |
- */ |
|
182 |
-var instance_verbosity = 0; |
|
183 |
-/** |
|
184 |
- * @author fenris |
|
185 |
- */ |
|
186 |
-function instance_collate(value1, value2) { |
|
187 |
- if (typeof (value1) === "object") { |
|
188 |
- if (value1 == null) { |
|
189 |
- return (value2 == null); |
|
190 |
- } |
|
191 |
- else { |
|
192 |
- if ("_collate" in value1) { |
|
193 |
- return value1["_collate"](value2); |
|
194 |
- } |
|
195 |
- else { |
|
196 |
- throw (new Error("[collate]" + " " + "object has no such method")); |
|
197 |
- } |
|
198 |
- } |
|
199 |
- } |
|
200 |
- else { |
|
201 |
- if (instance_verbosity >= 1) { |
|
202 |
- lib_log.warn("[collate]" + " " + "primitive value; using default implementation"); |
|
203 |
- } |
|
204 |
- return (value1 === value2); |
|
205 |
- } |
|
206 |
-} |
|
207 |
-/** |
|
208 |
- * @author fenris |
|
209 |
- */ |
|
210 |
-function instance_compare(value1, value2) { |
|
211 |
- if (typeof (value1) === "object") { |
|
212 |
- if ("_compare" in value1) { |
|
213 |
- return value1["_compare"](value2); |
|
214 |
- } |
|
215 |
- else { |
|
216 |
- throw (new Error("[compare]" + " " + "object has no such method")); |
|
217 |
- } |
|
218 |
- } |
|
219 |
- else { |
|
220 |
- if (instance_verbosity >= 1) { |
|
221 |
- lib_log.warn("[compare]" + " " + "primitive value; using default implementation"); |
|
222 |
- } |
|
223 |
- return (value1 <= value2); |
|
224 |
- } |
|
225 |
-} |
|
226 |
-/** |
|
227 |
- * @author fenris |
|
228 |
- */ |
|
229 |
-function instance_clone(value) { |
|
230 |
- if (typeof (value) === "object") { |
|
231 |
- if ("_clone" in value) { |
|
232 |
- return value["_clone"](); |
|
233 |
- } |
|
234 |
- else { |
|
235 |
- throw (new Error("[clone]" + " " + "object has no such method")); |
|
236 |
- } |
|
237 |
- } |
|
238 |
- else { |
|
239 |
- if (instance_verbosity >= 1) { |
|
240 |
- lib_log.warn("[clone]" + " " + "primitive value; using default implementation"); |
|
241 |
- } |
|
242 |
- return value; |
|
243 |
- } |
|
244 |
-} |
|
245 |
-/** |
|
246 |
- * @desc the ability to generate a string out of the element, which identifies it to a high degree |
|
247 |
- * @author fenris |
|
248 |
- */ |
|
249 |
-function instance_hash(value) { |
|
250 |
- if (typeof (value) === "object") { |
|
251 |
- if ("_hash" in value) { |
|
252 |
- return value["_hash"](); |
|
253 |
- } |
|
254 |
- else { |
|
255 |
- throw (new Error("[hash]" + " " + "object has no such method")); |
|
256 |
- } |
|
257 |
- } |
|
258 |
- else { |
|
259 |
- if (instance_verbosity >= 1) { |
|
260 |
- lib_log.warn("[hash]" + " " + "primitive value; using default implementation"); |
|
261 |
- } |
|
262 |
- return String(value); |
|
263 |
- } |
|
264 |
-} |
|
265 |
-/** |
|
266 |
- * @desc the ability to map the element to a textual representation (most likely not injective) |
|
267 |
- * @author fenris |
|
268 |
- */ |
|
269 |
-function instance_show(value) { |
|
270 |
- if (typeof (value) === "object") { |
|
271 |
- if (value == null) { |
|
272 |
- return "NULL"; |
|
273 |
- } |
|
274 |
- else { |
|
275 |
- if ("_show" in value) { |
|
276 |
- return value["_show"](); |
|
277 |
- } |
|
278 |
- else { |
|
279 |
- // throw (new Error("[show]" + " " + "object has no such method")); |
|
280 |
- return JSON.stringify(value); |
|
281 |
- } |
|
282 |
- } |
|
283 |
- } |
|
284 |
- else { |
|
285 |
- if (instance_verbosity >= 1) { |
|
286 |
- lib_log.warn("[show]" + " " + "primitive value; using default implementation"); |
|
287 |
- } |
|
288 |
- return String(value); |
|
289 |
- } |
|
290 |
-} |
|
291 |
-/* |
|
292 |
-This file is part of »bacterio-plankton:base«. |
|
293 |
- |
|
294 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
295 |
-<info@greenscale.de> |
|
296 |
- |
|
297 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
298 |
-it under the terms of the GNU Lesser General Public License as published by |
|
299 |
-the Free Software Foundation, either version 3 of the License, or |
|
300 |
-(at your option) any later version. |
|
301 |
- |
|
302 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
303 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
304 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
305 |
-GNU Lesser General Public License for more details. |
|
306 |
- |
|
307 |
-You should have received a copy of the GNU Lesser General Public License |
|
308 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
309 |
- */ |
|
310 |
-/** |
|
311 |
- * @todo outsource to dedicated plankton-lib |
|
312 |
- */ |
|
313 |
-var lib_log; |
|
314 |
-(function (lib_log) { |
|
315 |
- /** |
|
316 |
- * @author fenris |
|
317 |
- */ |
|
318 |
- function log() { |
|
319 |
- var args = []; |
|
320 |
- for (var _i = 0; _i < arguments.length; _i++) { |
|
321 |
- args[_i] = arguments[_i]; |
|
322 |
- } |
|
323 |
- /*window.*/ console.log.apply(console, args); |
|
324 |
- } |
|
325 |
- lib_log.log = log; |
|
326 |
- /** |
|
327 |
- * @author fenris |
|
328 |
- */ |
|
329 |
- function info() { |
|
330 |
- var args = []; |
|
331 |
- for (var _i = 0; _i < arguments.length; _i++) { |
|
332 |
- args[_i] = arguments[_i]; |
|
333 |
- } |
|
334 |
- /*window.*/ console.info.apply(console, args); |
|
335 |
- } |
|
336 |
- lib_log.info = info; |
|
337 |
- /** |
|
338 |
- * @author fenris |
|
339 |
- */ |
|
340 |
- function warn() { |
|
341 |
- var args = []; |
|
342 |
- for (var _i = 0; _i < arguments.length; _i++) { |
|
343 |
- args[_i] = arguments[_i]; |
|
344 |
- } |
|
345 |
- /*window.*/ console.warn.apply(console, args); |
|
346 |
- } |
|
347 |
- lib_log.warn = warn; |
|
348 |
- /** |
|
349 |
- * @author fenris |
|
350 |
- */ |
|
351 |
- function error() { |
|
352 |
- var args = []; |
|
353 |
- for (var _i = 0; _i < arguments.length; _i++) { |
|
354 |
- args[_i] = arguments[_i]; |
|
355 |
- } |
|
356 |
- /*window.*/ console.error.apply(console, args); |
|
357 |
- } |
|
358 |
- lib_log.error = error; |
|
359 |
-})(lib_log || (lib_log = {})); |
|
360 |
-/* |
|
361 |
-This file is part of »bacterio-plankton:base«. |
|
362 |
- |
|
363 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
364 |
-<info@greenscale.de> |
|
365 |
- |
|
366 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
367 |
-it under the terms of the GNU Lesser General Public License as published by |
|
368 |
-the Free Software Foundation, either version 3 of the License, or |
|
369 |
-(at your option) any later version. |
|
370 |
- |
|
371 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
372 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
373 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
374 |
-GNU Lesser General Public License for more details. |
|
375 |
- |
|
376 |
-You should have received a copy of the GNU Lesser General Public License |
|
377 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
378 |
- */ |
|
379 |
-/** |
|
380 |
- * @author frac |
|
381 |
- */ |
|
382 |
-var class_observer = /** @class */ (function () { |
|
383 |
- /** |
|
384 |
- * @author frac |
|
385 |
- */ |
|
386 |
- function class_observer() { |
|
387 |
- this.counter = 0; |
|
388 |
- this.actions = {}; |
|
389 |
- this.buffer = []; |
|
390 |
- } |
|
391 |
- /** |
|
392 |
- * @author frac |
|
393 |
- */ |
|
394 |
- class_observer.prototype.empty = function () { |
|
395 |
- return (Object.keys(this.actions).length == 0); |
|
396 |
- }; |
|
397 |
- /** |
|
398 |
- * @author frac |
|
399 |
- */ |
|
400 |
- class_observer.prototype.flush = function () { |
|
401 |
- this.actions = {}; |
|
402 |
- }; |
|
403 |
- /** |
|
404 |
- * @author frac |
|
405 |
- */ |
|
406 |
- class_observer.prototype.set = function (id, action) { |
|
407 |
- this.actions[id] = action; |
|
408 |
- }; |
|
409 |
- /** |
|
410 |
- * @author frac |
|
411 |
- */ |
|
412 |
- class_observer.prototype.del = function (id) { |
|
413 |
- delete this.actions[id]; |
|
414 |
- }; |
|
415 |
- /** |
|
416 |
- * @author frac |
|
417 |
- */ |
|
418 |
- class_observer.prototype.add = function (action) { |
|
419 |
- this.set((this.counter++).toString(), action); |
|
420 |
- }; |
|
421 |
- /** |
|
422 |
- * @author frac |
|
423 |
- */ |
|
424 |
- class_observer.prototype.notify = function (information, delayed) { |
|
425 |
- var _this = this; |
|
426 |
- if (information === void 0) { information = {}; } |
|
427 |
- if (delayed === void 0) { delayed = false; } |
|
428 |
- if (delayed) { |
|
429 |
- this.buffer.push(information); |
|
430 |
- } |
|
431 |
- else { |
|
432 |
- Object.keys(this.actions).forEach(function (id) { return _this.actions[id](information); }); |
|
433 |
- } |
|
434 |
- }; |
|
435 |
- /** |
|
436 |
- * @author frac |
|
437 |
- */ |
|
438 |
- class_observer.prototype.rollout = function () { |
|
439 |
- var _this = this; |
|
440 |
- this.buffer.forEach(function (information) { return _this.notify(information, false); }); |
|
441 |
- this.buffer = []; |
|
442 |
- }; |
|
443 |
- return class_observer; |
|
444 |
-}()); |
|
445 |
-/** |
|
446 |
- * @author frac |
|
447 |
- */ |
|
448 |
-/* |
|
449 |
-export interface interface_readable<type_value> { |
|
450 |
- |
|
451 |
- |** |
|
452 |
- * @author frac |
|
453 |
- *| |
|
454 |
- read() : type_executor<type_value, Error>; |
|
455 |
- |
|
456 |
-} |
|
457 |
- */ |
|
458 |
-/** |
|
459 |
- * @author frac |
|
460 |
- */ |
|
461 |
-/* |
|
462 |
-export interface interface_writeable<type_value> { |
|
463 |
- |
|
464 |
- |** |
|
465 |
- * @author frac |
|
466 |
- *| |
|
467 |
- write(value : type_value) : type_executor<void, Error>; |
|
468 |
- |
|
469 |
-} |
|
470 |
- */ |
|
471 |
-/* |
|
472 |
-This file is part of »bacterio-plankton:base«. |
|
473 |
- |
|
474 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
475 |
-<info@greenscale.de> |
|
476 |
- |
|
477 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
478 |
-it under the terms of the GNU Lesser General Public License as published by |
|
479 |
-the Free Software Foundation, either version 3 of the License, or |
|
480 |
-(at your option) any later version. |
|
481 |
- |
|
482 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
483 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
484 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
485 |
-GNU Lesser General Public License for more details. |
|
486 |
- |
|
487 |
-You should have received a copy of the GNU Lesser General Public License |
|
488 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
489 |
- */ |
|
490 |
-var lib_maybe; |
|
491 |
-(function (lib_maybe) { |
|
492 |
- /** |
|
493 |
- * @author fenris |
|
494 |
- */ |
|
495 |
- function make_nothing() { |
|
496 |
- return { |
|
497 |
- "kind": "nothing", |
|
498 |
- "parameters": {} |
|
499 |
- }; |
|
500 |
- } |
|
501 |
- lib_maybe.make_nothing = make_nothing; |
|
502 |
- /** |
|
503 |
- * @author fenris |
|
504 |
- */ |
|
505 |
- function make_just(value) { |
|
506 |
- return { |
|
507 |
- "kind": "just", |
|
508 |
- "parameters": { |
|
509 |
- "value": value |
|
510 |
- } |
|
511 |
- }; |
|
512 |
- } |
|
513 |
- lib_maybe.make_just = make_just; |
|
514 |
- /** |
|
515 |
- * @author fenris |
|
516 |
- */ |
|
517 |
- function is_nothing(maybe) { |
|
518 |
- return (maybe.kind === "nothing"); |
|
519 |
- } |
|
520 |
- lib_maybe.is_nothing = is_nothing; |
|
521 |
- /** |
|
522 |
- * @author fenris |
|
523 |
- */ |
|
524 |
- function is_just(maybe) { |
|
525 |
- return (maybe.kind === "just"); |
|
526 |
- } |
|
527 |
- lib_maybe.is_just = is_just; |
|
528 |
- /** |
|
529 |
- * @author fenris |
|
530 |
- */ |
|
531 |
- function cull(maybe) { |
|
532 |
- if (!is_just(maybe)) { |
|
533 |
- var message = "cull from nothing"; |
|
534 |
- throw (new Error(message)); |
|
535 |
- } |
|
536 |
- else { |
|
537 |
- var value = maybe.parameters["value"]; |
|
538 |
- return value; |
|
539 |
- } |
|
540 |
- } |
|
541 |
- lib_maybe.cull = cull; |
|
542 |
- /** |
|
543 |
- * @author fenris |
|
544 |
- */ |
|
545 |
- function propagate(maybe, function_) { |
|
546 |
- if (!is_just(maybe)) { |
|
547 |
- } |
|
548 |
- else { |
|
549 |
- var value = maybe.parameters["value"]; |
|
550 |
- var maybe_ = function_(value); |
|
551 |
- return maybe_; |
|
552 |
- } |
|
553 |
- } |
|
554 |
- lib_maybe.propagate = propagate; |
|
555 |
-})(lib_maybe || (lib_maybe = {})); |
|
556 |
-/** |
|
557 |
- * @author fenris |
|
558 |
- */ |
|
559 |
-/*export*/ var class_maybe = /** @class */ (function () { |
|
560 |
- function class_maybe() { |
|
561 |
- } |
|
562 |
- /** |
|
563 |
- * @desc whether the wrapper is nothing |
|
564 |
- * @author fenris |
|
565 |
- */ |
|
566 |
- class_maybe.prototype.is_nothing = function () { |
|
567 |
- throw (new Error("not implemented: class_maybe.is_nothing")); |
|
568 |
- }; |
|
569 |
- /** |
|
570 |
- * @desc whether the wrapper is just |
|
571 |
- * @author fenris |
|
572 |
- */ |
|
573 |
- class_maybe.prototype.is_just = function () { |
|
574 |
- throw (new Error("not implemented: class_maybe.is_just")); |
|
575 |
- }; |
|
576 |
- /** |
|
577 |
- * @desc return the value, stored in the maybe-wrapper |
|
578 |
- * @author fenris |
|
579 |
- */ |
|
580 |
- class_maybe.prototype.cull = function () { |
|
581 |
- throw (new Error("not implemented: class_maybe.cull")); |
|
582 |
- }; |
|
583 |
- /** |
|
584 |
- * @author fenris |
|
585 |
- */ |
|
586 |
- class_maybe.prototype.toString = function () { |
|
587 |
- throw (new Error("not implemented: class_maybe.cull")); |
|
588 |
- }; |
|
589 |
- /** |
|
590 |
- * @author fenris |
|
591 |
- */ |
|
592 |
- class_maybe.prototype.distinguish = function (action_just, action_nothing) { |
|
593 |
- if (action_nothing === void 0) { action_nothing = function () { }; } |
|
594 |
- throw (new Error("not implemented: class_maybe.distinguish")); |
|
595 |
- }; |
|
596 |
- /** |
|
597 |
- * @author fenris |
|
598 |
- */ |
|
599 |
- class_maybe.prototype.propagate = function (action) { |
|
600 |
- throw (new Error("not implemented: class_maybe.propagate")); |
|
601 |
- }; |
|
602 |
- /** |
|
603 |
- * @desc [implementation] |
|
604 |
- * @author fenris |
|
605 |
- */ |
|
606 |
- class_maybe.prototype._show = function () { |
|
607 |
- return this.toString(); |
|
608 |
- }; |
|
609 |
- return class_maybe; |
|
610 |
-}()); |
|
611 |
-/** |
|
612 |
- * @author fenris |
|
613 |
- */ |
|
614 |
-/*export*/ var class_nothing = /** @class */ (function (_super) { |
|
615 |
- __extends(class_nothing, _super); |
|
616 |
- /** |
|
617 |
- * @author fenris |
|
618 |
- */ |
|
619 |
- function class_nothing(reason) { |
|
620 |
- if (reason === void 0) { reason = null; } |
|
621 |
- var _this = _super.call(this) || this; |
|
622 |
- _this.reason = reason; |
|
623 |
- return _this; |
|
624 |
- } |
|
625 |
- /** |
|
626 |
- * @author fenris |
|
627 |
- */ |
|
628 |
- class_nothing.prototype.is_nothing = function () { |
|
629 |
- return true; |
|
630 |
- }; |
|
631 |
- /** |
|
632 |
- * @author fenris |
|
633 |
- */ |
|
634 |
- class_nothing.prototype.is_just = function () { |
|
635 |
- return false; |
|
636 |
- }; |
|
637 |
- /** |
|
638 |
- * @author fenris |
|
639 |
- */ |
|
640 |
- class_nothing.prototype.cull = function () { |
|
641 |
- var message = "you shouldn't cull a nothing-value …"; |
|
642 |
- lib_log.warn(message); |
|
643 |
- return null; |
|
644 |
- }; |
|
645 |
- /** |
|
646 |
- * @author fenris |
|
647 |
- */ |
|
648 |
- class_nothing.prototype.toString = function () { |
|
649 |
- return "<\u00B7>"; |
|
650 |
- }; |
|
651 |
- /** |
|
652 |
- * @author fenris |
|
653 |
- */ |
|
654 |
- class_nothing.prototype.reason_get = function () { |
|
655 |
- var content = ((this.reason == null) ? "·" : this.reason); |
|
656 |
- return "<- " + content + " ->"; |
|
657 |
- }; |
|
658 |
- /** |
|
659 |
- * @author fenris |
|
660 |
- */ |
|
661 |
- class_nothing.prototype.distinguish = function (action_just, action_nothing) { |
|
662 |
- if (action_nothing === void 0) { action_nothing = function () { }; } |
|
663 |
- action_nothing(this.reason); |
|
664 |
- }; |
|
665 |
- /** |
|
666 |
- * @author fenris |
|
667 |
- */ |
|
668 |
- class_nothing.prototype.propagate = function (action) { |
|
669 |
- return (new class_nothing(this.reason)); |
|
670 |
- }; |
|
671 |
- return class_nothing; |
|
672 |
-}(class_maybe)); |
|
673 |
-/** |
|
674 |
- * @author fenris |
|
675 |
- */ |
|
676 |
-/*export*/ var class_just = /** @class */ (function (_super) { |
|
677 |
- __extends(class_just, _super); |
|
678 |
- /** |
|
679 |
- * @author fenris |
|
680 |
- */ |
|
681 |
- function class_just(value) { |
|
682 |
- var _this = _super.call(this) || this; |
|
683 |
- _this.value = value; |
|
684 |
- return _this; |
|
685 |
- } |
|
686 |
- /** |
|
687 |
- * @author fenris |
|
688 |
- */ |
|
689 |
- class_just.prototype.is_nothing = function () { |
|
690 |
- return false; |
|
691 |
- }; |
|
692 |
- /** |
|
693 |
- * @author fenris |
|
694 |
- */ |
|
695 |
- class_just.prototype.is_just = function () { |
|
696 |
- return true; |
|
697 |
- }; |
|
698 |
- /** |
|
699 |
- * @author fenris |
|
700 |
- */ |
|
701 |
- class_just.prototype.cull = function () { |
|
702 |
- return this.value; |
|
703 |
- }; |
|
704 |
- /** |
|
705 |
- * @author fenris |
|
706 |
- */ |
|
707 |
- class_just.prototype.toString = function () { |
|
708 |
- var content = instance_show(this.value); |
|
709 |
- return "<+ " + content + " +>"; |
|
710 |
- }; |
|
711 |
- /** |
|
712 |
- * @author fenris |
|
713 |
- */ |
|
714 |
- class_just.prototype.distinguish = function (action_just, action_nothing) { |
|
715 |
- if (action_nothing === void 0) { action_nothing = function () { }; } |
|
716 |
- action_just(this.value); |
|
717 |
- }; |
|
718 |
- /** |
|
719 |
- * @author fenris |
|
720 |
- */ |
|
721 |
- class_just.prototype.propagate = function (action) { |
|
722 |
- return action(this.value); |
|
723 |
- }; |
|
724 |
- return class_just; |
|
725 |
-}(class_maybe)); |
|
726 |
-/* |
|
727 |
-This file is part of »bacterio-plankton:base«. |
|
728 |
- |
|
729 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
730 |
-<info@greenscale.de> |
|
731 |
- |
|
732 |
-»bacterio-plankton:base« is free software: you can redistribute it and/or modify |
|
733 |
-it under the terms of the GNU Lesser General Public License as published by |
|
734 |
-the Free Software Foundation, either version 3 of the License, or |
|
735 |
-(at your option) any later version. |
|
736 |
- |
|
737 |
-»bacterio-plankton:base« is distributed in the hope that it will be useful, |
|
738 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
739 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
740 |
-GNU Lesser General Public License for more details. |
|
741 |
- |
|
742 |
-You should have received a copy of the GNU Lesser General Public License |
|
743 |
-along with »bacterio-plankton:base«. If not, see <http://www.gnu.org/licenses/>. |
|
744 |
- */ |
|
745 |
-/** |
|
746 |
- * @author frac |
|
747 |
- */ |
|
748 |
-var class_error = /** @class */ (function (_super) { |
|
749 |
- __extends(class_error, _super); |
|
750 |
- /** |
|
751 |
- * @author frac |
|
752 |
- */ |
|
753 |
- function class_error(message, suberrors) { |
|
754 |
- if (suberrors === void 0) { suberrors = []; } |
|
755 |
- var _this = _super.call(this, message) || this; |
|
756 |
- _this.suberrors = suberrors; |
|
757 |
- _this.mess = message; |
|
758 |
- return _this; |
|
759 |
- } |
|
760 |
- /** |
|
761 |
- * @override |
|
762 |
- * @author frac |
|
763 |
- */ |
|
764 |
- class_error.prototype.toString = function () { |
|
765 |
- return ( /*super.toString()*/this.mess + " " + ("[" + this.suberrors.map(function (x) { return x.toString(); }).join(",") + "]")); |
|
766 |
- }; |
|
767 |
- return class_error; |
|
768 |
-}(Error)); |
|
769 |
-/* |
|
770 |
-This file is part of »bacterio-plankton:object«. |
|
771 |
- |
|
772 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
773 |
-<info@greenscale.de> |
|
774 |
- |
|
775 |
-»bacterio-plankton:object« is free software: you can redistribute it and/or modify |
|
776 |
-it under the terms of the GNU Lesser General Public License as published by |
|
777 |
-the Free Software Foundation, either version 3 of the License, or |
|
778 |
-(at your option) any later version. |
|
779 |
- |
|
780 |
-»bacterio-plankton:object« is distributed in the hope that it will be useful, |
|
781 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
782 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
783 |
-GNU Lesser General Public License for more details. |
|
784 |
- |
|
785 |
-You should have received a copy of the GNU Lesser General Public License |
|
786 |
-along with »bacterio-plankton:object«. If not, see <http://www.gnu.org/licenses/>. |
|
787 |
- */ |
|
788 |
-var lib_object; |
|
789 |
-(function (lib_object) { |
|
790 |
- /** |
|
791 |
- * @author fenris |
|
792 |
- */ |
|
793 |
- function fetch(object, fieldname, fallback, escalation) { |
|
794 |
- if (fallback === void 0) { fallback = null; } |
|
795 |
- if (escalation === void 0) { escalation = 1; } |
|
796 |
- if ((fieldname in object) && (object[fieldname] !== undefined)) { |
|
797 |
- return object[fieldname]; |
|
798 |
- } |
|
799 |
- else { |
|
800 |
- switch (escalation) { |
|
801 |
- case 0: { |
|
802 |
- return fallback; |
|
803 |
- break; |
|
804 |
- } |
|
805 |
- case 1: { |
|
806 |
- var message = ("field '" + fieldname + "' not in structure"); |
|
807 |
- message += ("; using fallback value '" + String(fallback) + "'"); |
|
808 |
- // console.warn(message); |
|
809 |
- return fallback; |
|
810 |
- break; |
|
811 |
- } |
|
812 |
- case 2: { |
|
813 |
- var message = ("field '" + fieldname + "' not in structure"); |
|
814 |
- throw (new Error(message)); |
|
815 |
- break; |
|
816 |
- } |
|
817 |
- default: { |
|
818 |
- throw (new Error("invalid escalation level " + escalation)); |
|
819 |
- break; |
|
820 |
- } |
|
821 |
- } |
|
822 |
- } |
|
823 |
- } |
|
824 |
- lib_object.fetch = fetch; |
|
825 |
- /** |
|
826 |
- * @author fenris |
|
827 |
- */ |
|
828 |
- function map(object_from, transformator) { |
|
829 |
- var object_to = {}; |
|
830 |
- Object.keys(object_from).forEach(function (key) { return (object_to[key] = transformator(object_from[key], key)); }); |
|
831 |
- return object_to; |
|
832 |
- } |
|
833 |
- lib_object.map = map; |
|
834 |
- /** |
|
835 |
- * @desc gibt ein Objekt mit bestimmten Einträgen des Eingabe-Objekts zurück |
|
836 |
- * @author fenris |
|
837 |
- */ |
|
838 |
- function filter(object_from, predicate) { |
|
839 |
- var object_to = {}; |
|
840 |
- Object.keys(object_from).forEach(function (key) { |
|
841 |
- var value = object_from[key]; |
|
842 |
- if (predicate(value, key)) { |
|
843 |
- object_to[key] = value; |
|
844 |
- } |
|
845 |
- }); |
|
846 |
- return object_to; |
|
847 |
- } |
|
848 |
- lib_object.filter = filter; |
|
849 |
- /** |
|
850 |
- * @desc wandelt ein Array mit Einträgen der Form {key,value} in ein entsprechendes Objekt um |
|
851 |
- * @author fenris |
|
852 |
- */ |
|
853 |
- function from_array(array) { |
|
854 |
- var object = {}; |
|
855 |
- array.forEach(function (entry) { return (object[entry.key] = entry.value); }); |
|
856 |
- return object; |
|
857 |
- } |
|
858 |
- lib_object.from_array = from_array; |
|
859 |
- /** |
|
860 |
- * @desc wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form {key,value} um |
|
861 |
- * @author fenris |
|
862 |
- */ |
|
863 |
- function to_array(object) { |
|
864 |
- var array = []; |
|
865 |
- Object.keys(object).forEach(function (key) { return array.push({ "key": key, "value": object[key] }); }); |
|
866 |
- return array; |
|
867 |
- } |
|
868 |
- lib_object.to_array = to_array; |
|
869 |
- /** |
|
870 |
- * @desc gibt eine Liste von Schlüsseln eines Objekts zurück |
|
871 |
- * @author fenris |
|
872 |
- */ |
|
873 |
- function keys(object) { |
|
874 |
- return Object.keys(object); |
|
875 |
- } |
|
876 |
- lib_object.keys = keys; |
|
877 |
- /** |
|
878 |
- * @desc gibt eine Liste von Werten eines Objekts zurück |
|
879 |
- * @author fenris |
|
880 |
- */ |
|
881 |
- function values(object) { |
|
882 |
- return to_array(object).map(function (entry) { return entry.value; }); |
|
883 |
- } |
|
884 |
- lib_object.values = values; |
|
885 |
- /** |
|
886 |
- * @desc liest ein Baum-artiges Objekt an einer bestimmten Stelle aus |
|
887 |
- * @author fenris |
|
888 |
- */ |
|
889 |
- function path_read(object, path, fallback, escalation) { |
|
890 |
- if (fallback === void 0) { fallback = null; } |
|
891 |
- if (escalation === void 0) { escalation = 1; } |
|
892 |
- var steps = ((path.length == 0) ? [] : path.split(".")); |
|
893 |
- if (steps.length == 0) { |
|
894 |
- throw (new Error("empty path")); |
|
895 |
- } |
|
896 |
- else { |
|
897 |
- var position_1 = object; |
|
898 |
- var reachable = (position_1 != null) && steps.slice(0, steps.length - 1).every(function (step) { |
|
899 |
- position_1 = object_fetch(position_1, step, null, 0); |
|
900 |
- return (position_1 != null); |
|
901 |
- }); |
|
902 |
- if (reachable) { |
|
903 |
- return object_fetch(position_1, steps[steps.length - 1], fallback, escalation); |
|
904 |
- } |
|
905 |
- else { |
|
906 |
- return object_fetch({}, "_dummy_", fallback, escalation); |
|
907 |
- } |
|
908 |
- } |
|
909 |
- } |
|
910 |
- lib_object.path_read = path_read; |
|
911 |
- /** |
|
912 |
- * @desc schreibt einen Wert an eine bestimmte Stelle in einem Baum-artigen Objekt |
|
913 |
- * @author fenris |
|
914 |
- */ |
|
915 |
- function path_write(object, path, value, construct) { |
|
916 |
- if (construct === void 0) { construct = true; } |
|
917 |
- var steps = ((path.length == 0) ? [] : path.split(".")); |
|
918 |
- if (steps.length == 0) { |
|
919 |
- throw (new Error("empty path")); |
|
920 |
- } |
|
921 |
- else { |
|
922 |
- var position_2 = object; |
|
923 |
- var reachable = steps.slice(0, steps.length - 1).every(function (step) { |
|
924 |
- var position_ = object_fetch(position_2, step, null, 0); |
|
925 |
- if (position_ == null) { |
|
926 |
- if (construct) { |
|
927 |
- position_2[step] = {}; |
|
928 |
- position_2 = position_2[step]; |
|
929 |
- return true; |
|
930 |
- } |
|
931 |
- else { |
|
932 |
- return false; |
|
933 |
- } |
|
934 |
- } |
|
935 |
- else { |
|
936 |
- position_2 = position_; |
|
937 |
- return true; |
|
938 |
- } |
|
939 |
- }); |
|
940 |
- if (reachable) { |
|
941 |
- position_2[steps[steps.length - 1]] = value; |
|
942 |
- } |
|
943 |
- else { |
|
944 |
- var message = ("path '" + path + "' does not exist and may not be constructed"); |
|
945 |
- throw (new Error(message)); |
|
946 |
- } |
|
947 |
- } |
|
948 |
- } |
|
949 |
- lib_object.path_write = path_write; |
|
950 |
- /** |
|
951 |
- * @desc prüft ob ein Objekt einem bestimmten Muster entspricht |
|
952 |
- * @param {Object} object das zu prüfende Objekt |
|
953 |
- * @param {Object} pattern das einzuhaltende Muster |
|
954 |
- * @param {Function} connlate eine Funktion zum Feststellen der Gleichheit von Einzelwerten |
|
955 |
- * @author fenris |
|
956 |
- */ |
|
957 |
- function matches(object, pattern, collate) { |
|
958 |
- if (collate === void 0) { collate = instance_collate; } |
|
959 |
- return Object.keys(pattern).every(function (key) { return collate(pattern[key], object[key]); }); |
|
960 |
- } |
|
961 |
- lib_object.matches = matches; |
|
962 |
- /** |
|
963 |
- * @desc erzeugt eine Projektion eines Baum-artigen Objekts in ein Listen-artiges Objekt |
|
964 |
- * @param {string} [separator] welches Zeichen als Trenner zwischen zwei Pfad-Schritten verwendet werden soll |
|
965 |
- * @author fenris |
|
966 |
- */ |
|
967 |
- function flatten(value, separator, key_for_element) { |
|
968 |
- if (separator === void 0) { separator = "."; } |
|
969 |
- if (key_for_element === void 0) { key_for_element = (function (index) { return ("element_" + index.toFixed(0)); }); } |
|
970 |
- var integrate = function (result, key_, value_) { |
|
971 |
- if (value_ == null) { |
|
972 |
- result[key_] = value_; |
|
973 |
- } |
|
974 |
- else { |
|
975 |
- // primitive Werte direkt übernehmen |
|
976 |
- if (typeof (value_) != "object") { |
|
977 |
- result[key_] = value_; |
|
978 |
- } |
|
979 |
- // sonst durch rekursiven Aufruf die flache Variante des Wertes ermitteln und einarbeiten |
|
980 |
- else { |
|
981 |
- var result_1 = flatten(value_); |
|
982 |
- Object.keys(result_1) |
|
983 |
- .forEach(function (key__) { |
|
984 |
- var value__ = result_1[key__]; |
|
985 |
- var key_new = (key_ + separator + key__); |
|
986 |
- result[key_new] = value__; |
|
987 |
- }); |
|
988 |
- } |
|
989 |
- } |
|
990 |
- }; |
|
991 |
- if ((value === null) || (value === undefined)) { |
|
992 |
- return null; |
|
993 |
- } |
|
994 |
- else { |
|
995 |
- var result_2 = {}; |
|
996 |
- if (typeof (value) != "object") { |
|
997 |
- result_2["value"] = value; |
|
998 |
- } |
|
999 |
- else { |
|
1000 |
- if (value instanceof Array) { |
|
1001 |
- var array = (value); |
|
1002 |
- array |
|
1003 |
- .forEach(function (element, index) { |
|
1004 |
- integrate(result_2, key_for_element(index), element); |
|
1005 |
- }); |
|
1006 |
- } |
|
1007 |
- else { |
|
1008 |
- var object_1 = (value); |
|
1009 |
- Object.keys(object_1) |
|
1010 |
- .forEach(function (key) { |
|
1011 |
- integrate(result_2, key, object_1[key]); |
|
1012 |
- }); |
|
1013 |
- } |
|
1014 |
- } |
|
1015 |
- return result_2; |
|
1016 |
- } |
|
1017 |
- } |
|
1018 |
- lib_object.flatten = flatten; |
|
1019 |
- /** |
|
1020 |
- * @author fenris |
|
1021 |
- */ |
|
1022 |
- function clash(x, y, _a) { |
|
1023 |
- var _b = _a === void 0 ? {} : _a, _c = _b["overwrite"], overwrite = _c === void 0 ? true : _c, _d = _b["hooks"], _e = (_d === void 0 ? {} : _d)["existing"], hook_existing = _e === void 0 ? null : _e; |
|
1024 |
- if (hook_existing == null) { |
|
1025 |
- (function (key, value_old, value_new) { return console.warn("field " + key + " already defined"); }); |
|
1026 |
- } |
|
1027 |
- var z = {}; |
|
1028 |
- Object.keys(x).forEach(function (key) { |
|
1029 |
- z[key] = x[key]; |
|
1030 |
- }); |
|
1031 |
- Object.keys(y).forEach(function (key) { |
|
1032 |
- if (key in z) { |
|
1033 |
- if (hook_existing != null) { |
|
1034 |
- hook_existing(key, z[key], y[key]); |
|
1035 |
- } |
|
1036 |
- if (overwrite) { |
|
1037 |
- z[key] = y[key]; |
|
1038 |
- } |
|
1039 |
- } |
|
1040 |
- else { |
|
1041 |
- z[key] = y[key]; |
|
1042 |
- } |
|
1043 |
- }); |
|
1044 |
- return z; |
|
1045 |
- } |
|
1046 |
- lib_object.clash = clash; |
|
1047 |
- /** |
|
1048 |
- * @author fenris |
|
1049 |
- */ |
|
1050 |
- function patch(core, mantle, deep, path) { |
|
1051 |
- if (deep === void 0) { deep = true; } |
|
1052 |
- if (path === void 0) { path = null; } |
|
1053 |
- if (mantle == null) { |
|
1054 |
- console.warn("mantle is null; core was", core); |
|
1055 |
- } |
|
1056 |
- else { |
|
1057 |
- Object.keys(mantle).forEach(function (key) { |
|
1058 |
- var path_ = ((path == null) ? key : path + "." + key); |
|
1059 |
- var value_mantle = mantle[key]; |
|
1060 |
- if (!(key in core)) { |
|
1061 |
- if ((typeof (value_mantle) == "object") && (value_mantle != null) && deep) { |
|
1062 |
- if (value_mantle instanceof Array) { |
|
1063 |
- core[key] = []; |
|
1064 |
- value_mantle.forEach(function (element) { |
|
1065 |
- if ((typeof (element) == "object") && (element != null)) { |
|
1066 |
- var element_ = {}; |
|
1067 |
- patch(element_, element); |
|
1068 |
- core[key].push(element_); |
|
1069 |
- } |
|
1070 |
- else { |
|
1071 |
- core[key].push(element); |
|
1072 |
- } |
|
1073 |
- }); |
|
1074 |
- } |
|
1075 |
- else { |
|
1076 |
- core[key] = {}; |
|
1077 |
- patch(core[key], value_mantle, deep, path_); |
|
1078 |
- } |
|
1079 |
- } |
|
1080 |
- else { |
|
1081 |
- core[key] = value_mantle; |
|
1082 |
- } |
|
1083 |
- } |
|
1084 |
- else { |
|
1085 |
- var value_core = core[key]; |
|
1086 |
- if (typeof (value_core) == typeof (value_mantle)) { |
|
1087 |
- if ((typeof (value_mantle) == "object") && (value_mantle != null) && deep) { |
|
1088 |
- patch(core[key], value_mantle, deep, path_); |
|
1089 |
- } |
|
1090 |
- else { |
|
1091 |
- core[key] = value_mantle; |
|
1092 |
- } |
|
1093 |
- } |
|
1094 |
- else { |
|
1095 |
- if ((value_core != null) && (value_mantle != null)) { |
|
1096 |
- var message = "objects have different shapes at path '" + path_ + "'; core has type '" + typeof (value_core) + "' and mantle has type '" + typeof (value_mantle) + "'"; |
|
1097 |
- console.warn(message); |
|
1098 |
- } |
|
1099 |
- core[key] = value_mantle; |
|
1100 |
- // throw (new Error(message)); |
|
1101 |
- } |
|
1102 |
- } |
|
1103 |
- }); |
|
1104 |
- } |
|
1105 |
- } |
|
1106 |
- lib_object.patch = patch; |
|
1107 |
- /** |
|
1108 |
- * @author fenris |
|
1109 |
- */ |
|
1110 |
- function patched(core, mantle, deep) { |
|
1111 |
- if (deep === void 0) { deep = undefined; } |
|
1112 |
- var result = {}; |
|
1113 |
- patch(result, core, deep); |
|
1114 |
- patch(result, mantle, deep); |
|
1115 |
- return result; |
|
1116 |
- } |
|
1117 |
- lib_object.patched = patched; |
|
1118 |
- /** |
|
1119 |
- * @author fenris |
|
1120 |
- */ |
|
1121 |
- function attached(object, key, value) { |
|
1122 |
- var mantle = {}; |
|
1123 |
- mantle[key] = value; |
|
1124 |
- return patched(object, mantle, false); |
|
1125 |
- } |
|
1126 |
- lib_object.attached = attached; |
|
1127 |
- /** |
|
1128 |
- * @author fenris |
|
1129 |
- */ |
|
1130 |
- function copy(object) { |
|
1131 |
- return patched({}, object); |
|
1132 |
- } |
|
1133 |
- lib_object.copy = copy; |
|
1134 |
-})(lib_object || (lib_object = {})); |
|
1135 |
-/** |
|
1136 |
- * @desc adapters for old syntax |
|
1137 |
- * @author fenris |
|
1138 |
- */ |
|
1139 |
-var object_fetch = lib_object.fetch; |
|
1140 |
-var object_map = lib_object.map; |
|
1141 |
-var object_a2o = lib_object.from_array; |
|
1142 |
-var object_o2a = lib_object.to_array; |
|
1143 |
-var object_matches = lib_object.matches; |
|
1144 |
-var object_clash = lib_object.clash; |
|
1145 |
-/* |
|
1146 |
-This file is part of »bacterio-plankton:shape«. |
|
1147 |
- |
|
1148 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1149 |
-<info@greenscale.de> |
|
1150 |
- |
|
1151 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1152 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1153 |
-the Free Software Foundation, either version 3 of the License, or |
|
1154 |
-(at your option) any later version. |
|
1155 |
- |
|
1156 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1157 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1158 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1159 |
-GNU Lesser General Public License for more details. |
|
1160 |
- |
|
1161 |
-You should have received a copy of the GNU Lesser General Public License |
|
1162 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1163 |
- */ |
|
1164 |
-var lib_shape; |
|
1165 |
-(function (lib_shape) { |
|
1166 |
- /** |
|
1167 |
- * @author fenris |
|
1168 |
- */ |
|
1169 |
- var _pool = {}; |
|
1170 |
- /** |
|
1171 |
- * @author fenris |
|
1172 |
- */ |
|
1173 |
- var _aliases = {}; |
|
1174 |
- /** |
|
1175 |
- * @author fenris |
|
1176 |
- */ |
|
1177 |
- function list() { |
|
1178 |
- return [].concat(Object.keys(_pool)).concat(Object.keys(_aliases)); |
|
1179 |
- } |
|
1180 |
- lib_shape.list = list; |
|
1181 |
- /** |
|
1182 |
- * @author fenris |
|
1183 |
- */ |
|
1184 |
- function inspection_create() { |
|
1185 |
- return { |
|
1186 |
- "messages": [] |
|
1187 |
- }; |
|
1188 |
- } |
|
1189 |
- lib_shape.inspection_create = inspection_create; |
|
1190 |
- /** |
|
1191 |
- * @author fenris |
|
1192 |
- */ |
|
1193 |
- function inspection_add(main, message) { |
|
1194 |
- main.messages.push(message); |
|
1195 |
- } |
|
1196 |
- lib_shape.inspection_add = inspection_add; |
|
1197 |
- /** |
|
1198 |
- * @author fenris |
|
1199 |
- */ |
|
1200 |
- function inspection_extend(main, prefix, sub) { |
|
1201 |
- main.messages = main.messages.concat(sub.messages.map(message => `${prefix}: ${message}`)); |
|
1202 |
- } |
|
1203 |
- lib_shape.inspection_extend = inspection_extend; |
|
1204 |
- /** |
|
1205 |
- * @author fenris |
|
1206 |
- * @todo check for existing |
|
1207 |
- */ |
|
1208 |
- function register({ "name": name, "make": make, "inspect": _inspect, "stance": _stance, "show": _show, }) { |
|
1209 |
- const entry = { |
|
1210 |
- "name": name, |
|
1211 |
- "make": make, |
|
1212 |
- "inspect": _inspect, |
|
1213 |
- "stance": _stance, |
|
1214 |
- "show": _show, |
|
1215 |
- }; |
|
1216 |
- _pool[name] = entry; |
|
1217 |
- } |
|
1218 |
- lib_shape.register = register; |
|
1219 |
- /** |
|
1220 |
- * @author fenris |
|
1221 |
- * @todo check for existing |
|
1222 |
- */ |
|
1223 |
- function define_alias({ "name": name, "target": target, }) { |
|
1224 |
- const entry = { |
|
1225 |
- "name": "alias", |
|
1226 |
- "target": target, |
|
1227 |
- }; |
|
1228 |
- _aliases[name] = entry; |
|
1229 |
- } |
|
1230 |
- lib_shape.define_alias = define_alias; |
|
1231 |
- /** |
|
1232 |
- * @author fenris |
|
1233 |
- * @todo check for existing |
|
1234 |
- */ |
|
1235 |
- /* |
|
1236 |
- export function inspect_jstype( |
|
1237 |
- inspection, |
|
1238 |
- jstype_expected : string, |
|
1239 |
- value : any |
|
1240 |
- ) : void { |
|
1241 |
- let jstype_actual : string = typeof(value); |
|
1242 |
- if (jstype_actual === jstype_expected) { |
|
1243 |
- // all good |
|
1244 |
- } |
|
1245 |
- else { |
|
1246 |
- inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
1247 |
- } |
|
1248 |
- } |
|
1249 |
- */ |
|
1250 |
- /** |
|
1251 |
- * @author fenris |
|
1252 |
- */ |
|
1253 |
- function make(raw) { |
|
1254 |
- const name = raw["name"]; |
|
1255 |
- if (_aliases.hasOwnProperty(name)) { |
|
1256 |
- const alias = _aliases[name]; |
|
1257 |
- return alias.target; |
|
1258 |
- } |
|
1259 |
- else { |
|
1260 |
- if (_pool.hasOwnProperty(name)) { |
|
1261 |
- const entry = _pool[name]; |
|
1262 |
- const parameters = entry.make(raw["parameters"] || {}, make); |
|
1263 |
- return { |
|
1264 |
- "name": name, |
|
1265 |
- "parameters": parameters, |
|
1266 |
- }; |
|
1267 |
- } |
|
1268 |
- else { |
|
1269 |
- const message = `no shape registered with name '${name}'`; |
|
1270 |
- throw (new Error(message)); |
|
1271 |
- } |
|
1272 |
- } |
|
1273 |
- } |
|
1274 |
- lib_shape.make = make; |
|
1275 |
- /** |
|
1276 |
- * @author fenris |
|
1277 |
- */ |
|
1278 |
- function inspect(shape, value) { |
|
1279 |
- if (_pool.hasOwnProperty(shape.name)) { |
|
1280 |
- const entry = _pool[shape.name]; |
|
1281 |
- return entry.inspect(shape.parameters, value, inspect); |
|
1282 |
- } |
|
1283 |
- else { |
|
1284 |
- const message = `no shape registered with name '${shape.name}'`; |
|
1285 |
- throw (new Error(message)); |
|
1286 |
- } |
|
1287 |
- } |
|
1288 |
- lib_shape.inspect = inspect; |
|
1289 |
- /** |
|
1290 |
- * @author fenris |
|
1291 |
- */ |
|
1292 |
- function check(shape, value) { |
|
1293 |
- if (_pool.hasOwnProperty(shape.name)) { |
|
1294 |
- const entry = _pool[shape.name]; |
|
1295 |
- const inspection = inspect(shape, value); |
|
1296 |
- inspection.messages |
|
1297 |
- .forEach((message) => { console.warn(message); }); |
|
1298 |
- return (inspection.messages.length === 0); |
|
1299 |
- } |
|
1300 |
- else { |
|
1301 |
- const message = `no shape registered with name '${shape.name}'`; |
|
1302 |
- throw (new Error(message)); |
|
1303 |
- } |
|
1304 |
- } |
|
1305 |
- lib_shape.check = check; |
|
1306 |
- /** |
|
1307 |
- * @author fenris |
|
1308 |
- */ |
|
1309 |
- function stance(shape, bindings) { |
|
1310 |
- if (_pool.hasOwnProperty(shape.name)) { |
|
1311 |
- const entry = _pool[shape.name]; |
|
1312 |
- return entry.stance(shape.parameters, bindings, stance); |
|
1313 |
- } |
|
1314 |
- else { |
|
1315 |
- const message = `no shape registered with name '${shape.name}'`; |
|
1316 |
- throw (new Error(message)); |
|
1317 |
- } |
|
1318 |
- } |
|
1319 |
- lib_shape.stance = stance; |
|
1320 |
- /** |
|
1321 |
- * @author fenris |
|
1322 |
- */ |
|
1323 |
- function show(shape) { |
|
1324 |
- if (_pool.hasOwnProperty(shape.name)) { |
|
1325 |
- const entry = _pool[shape.name]; |
|
1326 |
- return entry.show(shape.parameters, show); |
|
1327 |
- } |
|
1328 |
- else { |
|
1329 |
- const message = `no shape registered with name '${shape.name}'`; |
|
1330 |
- throw (new Error(message)); |
|
1331 |
- } |
|
1332 |
- } |
|
1333 |
- lib_shape.show = show; |
|
1334 |
-})(lib_shape || (lib_shape = {})); |
|
1335 |
-/* |
|
1336 |
-This file is part of »bacterio-plankton:shape«. |
|
1337 |
- |
|
1338 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1339 |
-<info@greenscale.de> |
|
1340 |
- |
|
1341 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1342 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1343 |
-the Free Software Foundation, either version 3 of the License, or |
|
1344 |
-(at your option) any later version. |
|
1345 |
- |
|
1346 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1347 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1348 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1349 |
-GNU Lesser General Public License for more details. |
|
1350 |
- |
|
1351 |
-You should have received a copy of the GNU Lesser General Public License |
|
1352 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1353 |
- */ |
|
1354 |
-var lib_shape; |
|
1355 |
-(function (lib_shape) { |
|
1356 |
- /** |
|
1357 |
- * @author fenris |
|
1358 |
- */ |
|
1359 |
- function variable_make({ "name": name }) { |
|
1360 |
- if (name == undefined) { |
|
1361 |
- let message = `mandatory parameter 'name' missing`; |
|
1362 |
- throw (new Error(message)); |
|
1363 |
- } |
|
1364 |
- else { |
|
1365 |
- return { |
|
1366 |
- "name": name, |
|
1367 |
- }; |
|
1368 |
- } |
|
1369 |
- } |
|
1370 |
- /** |
|
1371 |
- * @author fenris |
|
1372 |
- */ |
|
1373 |
- function variable_inspect(parameters, value, _inspect) { |
|
1374 |
- let inspection = lib_shape.inspection_create(); |
|
1375 |
- let message = "cannot inspect a value against a type variable"; |
|
1376 |
- console.warn(message + "; will just pass ..."); |
|
1377 |
- // throw (new Error(message)); |
|
1378 |
- return inspection; |
|
1379 |
- } |
|
1380 |
- /** |
|
1381 |
- * @author fenris |
|
1382 |
- */ |
|
1383 |
- function variable_stance(parameters, bindings, _stance) { |
|
1384 |
- if (parameters.name in bindings) { |
|
1385 |
- return bindings[parameters.name]; |
|
1386 |
- } |
|
1387 |
- else { |
|
1388 |
- return { |
|
1389 |
- "name": "variable", |
|
1390 |
- "parameters": parameters |
|
1391 |
- }; |
|
1392 |
- } |
|
1393 |
- } |
|
1394 |
- /** |
|
1395 |
- * @author fenris |
|
1396 |
- */ |
|
1397 |
- function variable_show(parameters, _show) { |
|
1398 |
- let str; |
|
1399 |
- // core |
|
1400 |
- { |
|
1401 |
- str = ("$" + parameters.name); |
|
1402 |
- } |
|
1403 |
- return str; |
|
1404 |
- } |
|
1405 |
- /** |
|
1406 |
- * @author fenris |
|
1407 |
- */ |
|
1408 |
- lib_shape.register({ |
|
1409 |
- "name": "variable", |
|
1410 |
- "make": variable_make, |
|
1411 |
- "inspect": variable_inspect, |
|
1412 |
- "stance": variable_stance, |
|
1413 |
- "show": variable_show, |
|
1414 |
- }); |
|
1415 |
-})(lib_shape || (lib_shape = {})); |
|
1416 |
-/* |
|
1417 |
-This file is part of »bacterio-plankton:shape«. |
|
1418 |
- |
|
1419 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1420 |
-<info@greenscale.de> |
|
1421 |
- |
|
1422 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1423 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1424 |
-the Free Software Foundation, either version 3 of the License, or |
|
1425 |
-(at your option) any later version. |
|
1426 |
- |
|
1427 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1428 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1429 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1430 |
-GNU Lesser General Public License for more details. |
|
1431 |
- |
|
1432 |
-You should have received a copy of the GNU Lesser General Public License |
|
1433 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1434 |
- */ |
|
1435 |
-var lib_shape; |
|
1436 |
-(function (lib_shape) { |
|
1437 |
- /** |
|
1438 |
- * @author fenris |
|
1439 |
- */ |
|
1440 |
- function function_make({ "soft": soft = false, "shape_input": shape_input, "shape_output": shape_output, "defaultvalue": defaultvalue = undefined, }, _make) { |
|
1441 |
- if (shape_input === undefined) { |
|
1442 |
- let message = `mandatory parameter 'shape_input' missing`; |
|
1443 |
- throw (new Error(message)); |
|
1444 |
- } |
|
1445 |
- if (shape_output === undefined) { |
|
1446 |
- let message = `mandatory parameter 'shape_output' missing`; |
|
1447 |
- throw (new Error(message)); |
|
1448 |
- } |
|
1449 |
- if (defaultvalue === undefined) { |
|
1450 |
- defaultvalue = (soft ? null : (x => x)); |
|
1451 |
- } |
|
1452 |
- return { |
|
1453 |
- "soft": soft, |
|
1454 |
- "shape_input": _make(shape_input), |
|
1455 |
- "shape_output": _make(shape_output), |
|
1456 |
- "defaultvalue": defaultvalue, |
|
1457 |
- }; |
|
1458 |
- } |
|
1459 |
- /** |
|
1460 |
- * @author fenris |
|
1461 |
- */ |
|
1462 |
- function function_stance(parameters, bindings, _stance) { |
|
1463 |
- return { |
|
1464 |
- "name": "function", |
|
1465 |
- "parameters": { |
|
1466 |
- "soft": parameters.soft, |
|
1467 |
- "shape_input": _stance(parameters.shape_input, bindings), |
|
1468 |
- "shape_output": _stance(parameters.shape_output, bindings) |
|
1469 |
- } |
|
1470 |
- }; |
|
1471 |
- } |
|
1472 |
- /** |
|
1473 |
- * @author fenris |
|
1474 |
- * @todo closer look not possible? |
|
1475 |
- */ |
|
1476 |
- function function_inspect(parameters, value, _inspect) { |
|
1477 |
- let inspection = lib_shape.inspection_create(); |
|
1478 |
- if (value == undefined) { |
|
1479 |
- if (parameters.soft) { |
|
1480 |
- // all good |
|
1481 |
- } |
|
1482 |
- else { |
|
1483 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
1484 |
- } |
|
1485 |
- } |
|
1486 |
- else { |
|
1487 |
- let jstype_actual = typeof (value); |
|
1488 |
- let jstype_expected = "function"; |
|
1489 |
- if (jstype_actual === jstype_expected) { |
|
1490 |
- // all good? |
|
1491 |
- } |
|
1492 |
- else { |
|
1493 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
1494 |
- } |
|
1495 |
- } |
|
1496 |
- return inspection; |
|
1497 |
- } |
|
1498 |
- /** |
|
1499 |
- * @author fenris |
|
1500 |
- */ |
|
1501 |
- function function_show(parameters, _show) { |
|
1502 |
- let str; |
|
1503 |
- /* |
|
1504 |
- // core |
|
1505 |
- { |
|
1506 |
- str = "function"; |
|
1507 |
- } |
|
1508 |
- // in/out |
|
1509 |
- { |
|
1510 |
- str += ( |
|
1511 |
- "<" |
|
1512 |
- + |
|
1513 |
- [ |
|
1514 |
- _show(parameters.shape_input), |
|
1515 |
- _show(parameters.shape_output), |
|
1516 |
- ].join(",") |
|
1517 |
- + |
|
1518 |
- ">" |
|
1519 |
- ); |
|
1520 |
- } |
|
1521 |
- */ |
|
1522 |
- str = ""; |
|
1523 |
- str += ("(" + _show(parameters.shape_input) + " => " + _show(parameters.shape_output) + ")"); |
|
1524 |
- // soft |
|
1525 |
- { |
|
1526 |
- if (parameters.soft) { |
|
1527 |
- str = `~${str}`; |
|
1528 |
- } |
|
1529 |
- } |
|
1530 |
- return str; |
|
1531 |
- } |
|
1532 |
- /** |
|
1533 |
- * @author fenris |
|
1534 |
- */ |
|
1535 |
- lib_shape.register({ |
|
1536 |
- "name": "function", |
|
1537 |
- "make": function_make, |
|
1538 |
- "inspect": function_inspect, |
|
1539 |
- "stance": function_stance, |
|
1540 |
- "show": function_show, |
|
1541 |
- }); |
|
1542 |
-})(lib_shape || (lib_shape = {})); |
|
1543 |
-/* |
|
1544 |
-This file is part of »bacterio-plankton:shape«. |
|
1545 |
- |
|
1546 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1547 |
-<info@greenscale.de> |
|
1548 |
- |
|
1549 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1550 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1551 |
-the Free Software Foundation, either version 3 of the License, or |
|
1552 |
-(at your option) any later version. |
|
1553 |
- |
|
1554 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1555 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1556 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1557 |
-GNU Lesser General Public License for more details. |
|
1558 |
- |
|
1559 |
-You should have received a copy of the GNU Lesser General Public License |
|
1560 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1561 |
- */ |
|
1562 |
-var lib_shape; |
|
1563 |
-(function (lib_shape) { |
|
1564 |
- /** |
|
1565 |
- * @author fenris |
|
1566 |
- */ |
|
1567 |
- function void_make({ "soft": soft = true, }) { |
|
1568 |
- return { |
|
1569 |
- "soft": soft, |
|
1570 |
- }; |
|
1571 |
- } |
|
1572 |
- /** |
|
1573 |
- * @author fenris |
|
1574 |
- */ |
|
1575 |
- function void_inspect(parameters, value, _inspect) { |
|
1576 |
- let inspection = lib_shape.inspection_create(); |
|
1577 |
- if (value == undefined) { |
|
1578 |
- if (parameters.soft) { |
|
1579 |
- // all good |
|
1580 |
- } |
|
1581 |
- else { |
|
1582 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
1583 |
- } |
|
1584 |
- } |
|
1585 |
- else { |
|
1586 |
- // all good |
|
1587 |
- } |
|
1588 |
- return inspection; |
|
1589 |
- } |
|
1590 |
- /** |
|
1591 |
- * @author fenris |
|
1592 |
- */ |
|
1593 |
- function void_stance(parameters, bindings, _stance) { |
|
1594 |
- return { |
|
1595 |
- "name": "void", |
|
1596 |
- "parameters": parameters |
|
1597 |
- }; |
|
1598 |
- } |
|
1599 |
- /** |
|
1600 |
- * @author fenris |
|
1601 |
- */ |
|
1602 |
- function void_show(parameters, _show) { |
|
1603 |
- let str; |
|
1604 |
- // core |
|
1605 |
- { |
|
1606 |
- str = "void"; |
|
1607 |
- } |
|
1608 |
- // soft |
|
1609 |
- { |
|
1610 |
- if (parameters.soft) { |
|
1611 |
- str = `~${str}`; |
|
1612 |
- } |
|
1613 |
- } |
|
1614 |
- return str; |
|
1615 |
- } |
|
1616 |
- /** |
|
1617 |
- * @author fenris |
|
1618 |
- */ |
|
1619 |
- lib_shape.register({ |
|
1620 |
- "name": "void", |
|
1621 |
- "make": void_make, |
|
1622 |
- "inspect": void_inspect, |
|
1623 |
- "stance": void_stance, |
|
1624 |
- "show": void_show, |
|
1625 |
- }); |
|
1626 |
-})(lib_shape || (lib_shape = {})); |
|
1627 |
-/* |
|
1628 |
-This file is part of »bacterio-plankton:shape«. |
|
1629 |
- |
|
1630 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1631 |
-<info@greenscale.de> |
|
1632 |
- |
|
1633 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1634 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1635 |
-the Free Software Foundation, either version 3 of the License, or |
|
1636 |
-(at your option) any later version. |
|
1637 |
- |
|
1638 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1639 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1640 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1641 |
-GNU Lesser General Public License for more details. |
|
1642 |
- |
|
1643 |
-You should have received a copy of the GNU Lesser General Public License |
|
1644 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1645 |
- */ |
|
1646 |
-var lib_shape; |
|
1647 |
-(function (lib_shape) { |
|
1648 |
- /** |
|
1649 |
- * @author fenris |
|
1650 |
- */ |
|
1651 |
- function any_make({ "soft": soft = true, "mutable": mutable = true, "defaultvalue": defaultvalue = null, }) { |
|
1652 |
- return { |
|
1653 |
- "soft": soft, |
|
1654 |
- "mutable": mutable, |
|
1655 |
- "defaultvalue": defaultvalue, |
|
1656 |
- }; |
|
1657 |
- } |
|
1658 |
- /** |
|
1659 |
- * @author fenris |
|
1660 |
- */ |
|
1661 |
- function any_inspect(parameters, value, _inspect) { |
|
1662 |
- let inspection = lib_shape.inspection_create(); |
|
1663 |
- if (value == undefined) { |
|
1664 |
- if (parameters.soft) { |
|
1665 |
- // all good |
|
1666 |
- } |
|
1667 |
- else { |
|
1668 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
1669 |
- } |
|
1670 |
- } |
|
1671 |
- else { |
|
1672 |
- // all good |
|
1673 |
- } |
|
1674 |
- return inspection; |
|
1675 |
- } |
|
1676 |
- /** |
|
1677 |
- * @author fenris |
|
1678 |
- */ |
|
1679 |
- function any_stance(parameters, bindings, _stance) { |
|
1680 |
- return { |
|
1681 |
- "name": "any", |
|
1682 |
- "parameters": parameters |
|
1683 |
- }; |
|
1684 |
- } |
|
1685 |
- /** |
|
1686 |
- * @author fenris |
|
1687 |
- */ |
|
1688 |
- function any_show(parameters, _show) { |
|
1689 |
- let str; |
|
1690 |
- // core |
|
1691 |
- { |
|
1692 |
- str = "any"; |
|
1693 |
- } |
|
1694 |
- // soft |
|
1695 |
- { |
|
1696 |
- if (parameters.soft) { |
|
1697 |
- str = `~${str}`; |
|
1698 |
- } |
|
1699 |
- } |
|
1700 |
- return str; |
|
1701 |
- } |
|
1702 |
- /** |
|
1703 |
- * @author fenris |
|
1704 |
- */ |
|
1705 |
- lib_shape.register({ |
|
1706 |
- "name": "any", |
|
1707 |
- "make": any_make, |
|
1708 |
- "inspect": any_inspect, |
|
1709 |
- "stance": any_stance, |
|
1710 |
- "show": any_show, |
|
1711 |
- }); |
|
1712 |
-})(lib_shape || (lib_shape = {})); |
|
1713 |
-/* |
|
1714 |
-This file is part of »bacterio-plankton:shape«. |
|
1715 |
- |
|
1716 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1717 |
-<info@greenscale.de> |
|
1718 |
- |
|
1719 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1720 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1721 |
-the Free Software Foundation, either version 3 of the License, or |
|
1722 |
-(at your option) any later version. |
|
1723 |
- |
|
1724 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1725 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1726 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1727 |
-GNU Lesser General Public License for more details. |
|
1728 |
- |
|
1729 |
-You should have received a copy of the GNU Lesser General Public License |
|
1730 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1731 |
- */ |
|
1732 |
-var lib_shape; |
|
1733 |
-(function (lib_shape) { |
|
1734 |
- /** |
|
1735 |
- * @author fenris |
|
1736 |
- */ |
|
1737 |
- function boolean_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { |
|
1738 |
- if (defaultvalue === undefined) { |
|
1739 |
- defaultvalue = (soft ? null : false); |
|
1740 |
- } |
|
1741 |
- return { |
|
1742 |
- "soft": soft, |
|
1743 |
- "mutable": mutable, |
|
1744 |
- "defaultvalue": defaultvalue, |
|
1745 |
- }; |
|
1746 |
- } |
|
1747 |
- /** |
|
1748 |
- * @author fenris |
|
1749 |
- */ |
|
1750 |
- function boolean_inspect(parameters, value, _inspect) { |
|
1751 |
- let inspection = lib_shape.inspection_create(); |
|
1752 |
- if (value == undefined) { |
|
1753 |
- if (parameters.soft) { |
|
1754 |
- // all good |
|
1755 |
- } |
|
1756 |
- else { |
|
1757 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
1758 |
- } |
|
1759 |
- } |
|
1760 |
- else { |
|
1761 |
- let jstype_actual = typeof (value); |
|
1762 |
- let jstype_expected = "boolean"; |
|
1763 |
- if (jstype_actual === jstype_expected) { |
|
1764 |
- // all good |
|
1765 |
- } |
|
1766 |
- else { |
|
1767 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
1768 |
- } |
|
1769 |
- } |
|
1770 |
- return inspection; |
|
1771 |
- } |
|
1772 |
- /** |
|
1773 |
- * @author fenris |
|
1774 |
- */ |
|
1775 |
- function boolean_stance(parameters, bindings, _stance) { |
|
1776 |
- return { |
|
1777 |
- "name": "boolean", |
|
1778 |
- "parameters": parameters |
|
1779 |
- }; |
|
1780 |
- } |
|
1781 |
- /** |
|
1782 |
- * @author fenris |
|
1783 |
- */ |
|
1784 |
- function boolean_show(parameters, _show) { |
|
1785 |
- let str; |
|
1786 |
- // core |
|
1787 |
- { |
|
1788 |
- str = "boolean"; |
|
1789 |
- } |
|
1790 |
- // soft |
|
1791 |
- { |
|
1792 |
- if (parameters.soft) { |
|
1793 |
- str = `~${str}`; |
|
1794 |
- } |
|
1795 |
- } |
|
1796 |
- return str; |
|
1797 |
- } |
|
1798 |
- /** |
|
1799 |
- * @author fenris |
|
1800 |
- */ |
|
1801 |
- lib_shape.register({ |
|
1802 |
- "name": "boolean", |
|
1803 |
- "make": boolean_make, |
|
1804 |
- "inspect": boolean_inspect, |
|
1805 |
- "stance": boolean_stance, |
|
1806 |
- "show": boolean_show, |
|
1807 |
- }); |
|
1808 |
-})(lib_shape || (lib_shape = {})); |
|
1809 |
-/* |
|
1810 |
-This file is part of »bacterio-plankton:shape«. |
|
1811 |
- |
|
1812 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1813 |
-<info@greenscale.de> |
|
1814 |
- |
|
1815 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1816 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1817 |
-the Free Software Foundation, either version 3 of the License, or |
|
1818 |
-(at your option) any later version. |
|
1819 |
- |
|
1820 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1821 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1822 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1823 |
-GNU Lesser General Public License for more details. |
|
1824 |
- |
|
1825 |
-You should have received a copy of the GNU Lesser General Public License |
|
1826 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1827 |
- */ |
|
1828 |
-var lib_shape; |
|
1829 |
-(function (lib_shape) { |
|
1830 |
- /** |
|
1831 |
- * @author fenris |
|
1832 |
- */ |
|
1833 |
- function int_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "minimum": minimum = null, "maximum": maximum = null, }) { |
|
1834 |
- if (defaultvalue === undefined) { |
|
1835 |
- defaultvalue = (soft ? null : 0); |
|
1836 |
- } |
|
1837 |
- return { |
|
1838 |
- "soft": soft, |
|
1839 |
- "mutable": mutable, |
|
1840 |
- "defaultvalue": defaultvalue, |
|
1841 |
- "minimum": minimum, |
|
1842 |
- "maximum": maximum, |
|
1843 |
- }; |
|
1844 |
- } |
|
1845 |
- /** |
|
1846 |
- * @author fenris |
|
1847 |
- */ |
|
1848 |
- function int_inspect(parameters, value, _inspect) { |
|
1849 |
- let inspection = lib_shape.inspection_create(); |
|
1850 |
- if (value == undefined) { |
|
1851 |
- if (parameters.soft) { |
|
1852 |
- // all good |
|
1853 |
- } |
|
1854 |
- else { |
|
1855 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
1856 |
- } |
|
1857 |
- } |
|
1858 |
- else { |
|
1859 |
- let jstype_actual = typeof (value); |
|
1860 |
- let jstype_expected = "number"; |
|
1861 |
- if (jstype_actual === jstype_expected) { |
|
1862 |
- if (!isNaN(parseInt(value))) { |
|
1863 |
- if ((parameters.minimum === null) || (value >= parameters.minimum)) { |
|
1864 |
- if ((parameters.maximum === null) || (value <= parameters.maximum)) { |
|
1865 |
- // all good |
|
1866 |
- } |
|
1867 |
- else { |
|
1868 |
- lib_shape.inspection_add(inspection, `value is beyond maximum`); |
|
1869 |
- } |
|
1870 |
- } |
|
1871 |
- else { |
|
1872 |
- lib_shape.inspection_add(inspection, `value is below minimum`); |
|
1873 |
- } |
|
1874 |
- } |
|
1875 |
- else { |
|
1876 |
- lib_shape.inspection_add(inspection, `value is not parsable into a valid int`); |
|
1877 |
- } |
|
1878 |
- } |
|
1879 |
- else { |
|
1880 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
1881 |
- } |
|
1882 |
- } |
|
1883 |
- return inspection; |
|
1884 |
- } |
|
1885 |
- /** |
|
1886 |
- * @author fenris |
|
1887 |
- */ |
|
1888 |
- function int_stance(parameters, bindings, _stance) { |
|
1889 |
- return { |
|
1890 |
- "name": "int", |
|
1891 |
- "parameters": parameters |
|
1892 |
- }; |
|
1893 |
- } |
|
1894 |
- /** |
|
1895 |
- * @author fenris |
|
1896 |
- */ |
|
1897 |
- function int_show(parameters, _show) { |
|
1898 |
- let str; |
|
1899 |
- // core |
|
1900 |
- { |
|
1901 |
- str = "int"; |
|
1902 |
- } |
|
1903 |
- // soft |
|
1904 |
- { |
|
1905 |
- if (parameters.soft) { |
|
1906 |
- str = `~${str}`; |
|
1907 |
- } |
|
1908 |
- } |
|
1909 |
- return str; |
|
1910 |
- } |
|
1911 |
- /** |
|
1912 |
- * @author fenris |
|
1913 |
- */ |
|
1914 |
- lib_shape.register({ |
|
1915 |
- "name": "int", |
|
1916 |
- "make": int_make, |
|
1917 |
- "inspect": int_inspect, |
|
1918 |
- "stance": int_stance, |
|
1919 |
- "show": int_show, |
|
1920 |
- }); |
|
1921 |
-})(lib_shape || (lib_shape = {})); |
|
1922 |
-/* |
|
1923 |
-This file is part of »bacterio-plankton:shape«. |
|
1924 |
- |
|
1925 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
1926 |
-<info@greenscale.de> |
|
1927 |
- |
|
1928 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
1929 |
-it under the terms of the GNU Lesser General Public License as published by |
|
1930 |
-the Free Software Foundation, either version 3 of the License, or |
|
1931 |
-(at your option) any later version. |
|
1932 |
- |
|
1933 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
1934 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1935 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
1936 |
-GNU Lesser General Public License for more details. |
|
1937 |
- |
|
1938 |
-You should have received a copy of the GNU Lesser General Public License |
|
1939 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
1940 |
- */ |
|
1941 |
-var lib_shape; |
|
1942 |
-(function (lib_shape) { |
|
1943 |
- /** |
|
1944 |
- * @author fenris |
|
1945 |
- */ |
|
1946 |
- function float_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { |
|
1947 |
- if (defaultvalue === undefined) { |
|
1948 |
- defaultvalue = (soft ? null : 0.0); |
|
1949 |
- } |
|
1950 |
- return { |
|
1951 |
- "soft": soft, |
|
1952 |
- "mutable": mutable, |
|
1953 |
- "defaultvalue": defaultvalue, |
|
1954 |
- }; |
|
1955 |
- } |
|
1956 |
- /** |
|
1957 |
- * @author fenris |
|
1958 |
- */ |
|
1959 |
- function float_inspect(parameters, value, _inspect) { |
|
1960 |
- let inspection = lib_shape.inspection_create(); |
|
1961 |
- if (value == undefined) { |
|
1962 |
- if (parameters.soft) { |
|
1963 |
- // all good |
|
1964 |
- } |
|
1965 |
- else { |
|
1966 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
1967 |
- } |
|
1968 |
- } |
|
1969 |
- else { |
|
1970 |
- let jstype_actual = typeof (value); |
|
1971 |
- let jstype_expected = "number"; |
|
1972 |
- if (jstype_actual === jstype_expected) { |
|
1973 |
- if (!isNaN(parseFloat(value))) { |
|
1974 |
- // all good |
|
1975 |
- } |
|
1976 |
- else { |
|
1977 |
- lib_shape.inspection_add(inspection, `value is not parsable into a valid float`); |
|
1978 |
- } |
|
1979 |
- } |
|
1980 |
- else { |
|
1981 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
1982 |
- } |
|
1983 |
- } |
|
1984 |
- return inspection; |
|
1985 |
- } |
|
1986 |
- /** |
|
1987 |
- * @author fenris |
|
1988 |
- */ |
|
1989 |
- function float_stance(parameters, bindings, _stance) { |
|
1990 |
- return { |
|
1991 |
- "name": "float", |
|
1992 |
- "parameters": parameters |
|
1993 |
- }; |
|
1994 |
- } |
|
1995 |
- /** |
|
1996 |
- * @author fenris |
|
1997 |
- */ |
|
1998 |
- function float_show(parameters, _show) { |
|
1999 |
- let str; |
|
2000 |
- // core |
|
2001 |
- { |
|
2002 |
- str = "float"; |
|
2003 |
- } |
|
2004 |
- // soft |
|
2005 |
- { |
|
2006 |
- if (parameters.soft) { |
|
2007 |
- str = `~${str}`; |
|
2008 |
- } |
|
2009 |
- } |
|
2010 |
- return str; |
|
2011 |
- } |
|
2012 |
- /** |
|
2013 |
- * @author fenris |
|
2014 |
- */ |
|
2015 |
- lib_shape.register({ |
|
2016 |
- "name": "float", |
|
2017 |
- "make": float_make, |
|
2018 |
- "inspect": float_inspect, |
|
2019 |
- "stance": float_stance, |
|
2020 |
- "show": float_show, |
|
2021 |
- }); |
|
2022 |
-})(lib_shape || (lib_shape = {})); |
|
2023 |
-/* |
|
2024 |
-This file is part of »bacterio-plankton:shape«. |
|
2025 |
- |
|
2026 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2027 |
-<info@greenscale.de> |
|
2028 |
- |
|
2029 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2030 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2031 |
-the Free Software Foundation, either version 3 of the License, or |
|
2032 |
-(at your option) any later version. |
|
2033 |
- |
|
2034 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2035 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2036 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2037 |
-GNU Lesser General Public License for more details. |
|
2038 |
- |
|
2039 |
-You should have received a copy of the GNU Lesser General Public License |
|
2040 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2041 |
- */ |
|
2042 |
-var lib_shape; |
|
2043 |
-(function (lib_shape) { |
|
2044 |
- /** |
|
2045 |
- * @author fenris |
|
2046 |
- */ |
|
2047 |
- function string_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "long": long = false, }) { |
|
2048 |
- if (defaultvalue === undefined) { |
|
2049 |
- defaultvalue = (soft ? null : ""); |
|
2050 |
- } |
|
2051 |
- return { |
|
2052 |
- "soft": soft, |
|
2053 |
- "mutable": mutable, |
|
2054 |
- "defaultvalue": defaultvalue, |
|
2055 |
- "long": long, |
|
2056 |
- }; |
|
2057 |
- } |
|
2058 |
- /** |
|
2059 |
- * @author fenris |
|
2060 |
- */ |
|
2061 |
- function string_inspect(parameters, value, _inspect) { |
|
2062 |
- let inspection = lib_shape.inspection_create(); |
|
2063 |
- if (value == undefined) { |
|
2064 |
- if (parameters.soft) { |
|
2065 |
- // all good |
|
2066 |
- } |
|
2067 |
- else { |
|
2068 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2069 |
- } |
|
2070 |
- } |
|
2071 |
- else { |
|
2072 |
- let jstype_actual = typeof (value); |
|
2073 |
- let jstype_expected = "string"; |
|
2074 |
- if (jstype_actual === jstype_expected) { |
|
2075 |
- // all good |
|
2076 |
- } |
|
2077 |
- else { |
|
2078 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2079 |
- } |
|
2080 |
- } |
|
2081 |
- return inspection; |
|
2082 |
- } |
|
2083 |
- /** |
|
2084 |
- * @author fenris |
|
2085 |
- */ |
|
2086 |
- function string_stance(parameters, bindings, _stance) { |
|
2087 |
- return { |
|
2088 |
- "name": "string", |
|
2089 |
- "parameters": parameters |
|
2090 |
- }; |
|
2091 |
- } |
|
2092 |
- /** |
|
2093 |
- * @author fenris |
|
2094 |
- */ |
|
2095 |
- function string_show(parameters, _show) { |
|
2096 |
- let str; |
|
2097 |
- // core |
|
2098 |
- { |
|
2099 |
- str = "string"; |
|
2100 |
- } |
|
2101 |
- // soft |
|
2102 |
- { |
|
2103 |
- if (parameters.soft) { |
|
2104 |
- str = `~${str}`; |
|
2105 |
- } |
|
2106 |
- } |
|
2107 |
- return str; |
|
2108 |
- } |
|
2109 |
- /** |
|
2110 |
- * @author fenris |
|
2111 |
- */ |
|
2112 |
- lib_shape.register({ |
|
2113 |
- "name": "string", |
|
2114 |
- "make": string_make, |
|
2115 |
- "inspect": string_inspect, |
|
2116 |
- "stance": string_stance, |
|
2117 |
- "show": string_show, |
|
2118 |
- }); |
|
2119 |
-})(lib_shape || (lib_shape = {})); |
|
2120 |
-/* |
|
2121 |
-This file is part of »bacterio-plankton:shape«. |
|
2122 |
- |
|
2123 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2124 |
-<info@greenscale.de> |
|
2125 |
- |
|
2126 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2127 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2128 |
-the Free Software Foundation, either version 3 of the License, or |
|
2129 |
-(at your option) any later version. |
|
2130 |
- |
|
2131 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2132 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2133 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2134 |
-GNU Lesser General Public License for more details. |
|
2135 |
- |
|
2136 |
-You should have received a copy of the GNU Lesser General Public License |
|
2137 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2138 |
- */ |
|
2139 |
-var lib_shape; |
|
2140 |
-(function (lib_shape) { |
|
2141 |
- /** |
|
2142 |
- * @author fenris |
|
2143 |
- */ |
|
2144 |
- function email_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { |
|
2145 |
- if (defaultvalue === undefined) { |
|
2146 |
- defaultvalue = (soft ? null : ""); |
|
2147 |
- } |
|
2148 |
- return { |
|
2149 |
- "soft": soft, |
|
2150 |
- "mutable": mutable, |
|
2151 |
- "defaultvalue": defaultvalue, |
|
2152 |
- }; |
|
2153 |
- } |
|
2154 |
- /** |
|
2155 |
- * @author fenris |
|
2156 |
- */ |
|
2157 |
- function email_inspect(parameters, value, _inspect) { |
|
2158 |
- let inspection = lib_shape.inspection_create(); |
|
2159 |
- if (value == undefined) { |
|
2160 |
- if (parameters.soft) { |
|
2161 |
- // all good |
|
2162 |
- } |
|
2163 |
- else { |
|
2164 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2165 |
- } |
|
2166 |
- } |
|
2167 |
- else { |
|
2168 |
- let jstype_actual = typeof (value); |
|
2169 |
- let jstype_expected = "string"; |
|
2170 |
- if (jstype_actual === jstype_expected) { |
|
2171 |
- // all good |
|
2172 |
- } |
|
2173 |
- else { |
|
2174 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2175 |
- } |
|
2176 |
- } |
|
2177 |
- return inspection; |
|
2178 |
- } |
|
2179 |
- /** |
|
2180 |
- * @author fenris |
|
2181 |
- */ |
|
2182 |
- function email_stance(parameters, bindings, _stance) { |
|
2183 |
- return { |
|
2184 |
- "name": "email", |
|
2185 |
- "parameters": parameters |
|
2186 |
- }; |
|
2187 |
- } |
|
2188 |
- /** |
|
2189 |
- * @author fenris |
|
2190 |
- */ |
|
2191 |
- function email_show(parameters, _show) { |
|
2192 |
- let str; |
|
2193 |
- // core |
|
2194 |
- { |
|
2195 |
- str = "email"; |
|
2196 |
- } |
|
2197 |
- // soft |
|
2198 |
- { |
|
2199 |
- if (parameters.soft) { |
|
2200 |
- str = `~${str}`; |
|
2201 |
- } |
|
2202 |
- } |
|
2203 |
- return str; |
|
2204 |
- } |
|
2205 |
- /** |
|
2206 |
- * @author fenris |
|
2207 |
- */ |
|
2208 |
- lib_shape.register({ |
|
2209 |
- "name": "email", |
|
2210 |
- "make": email_make, |
|
2211 |
- "inspect": email_inspect, |
|
2212 |
- "stance": email_stance, |
|
2213 |
- "show": email_show, |
|
2214 |
- }); |
|
2215 |
-})(lib_shape || (lib_shape = {})); |
|
2216 |
-/* |
|
2217 |
-This file is part of »bacterio-plankton:shape«. |
|
2218 |
- |
|
2219 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2220 |
-<info@greenscale.de> |
|
2221 |
- |
|
2222 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2223 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2224 |
-the Free Software Foundation, either version 3 of the License, or |
|
2225 |
-(at your option) any later version. |
|
2226 |
- |
|
2227 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2228 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2229 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2230 |
-GNU Lesser General Public License for more details. |
|
2231 |
- |
|
2232 |
-You should have received a copy of the GNU Lesser General Public License |
|
2233 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2234 |
- */ |
|
2235 |
-var lib_shape; |
|
2236 |
-(function (lib_shape) { |
|
2237 |
- /** |
|
2238 |
- * @author fenris |
|
2239 |
- */ |
|
2240 |
- function url_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "type": type = "link", }) { |
|
2241 |
- if (defaultvalue === undefined) { |
|
2242 |
- defaultvalue = (soft ? null : ""); |
|
2243 |
- } |
|
2244 |
- return { |
|
2245 |
- "soft": soft, |
|
2246 |
- "mutable": mutable, |
|
2247 |
- "defaultvalue": defaultvalue, |
|
2248 |
- "type": type, |
|
2249 |
- }; |
|
2250 |
- } |
|
2251 |
- /** |
|
2252 |
- * @author fenris |
|
2253 |
- */ |
|
2254 |
- function url_inspect(parameters, value, _inspect) { |
|
2255 |
- let inspection = lib_shape.inspection_create(); |
|
2256 |
- if (value == undefined) { |
|
2257 |
- if (parameters.soft) { |
|
2258 |
- // all good |
|
2259 |
- } |
|
2260 |
- else { |
|
2261 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2262 |
- } |
|
2263 |
- } |
|
2264 |
- else { |
|
2265 |
- let jstype_actual = typeof (value); |
|
2266 |
- let jstype_expected = "string"; |
|
2267 |
- if (jstype_actual === jstype_expected) { |
|
2268 |
- // all good |
|
2269 |
- } |
|
2270 |
- else { |
|
2271 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2272 |
- } |
|
2273 |
- } |
|
2274 |
- return inspection; |
|
2275 |
- } |
|
2276 |
- /** |
|
2277 |
- * @author fenris |
|
2278 |
- */ |
|
2279 |
- function url_stance(parameters, bindings, _stance) { |
|
2280 |
- return { |
|
2281 |
- "name": "url", |
|
2282 |
- "parameters": parameters |
|
2283 |
- }; |
|
2284 |
- } |
|
2285 |
- /** |
|
2286 |
- * @author fenris |
|
2287 |
- */ |
|
2288 |
- function url_show(parameters, _show) { |
|
2289 |
- let str; |
|
2290 |
- // core |
|
2291 |
- { |
|
2292 |
- str = "url"; |
|
2293 |
- } |
|
2294 |
- // soft |
|
2295 |
- { |
|
2296 |
- if (parameters.soft) { |
|
2297 |
- str = `~${str}`; |
|
2298 |
- } |
|
2299 |
- } |
|
2300 |
- return str; |
|
2301 |
- } |
|
2302 |
- /** |
|
2303 |
- * @author fenris |
|
2304 |
- */ |
|
2305 |
- lib_shape.register({ |
|
2306 |
- "name": "url", |
|
2307 |
- "make": url_make, |
|
2308 |
- "inspect": url_inspect, |
|
2309 |
- "stance": url_stance, |
|
2310 |
- "show": url_show, |
|
2311 |
- }); |
|
2312 |
-})(lib_shape || (lib_shape = {})); |
|
2313 |
-/* |
|
2314 |
-This file is part of »bacterio-plankton:shape«. |
|
2315 |
- |
|
2316 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2317 |
-<info@greenscale.de> |
|
2318 |
- |
|
2319 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2320 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2321 |
-the Free Software Foundation, either version 3 of the License, or |
|
2322 |
-(at your option) any later version. |
|
2323 |
- |
|
2324 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2325 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2326 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2327 |
-GNU Lesser General Public License for more details. |
|
2328 |
- |
|
2329 |
-You should have received a copy of the GNU Lesser General Public License |
|
2330 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2331 |
- */ |
|
2332 |
-var lib_shape; |
|
2333 |
-(function (lib_shape) { |
|
2334 |
- /** |
|
2335 |
- * @author fenris |
|
2336 |
- */ |
|
2337 |
- function markdown_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, "type": type = "link", }) { |
|
2338 |
- if (defaultvalue === undefined) { |
|
2339 |
- defaultvalue = (soft ? null : ""); |
|
2340 |
- } |
|
2341 |
- return { |
|
2342 |
- "soft": soft, |
|
2343 |
- "mutable": mutable, |
|
2344 |
- "defaultvalue": defaultvalue, |
|
2345 |
- "type": type, |
|
2346 |
- }; |
|
2347 |
- } |
|
2348 |
- /** |
|
2349 |
- * @author fenris |
|
2350 |
- */ |
|
2351 |
- function markdown_inspect(parameters, value, _inspect) { |
|
2352 |
- let inspection = lib_shape.inspection_create(); |
|
2353 |
- if (value == undefined) { |
|
2354 |
- if (parameters.soft) { |
|
2355 |
- // all good |
|
2356 |
- } |
|
2357 |
- else { |
|
2358 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2359 |
- } |
|
2360 |
- } |
|
2361 |
- else { |
|
2362 |
- let jstype_actual = typeof (value); |
|
2363 |
- let jstype_expected = "string"; |
|
2364 |
- if (jstype_actual === jstype_expected) { |
|
2365 |
- // all good |
|
2366 |
- } |
|
2367 |
- else { |
|
2368 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2369 |
- } |
|
2370 |
- } |
|
2371 |
- return inspection; |
|
2372 |
- } |
|
2373 |
- /** |
|
2374 |
- * @author fenris |
|
2375 |
- */ |
|
2376 |
- function markdown_stance(parameters, bindings, _stance) { |
|
2377 |
- return { |
|
2378 |
- "name": "markdown", |
|
2379 |
- "parameters": parameters |
|
2380 |
- }; |
|
2381 |
- } |
|
2382 |
- /** |
|
2383 |
- * @author fenris |
|
2384 |
- */ |
|
2385 |
- function markdown_show(parameters, _show) { |
|
2386 |
- let str; |
|
2387 |
- // core |
|
2388 |
- { |
|
2389 |
- str = "markdown"; |
|
2390 |
- } |
|
2391 |
- // soft |
|
2392 |
- { |
|
2393 |
- if (parameters.soft) { |
|
2394 |
- str = `~${str}`; |
|
2395 |
- } |
|
2396 |
- } |
|
2397 |
- return str; |
|
2398 |
- } |
|
2399 |
- /** |
|
2400 |
- * @author fenris |
|
2401 |
- */ |
|
2402 |
- lib_shape.register({ |
|
2403 |
- "name": "markdown", |
|
2404 |
- "make": markdown_make, |
|
2405 |
- "inspect": markdown_inspect, |
|
2406 |
- "stance": markdown_stance, |
|
2407 |
- "show": markdown_show, |
|
2408 |
- }); |
|
2409 |
-})(lib_shape || (lib_shape = {})); |
|
2410 |
-/* |
|
2411 |
-This file is part of »bacterio-plankton:shape«. |
|
2412 |
- |
|
2413 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2414 |
-<info@greenscale.de> |
|
2415 |
- |
|
2416 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2417 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2418 |
-the Free Software Foundation, either version 3 of the License, or |
|
2419 |
-(at your option) any later version. |
|
2420 |
- |
|
2421 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2422 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2423 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2424 |
-GNU Lesser General Public License for more details. |
|
2425 |
- |
|
2426 |
-You should have received a copy of the GNU Lesser General Public License |
|
2427 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2428 |
- */ |
|
2429 |
-var lib_shape; |
|
2430 |
-(function (lib_shape) { |
|
2431 |
- /** |
|
2432 |
- * @author fenris |
|
2433 |
- */ |
|
2434 |
- function time_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { |
|
2435 |
- if (defaultvalue === undefined) { |
|
2436 |
- defaultvalue = (soft ? null : ""); |
|
2437 |
- } |
|
2438 |
- return { |
|
2439 |
- "soft": soft, |
|
2440 |
- "mutable": mutable, |
|
2441 |
- "defaultvalue": defaultvalue, |
|
2442 |
- }; |
|
2443 |
- } |
|
2444 |
- /** |
|
2445 |
- * @author fenris |
|
2446 |
- */ |
|
2447 |
- function time_inspect(parameters, value, _inspect) { |
|
2448 |
- let inspection = lib_shape.inspection_create(); |
|
2449 |
- if (value == undefined) { |
|
2450 |
- if (parameters.soft) { |
|
2451 |
- // all good |
|
2452 |
- } |
|
2453 |
- else { |
|
2454 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2455 |
- } |
|
2456 |
- } |
|
2457 |
- else { |
|
2458 |
- let jstype_actual = typeof (value); |
|
2459 |
- let jstype_expected = "object"; |
|
2460 |
- if (jstype_actual === jstype_expected) { |
|
2461 |
- // all good? |
|
2462 |
- } |
|
2463 |
- else { |
|
2464 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2465 |
- } |
|
2466 |
- } |
|
2467 |
- return inspection; |
|
2468 |
- } |
|
2469 |
- /** |
|
2470 |
- * @author fenris |
|
2471 |
- */ |
|
2472 |
- function time_stance(parameters, bindings, _stance) { |
|
2473 |
- return { |
|
2474 |
- "name": "time", |
|
2475 |
- "parameters": parameters |
|
2476 |
- }; |
|
2477 |
- } |
|
2478 |
- /** |
|
2479 |
- * @author fenris |
|
2480 |
- */ |
|
2481 |
- function time_show(parameters, _show) { |
|
2482 |
- let str; |
|
2483 |
- // core |
|
2484 |
- { |
|
2485 |
- str = "time"; |
|
2486 |
- } |
|
2487 |
- // soft |
|
2488 |
- { |
|
2489 |
- if (parameters.soft) { |
|
2490 |
- str = `~${str}`; |
|
2491 |
- } |
|
2492 |
- } |
|
2493 |
- return str; |
|
2494 |
- } |
|
2495 |
- /** |
|
2496 |
- * @author fenris |
|
2497 |
- */ |
|
2498 |
- lib_shape.register({ |
|
2499 |
- "name": "time", |
|
2500 |
- "make": time_make, |
|
2501 |
- "inspect": time_inspect, |
|
2502 |
- "stance": time_stance, |
|
2503 |
- "show": time_show, |
|
2504 |
- }); |
|
2505 |
-})(lib_shape || (lib_shape = {})); |
|
2506 |
-/* |
|
2507 |
-This file is part of »bacterio-plankton:shape«. |
|
2508 |
- |
|
2509 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2510 |
-<info@greenscale.de> |
|
2511 |
- |
|
2512 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2513 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2514 |
-the Free Software Foundation, either version 3 of the License, or |
|
2515 |
-(at your option) any later version. |
|
2516 |
- |
|
2517 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2518 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2519 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2520 |
-GNU Lesser General Public License for more details. |
|
2521 |
- |
|
2522 |
-You should have received a copy of the GNU Lesser General Public License |
|
2523 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2524 |
- */ |
|
2525 |
-var lib_shape; |
|
2526 |
-(function (lib_shape) { |
|
2527 |
- /** |
|
2528 |
- * @author fenris |
|
2529 |
- */ |
|
2530 |
- function array_make({ "soft": soft = false, "mutable": mutable = true, "shape_element": shape_element, "defaultvalue": defaultvalue = undefined, }, _make) { |
|
2531 |
- if (shape_element === undefined) { |
|
2532 |
- let message = `mandatory parameter 'shape_element' missing`; |
|
2533 |
- throw (new Error(message)); |
|
2534 |
- } |
|
2535 |
- if (defaultvalue === undefined) { |
|
2536 |
- defaultvalue = (soft ? null : []); |
|
2537 |
- } |
|
2538 |
- return { |
|
2539 |
- "soft": soft, |
|
2540 |
- "mutable": mutable, |
|
2541 |
- "shape_element": _make(shape_element), |
|
2542 |
- "defaultvalue": defaultvalue, |
|
2543 |
- }; |
|
2544 |
- } |
|
2545 |
- /** |
|
2546 |
- * @author fenris |
|
2547 |
- */ |
|
2548 |
- function array_inspect(parameters, value, _inspect) { |
|
2549 |
- let inspection = lib_shape.inspection_create(); |
|
2550 |
- if (value == undefined) { |
|
2551 |
- if (parameters.soft) { |
|
2552 |
- // all good |
|
2553 |
- } |
|
2554 |
- else { |
|
2555 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2556 |
- } |
|
2557 |
- } |
|
2558 |
- else { |
|
2559 |
- let jstype_actual = typeof (value); |
|
2560 |
- let jstype_expected = "object"; |
|
2561 |
- if (jstype_actual === jstype_expected) { |
|
2562 |
- if (value instanceof Array) { |
|
2563 |
- value.forEach((element, index) => { |
|
2564 |
- lib_shape.inspection_extend(inspection, `element #${index.toFixed(0)}`, _inspect(parameters.shape_element, element)); |
|
2565 |
- }); |
|
2566 |
- } |
|
2567 |
- else { |
|
2568 |
- lib_shape.inspection_add(inspection, `value does not seem to be an array-instance`); |
|
2569 |
- } |
|
2570 |
- } |
|
2571 |
- else { |
|
2572 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2573 |
- } |
|
2574 |
- } |
|
2575 |
- return inspection; |
|
2576 |
- } |
|
2577 |
- /** |
|
2578 |
- * @author fenris |
|
2579 |
- */ |
|
2580 |
- function array_stance(parameters, bindings, _stance) { |
|
2581 |
- return { |
|
2582 |
- "name": "array", |
|
2583 |
- "parameters": { |
|
2584 |
- "soft": parameters.soft, |
|
2585 |
- "shape_element": _stance(parameters.shape_element, bindings) |
|
2586 |
- } |
|
2587 |
- }; |
|
2588 |
- } |
|
2589 |
- /** |
|
2590 |
- * @author fenris |
|
2591 |
- */ |
|
2592 |
- function array_show(parameters, _show) { |
|
2593 |
- let str; |
|
2594 |
- // core |
|
2595 |
- { |
|
2596 |
- str = "array"; |
|
2597 |
- } |
|
2598 |
- // shape_element |
|
2599 |
- { |
|
2600 |
- str += ("<" |
|
2601 |
- + |
|
2602 |
- _show(parameters.shape_element) |
|
2603 |
- + |
|
2604 |
- ">"); |
|
2605 |
- } |
|
2606 |
- // soft |
|
2607 |
- { |
|
2608 |
- if (parameters.soft) { |
|
2609 |
- str = `~${str}`; |
|
2610 |
- } |
|
2611 |
- } |
|
2612 |
- return str; |
|
2613 |
- } |
|
2614 |
- /** |
|
2615 |
- * @author fenris |
|
2616 |
- */ |
|
2617 |
- lib_shape.register({ |
|
2618 |
- "name": "array", |
|
2619 |
- "make": array_make, |
|
2620 |
- "inspect": array_inspect, |
|
2621 |
- "stance": array_stance, |
|
2622 |
- "show": array_show, |
|
2623 |
- }); |
|
2624 |
-})(lib_shape || (lib_shape = {})); |
|
2625 |
-/* |
|
2626 |
-This file is part of »bacterio-plankton:shape«. |
|
2627 |
- |
|
2628 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2629 |
-<info@greenscale.de> |
|
2630 |
- |
|
2631 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2632 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2633 |
-the Free Software Foundation, either version 3 of the License, or |
|
2634 |
-(at your option) any later version. |
|
2635 |
- |
|
2636 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2637 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2638 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2639 |
-GNU Lesser General Public License for more details. |
|
2640 |
- |
|
2641 |
-You should have received a copy of the GNU Lesser General Public License |
|
2642 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2643 |
- */ |
|
2644 |
-var lib_shape; |
|
2645 |
-(function (lib_shape) { |
|
2646 |
- /** |
|
2647 |
- * @author fenris |
|
2648 |
- */ |
|
2649 |
- function enumeration_make({ "soft": soft = false, "mutable": mutable = true, "shape_option": shape_option, "options": options, "defaultvalue": defaultvalue = undefined, }, _make) { |
|
2650 |
- if (shape_option === undefined) { |
|
2651 |
- let message = `mandatory parameter 'shape_option' missing`; |
|
2652 |
- throw (new Error(message)); |
|
2653 |
- } |
|
2654 |
- if (options === undefined) { |
|
2655 |
- let message = `mandatory parameter 'options' missing`; |
|
2656 |
- throw (new Error(message)); |
|
2657 |
- } |
|
2658 |
- if (defaultvalue === undefined) { |
|
2659 |
- defaultvalue = (soft ? null : options[0].value); |
|
2660 |
- } |
|
2661 |
- return { |
|
2662 |
- "soft": soft, |
|
2663 |
- "mutable": mutable, |
|
2664 |
- "shape_option": _make(shape_option), |
|
2665 |
- "options": options, |
|
2666 |
- "defaultvalue": defaultvalue, |
|
2667 |
- }; |
|
2668 |
- } |
|
2669 |
- /** |
|
2670 |
- * @author fenris |
|
2671 |
- */ |
|
2672 |
- function enumeration_inspect(parameters, value, _inspect) { |
|
2673 |
- let inspection = lib_shape.inspection_create(); |
|
2674 |
- if (value == undefined) { |
|
2675 |
- if (parameters.soft) { |
|
2676 |
- // all good |
|
2677 |
- } |
|
2678 |
- else { |
|
2679 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2680 |
- } |
|
2681 |
- } |
|
2682 |
- else { |
|
2683 |
- lib_shape.inspection_extend(inspection, `given value for enumeration`, _inspect(parameters.shape_option, value)); |
|
2684 |
- // TODO: check if corresponding option exists |
|
2685 |
- } |
|
2686 |
- return inspection; |
|
2687 |
- } |
|
2688 |
- /** |
|
2689 |
- * @author fenris |
|
2690 |
- */ |
|
2691 |
- function enumeration_stance(parameters, bindings, _stance) { |
|
2692 |
- return { |
|
2693 |
- "name": "enumeration", |
|
2694 |
- "parameters": { |
|
2695 |
- "soft": parameters.soft, |
|
2696 |
- "shape_option": _stance(parameters.shape_option, bindings), |
|
2697 |
- "options": parameters.options, |
|
2698 |
- } |
|
2699 |
- }; |
|
2700 |
- } |
|
2701 |
- /** |
|
2702 |
- * @author fenris |
|
2703 |
- */ |
|
2704 |
- function enumeration_show(parameters, _show) { |
|
2705 |
- let str; |
|
2706 |
- // core |
|
2707 |
- { |
|
2708 |
- str = "enumeration"; |
|
2709 |
- } |
|
2710 |
- // shape_option |
|
2711 |
- { |
|
2712 |
- str += ("<" |
|
2713 |
- + |
|
2714 |
- parameters.options.map(option => String(option)).join(",") + ":" + _show(parameters.shape_option) |
|
2715 |
- + |
|
2716 |
- ">"); |
|
2717 |
- } |
|
2718 |
- // soft |
|
2719 |
- { |
|
2720 |
- if (parameters.soft) { |
|
2721 |
- str = `~${str}`; |
|
2722 |
- } |
|
2723 |
- } |
|
2724 |
- return str; |
|
2725 |
- } |
|
2726 |
- /** |
|
2727 |
- * @author fenris |
|
2728 |
- */ |
|
2729 |
- lib_shape.register({ |
|
2730 |
- "name": "enumeration", |
|
2731 |
- "make": enumeration_make, |
|
2732 |
- "inspect": enumeration_inspect, |
|
2733 |
- "stance": enumeration_stance, |
|
2734 |
- "show": enumeration_show, |
|
2735 |
- }); |
|
2736 |
-})(lib_shape || (lib_shape = {})); |
|
2737 |
-/* |
|
2738 |
-This file is part of »bacterio-plankton:shape«. |
|
2739 |
- |
|
2740 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2741 |
-<info@greenscale.de> |
|
2742 |
- |
|
2743 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2744 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2745 |
-the Free Software Foundation, either version 3 of the License, or |
|
2746 |
-(at your option) any later version. |
|
2747 |
- |
|
2748 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2749 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2750 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2751 |
-GNU Lesser General Public License for more details. |
|
2752 |
- |
|
2753 |
-You should have received a copy of the GNU Lesser General Public License |
|
2754 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2755 |
- */ |
|
2756 |
-var lib_shape; |
|
2757 |
-(function (lib_shape) { |
|
2758 |
- /** |
|
2759 |
- * @author fenris |
|
2760 |
- */ |
|
2761 |
- function date_make({ "soft": soft = false, "mutable": mutable = true, "defaultvalue": defaultvalue = undefined, }) { |
|
2762 |
- if (defaultvalue === undefined) { |
|
2763 |
- defaultvalue = (soft ? null : (new Date(Date.now()))); |
|
2764 |
- } |
|
2765 |
- return { |
|
2766 |
- "soft": soft, |
|
2767 |
- "mutable": mutable, |
|
2768 |
- "defaultvalue": defaultvalue, |
|
2769 |
- }; |
|
2770 |
- } |
|
2771 |
- /** |
|
2772 |
- * @author fenris |
|
2773 |
- */ |
|
2774 |
- function date_inspect(parameters, value, _inspect) { |
|
2775 |
- let inspection = lib_shape.inspection_create(); |
|
2776 |
- if (value == undefined) { |
|
2777 |
- if (parameters.soft) { |
|
2778 |
- // all good |
|
2779 |
- } |
|
2780 |
- else { |
|
2781 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2782 |
- } |
|
2783 |
- } |
|
2784 |
- else { |
|
2785 |
- let jstype_actual = typeof (value); |
|
2786 |
- let jstype_expected = "object"; |
|
2787 |
- if (jstype_actual === jstype_expected) { |
|
2788 |
- if (value instanceof Date) { |
|
2789 |
- // all gode |
|
2790 |
- } |
|
2791 |
- else { |
|
2792 |
- lib_shape.inspection_add(inspection, `value does not seem to be a date-instance`); |
|
2793 |
- } |
|
2794 |
- } |
|
2795 |
- else { |
|
2796 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2797 |
- } |
|
2798 |
- } |
|
2799 |
- return inspection; |
|
2800 |
- } |
|
2801 |
- /** |
|
2802 |
- * @author fenris |
|
2803 |
- */ |
|
2804 |
- function date_stance(parameters, bindings, _stance) { |
|
2805 |
- return { |
|
2806 |
- "name": "date", |
|
2807 |
- "parameters": parameters |
|
2808 |
- }; |
|
2809 |
- } |
|
2810 |
- /** |
|
2811 |
- * @author fenris |
|
2812 |
- */ |
|
2813 |
- function date_show(parameters, _show) { |
|
2814 |
- let str; |
|
2815 |
- // core |
|
2816 |
- { |
|
2817 |
- str = "date"; |
|
2818 |
- } |
|
2819 |
- // soft |
|
2820 |
- { |
|
2821 |
- if (parameters.soft) { |
|
2822 |
- str = `~${str}`; |
|
2823 |
- } |
|
2824 |
- } |
|
2825 |
- return str; |
|
2826 |
- } |
|
2827 |
- /** |
|
2828 |
- * @author fenris |
|
2829 |
- */ |
|
2830 |
- lib_shape.register({ |
|
2831 |
- "name": "date", |
|
2832 |
- "make": date_make, |
|
2833 |
- "inspect": date_inspect, |
|
2834 |
- "stance": date_stance, |
|
2835 |
- "show": date_show, |
|
2836 |
- }); |
|
2837 |
-})(lib_shape || (lib_shape = {})); |
|
2838 |
-/* |
|
2839 |
-This file is part of »bacterio-plankton:shape«. |
|
2840 |
- |
|
2841 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2842 |
-<info@greenscale.de> |
|
2843 |
- |
|
2844 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2845 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2846 |
-the Free Software Foundation, either version 3 of the License, or |
|
2847 |
-(at your option) any later version. |
|
2848 |
- |
|
2849 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2850 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2851 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2852 |
-GNU Lesser General Public License for more details. |
|
2853 |
- |
|
2854 |
-You should have received a copy of the GNU Lesser General Public License |
|
2855 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2856 |
- */ |
|
2857 |
-var lib_shape; |
|
2858 |
-(function (lib_shape) { |
|
2859 |
- /** |
|
2860 |
- * @author fenris |
|
2861 |
- */ |
|
2862 |
- function record_make({ "soft": soft = false, "mutable": mutable = true, "fields": fields = [], "defaultvalue": defaultvalue = undefined, }, _make) { |
|
2863 |
- let fields_ = (fields |
|
2864 |
- .map((field) => ({ "name": field.name, "shape": _make(field.shape) }))); |
|
2865 |
- if (defaultvalue === undefined) { |
|
2866 |
- if (soft) { |
|
2867 |
- defaultvalue = null; |
|
2868 |
- } |
|
2869 |
- else { |
|
2870 |
- defaultvalue = {}; |
|
2871 |
- fields_.forEach(field => { |
|
2872 |
- defaultvalue[field.name] = field.shape.parameters["defaultvalue"]; |
|
2873 |
- }); |
|
2874 |
- } |
|
2875 |
- } |
|
2876 |
- return { |
|
2877 |
- "soft": soft, |
|
2878 |
- "mutable": mutable, |
|
2879 |
- "fields": fields_, |
|
2880 |
- "defaultvalue": defaultvalue, |
|
2881 |
- }; |
|
2882 |
- } |
|
2883 |
- /** |
|
2884 |
- * @author fenris |
|
2885 |
- */ |
|
2886 |
- function record_inspect(parameters, value, _inspect) { |
|
2887 |
- let inspection = lib_shape.inspection_create(); |
|
2888 |
- if (value == undefined) { |
|
2889 |
- if (parameters.soft) { |
|
2890 |
- // all good |
|
2891 |
- } |
|
2892 |
- else { |
|
2893 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
2894 |
- } |
|
2895 |
- } |
|
2896 |
- else { |
|
2897 |
- let jstype_actual = typeof (value); |
|
2898 |
- let jstype_expected = "object"; |
|
2899 |
- if (jstype_actual === jstype_expected) { |
|
2900 |
- parameters.fields.forEach(field => { |
|
2901 |
- let value_ = value[field.name]; |
|
2902 |
- lib_shape.inspection_extend(inspection, `field '${field.name}'`, _inspect(field.shape, value_)); |
|
2903 |
- }); |
|
2904 |
- } |
|
2905 |
- else { |
|
2906 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
2907 |
- } |
|
2908 |
- } |
|
2909 |
- return inspection; |
|
2910 |
- } |
|
2911 |
- /** |
|
2912 |
- * @author fenris |
|
2913 |
- */ |
|
2914 |
- function record_stance(parameters, bindings, _stance) { |
|
2915 |
- return { |
|
2916 |
- "name": "record", |
|
2917 |
- "parameters": { |
|
2918 |
- "soft": parameters.soft, |
|
2919 |
- "fields": parameters.fields.map(field => { |
|
2920 |
- return { |
|
2921 |
- "name": field.name, |
|
2922 |
- "shape": _stance(field.shape, bindings) |
|
2923 |
- }; |
|
2924 |
- }) |
|
2925 |
- } |
|
2926 |
- }; |
|
2927 |
- } |
|
2928 |
- /** |
|
2929 |
- * @author fenris |
|
2930 |
- */ |
|
2931 |
- function record_show(parameters, _show) { |
|
2932 |
- let str; |
|
2933 |
- // core |
|
2934 |
- { |
|
2935 |
- str = "record"; |
|
2936 |
- } |
|
2937 |
- // fields |
|
2938 |
- { |
|
2939 |
- str += ("<" |
|
2940 |
- + |
|
2941 |
- parameters.fields.map(field => (field.name + ":" + _show(field.shape))).join(",") |
|
2942 |
- + |
|
2943 |
- ">"); |
|
2944 |
- } |
|
2945 |
- // soft |
|
2946 |
- { |
|
2947 |
- if (parameters.soft) { |
|
2948 |
- str = `~${str}`; |
|
2949 |
- } |
|
2950 |
- } |
|
2951 |
- return str; |
|
2952 |
- } |
|
2953 |
- /** |
|
2954 |
- * @author fenris |
|
2955 |
- */ |
|
2956 |
- lib_shape.register({ |
|
2957 |
- "name": "record", |
|
2958 |
- "make": record_make, |
|
2959 |
- "inspect": record_inspect, |
|
2960 |
- "stance": record_stance, |
|
2961 |
- "show": record_show, |
|
2962 |
- }); |
|
2963 |
-})(lib_shape || (lib_shape = {})); |
|
2964 |
-/* |
|
2965 |
-This file is part of »bacterio-plankton:shape«. |
|
2966 |
- |
|
2967 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
2968 |
-<info@greenscale.de> |
|
2969 |
- |
|
2970 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
2971 |
-it under the terms of the GNU Lesser General Public License as published by |
|
2972 |
-the Free Software Foundation, either version 3 of the License, or |
|
2973 |
-(at your option) any later version. |
|
2974 |
- |
|
2975 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
2976 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
2977 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2978 |
-GNU Lesser General Public License for more details. |
|
2979 |
- |
|
2980 |
-You should have received a copy of the GNU Lesser General Public License |
|
2981 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
2982 |
- */ |
|
2983 |
-var lib_shape; |
|
2984 |
-(function (lib_shape) { |
|
2985 |
- /** |
|
2986 |
- * @author fenris |
|
2987 |
- */ |
|
2988 |
- function map_make({ "soft": soft = false, "mutable": mutable = true, "shape_key": shape_key, "shape_value": shape_value, "defaultvalue": defaultvalue = undefined, }, _make) { |
|
2989 |
- if (shape_key === undefined) { |
|
2990 |
- let message = `mandatory parameter 'shape_key' missing`; |
|
2991 |
- throw (new Error(message)); |
|
2992 |
- } |
|
2993 |
- if (shape_value === undefined) { |
|
2994 |
- let message = `mandatory parameter 'shape_value' missing`; |
|
2995 |
- throw (new Error(message)); |
|
2996 |
- } |
|
2997 |
- if (defaultvalue === undefined) { |
|
2998 |
- defaultvalue = (soft ? null : {}); |
|
2999 |
- } |
|
3000 |
- return { |
|
3001 |
- "soft": soft, |
|
3002 |
- "mutable": mutable, |
|
3003 |
- "shape_key": _make(shape_key), |
|
3004 |
- "shape_value": _make(shape_value), |
|
3005 |
- "defaultvalue": defaultvalue, |
|
3006 |
- }; |
|
3007 |
- } |
|
3008 |
- /** |
|
3009 |
- * @author fenris |
|
3010 |
- */ |
|
3011 |
- function map_stance(parameters, bindings, _stance) { |
|
3012 |
- return { |
|
3013 |
- "name": "map", |
|
3014 |
- "parameters": { |
|
3015 |
- "soft": parameters.soft, |
|
3016 |
- "shape_key": _stance(parameters.shape_key, bindings), |
|
3017 |
- "shape_value": _stance(parameters.shape_value, bindings) |
|
3018 |
- } |
|
3019 |
- }; |
|
3020 |
- } |
|
3021 |
- /** |
|
3022 |
- * @author fenris |
|
3023 |
- * @todo closer look not possible? |
|
3024 |
- */ |
|
3025 |
- function map_inspect(parameters, value, _inspect) { |
|
3026 |
- let inspection = lib_shape.inspection_create(); |
|
3027 |
- if (value == undefined) { |
|
3028 |
- if (parameters.soft) { |
|
3029 |
- // all good |
|
3030 |
- } |
|
3031 |
- else { |
|
3032 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
3033 |
- } |
|
3034 |
- } |
|
3035 |
- else { |
|
3036 |
- let jstype_actual = typeof (value); |
|
3037 |
- let jstype_expected = "object"; |
|
3038 |
- if (jstype_actual === jstype_expected) { |
|
3039 |
- Object.keys(value).forEach(key => { |
|
3040 |
- lib_shape.inspection_extend(inspection, `key '${key}'`, _inspect(parameters.shape_key, key)); |
|
3041 |
- let value_ = value[key]; |
|
3042 |
- lib_shape.inspection_extend(inspection, `value for key '${key}'`, _inspect(parameters.shape_value, value_)); |
|
3043 |
- }); |
|
3044 |
- } |
|
3045 |
- else { |
|
3046 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
3047 |
- } |
|
3048 |
- } |
|
3049 |
- return inspection; |
|
3050 |
- } |
|
3051 |
- /** |
|
3052 |
- * @author fenris |
|
3053 |
- */ |
|
3054 |
- function map_show(parameters, _show) { |
|
3055 |
- let str; |
|
3056 |
- // core |
|
3057 |
- { |
|
3058 |
- str = "map"; |
|
3059 |
- } |
|
3060 |
- // in/out |
|
3061 |
- { |
|
3062 |
- str += ("<" |
|
3063 |
- + |
|
3064 |
- [ |
|
3065 |
- _show(parameters.shape_key), |
|
3066 |
- _show(parameters.shape_value), |
|
3067 |
- ].join(",") |
|
3068 |
- + |
|
3069 |
- ">"); |
|
3070 |
- } |
|
3071 |
- // soft |
|
3072 |
- { |
|
3073 |
- if (parameters.soft) { |
|
3074 |
- str = `~${str}`; |
|
3075 |
- } |
|
3076 |
- } |
|
3077 |
- return str; |
|
3078 |
- } |
|
3079 |
- /** |
|
3080 |
- * @author fenris |
|
3081 |
- */ |
|
3082 |
- lib_shape.register({ |
|
3083 |
- "name": "map", |
|
3084 |
- "make": map_make, |
|
3085 |
- "inspect": map_inspect, |
|
3086 |
- "stance": map_stance, |
|
3087 |
- "show": map_show, |
|
3088 |
- }); |
|
3089 |
-})(lib_shape || (lib_shape = {})); |
|
3090 |
-/* |
|
3091 |
-This file is part of »bacterio-plankton:shape«. |
|
3092 |
- |
|
3093 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
3094 |
-<info@greenscale.de> |
|
3095 |
- |
|
3096 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
3097 |
-it under the terms of the GNU Lesser General Public License as published by |
|
3098 |
-the Free Software Foundation, either version 3 of the License, or |
|
3099 |
-(at your option) any later version. |
|
3100 |
- |
|
3101 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
3102 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3103 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3104 |
-GNU Lesser General Public License for more details. |
|
3105 |
- |
|
3106 |
-You should have received a copy of the GNU Lesser General Public License |
|
3107 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
3108 |
- */ |
|
3109 |
-var lib_shape; |
|
3110 |
-(function (lib_shape) { |
|
3111 |
- /** |
|
3112 |
- * @author fenris |
|
3113 |
- */ |
|
3114 |
- function maybe_make({ "soft": soft = false, "shape_value": shape_value, "defaultvalue": defaultvalue = undefined, }, _make) { |
|
3115 |
- if (shape_value === undefined) { |
|
3116 |
- let message = `mandatory parameter 'shape_value' missing`; |
|
3117 |
- throw (new Error(message)); |
|
3118 |
- } |
|
3119 |
- if (defaultvalue === undefined) { |
|
3120 |
- defaultvalue = (soft ? null : { "kind": "nothing" }); |
|
3121 |
- } |
|
3122 |
- return { |
|
3123 |
- "soft": soft, |
|
3124 |
- "shape_value": _make(shape_value), |
|
3125 |
- "defaultvalue": defaultvalue, |
|
3126 |
- }; |
|
3127 |
- } |
|
3128 |
- /** |
|
3129 |
- * @author fenris |
|
3130 |
- */ |
|
3131 |
- function maybe_inspect(parameters, value, _inspect) { |
|
3132 |
- let inspection = lib_shape.inspection_create(); |
|
3133 |
- if (value == undefined) { |
|
3134 |
- if (parameters.soft) { |
|
3135 |
- // all good |
|
3136 |
- } |
|
3137 |
- else { |
|
3138 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
3139 |
- } |
|
3140 |
- } |
|
3141 |
- else { |
|
3142 |
- let jstype_actual = typeof (value); |
|
3143 |
- let jstype_expected = "object"; |
|
3144 |
- if (jstype_actual === jstype_expected) { |
|
3145 |
- if ("kind" in value) { |
|
3146 |
- // all good? |
|
3147 |
- } |
|
3148 |
- else { |
|
3149 |
- lib_shape.inspection_add(inspection, `field 'kind' missing`); |
|
3150 |
- } |
|
3151 |
- } |
|
3152 |
- else { |
|
3153 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
3154 |
- } |
|
3155 |
- } |
|
3156 |
- return inspection; |
|
3157 |
- } |
|
3158 |
- /** |
|
3159 |
- * @author fenris |
|
3160 |
- */ |
|
3161 |
- function maybe_stance(parameters, bindings, _stance) { |
|
3162 |
- return { |
|
3163 |
- "name": "maybe", |
|
3164 |
- "parameters": { |
|
3165 |
- "soft": parameters.soft, |
|
3166 |
- "shape_value": _stance(parameters.shape_value, bindings) |
|
3167 |
- } |
|
3168 |
- }; |
|
3169 |
- } |
|
3170 |
- /** |
|
3171 |
- * @author fenris |
|
3172 |
- */ |
|
3173 |
- function maybe_show(parameters, _show) { |
|
3174 |
- let str; |
|
3175 |
- // core |
|
3176 |
- { |
|
3177 |
- str = "maybe"; |
|
3178 |
- } |
|
3179 |
- // shape_value |
|
3180 |
- { |
|
3181 |
- str += ("<" |
|
3182 |
- + |
|
3183 |
- _show(parameters.shape_value) |
|
3184 |
- + |
|
3185 |
- ">"); |
|
3186 |
- } |
|
3187 |
- // soft |
|
3188 |
- { |
|
3189 |
- if (parameters.soft) { |
|
3190 |
- str = `~${str}`; |
|
3191 |
- } |
|
3192 |
- } |
|
3193 |
- return str; |
|
3194 |
- } |
|
3195 |
- /** |
|
3196 |
- * @author fenris |
|
3197 |
- */ |
|
3198 |
- lib_shape.register({ |
|
3199 |
- "name": "maybe", |
|
3200 |
- "make": maybe_make, |
|
3201 |
- "inspect": maybe_inspect, |
|
3202 |
- "stance": maybe_stance, |
|
3203 |
- "show": maybe_show, |
|
3204 |
- }); |
|
3205 |
-})(lib_shape || (lib_shape = {})); |
|
3206 |
-/* |
|
3207 |
-This file is part of »bacterio-plankton:shape«. |
|
3208 |
- |
|
3209 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
3210 |
-<info@greenscale.de> |
|
3211 |
- |
|
3212 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
3213 |
-it under the terms of the GNU Lesser General Public License as published by |
|
3214 |
-the Free Software Foundation, either version 3 of the License, or |
|
3215 |
-(at your option) any later version. |
|
3216 |
- |
|
3217 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
3218 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3219 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3220 |
-GNU Lesser General Public License for more details. |
|
3221 |
- |
|
3222 |
-You should have received a copy of the GNU Lesser General Public License |
|
3223 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
3224 |
- */ |
|
3225 |
-var lib_shape; |
|
3226 |
-(function (lib_shape) { |
|
3227 |
- /** |
|
3228 |
- * @author fenris |
|
3229 |
- */ |
|
3230 |
- function promise_make({ "soft": soft = false, "shape_result": shape_result, "shape_reason": shape_reason, "defaultvalue": defaultvalue = undefined, }, _make) { |
|
3231 |
- if (shape_result === undefined) { |
|
3232 |
- let message = `mandatory parameter 'shape_result' missing`; |
|
3233 |
- throw (new Error(message)); |
|
3234 |
- } |
|
3235 |
- if (shape_reason === undefined) { |
|
3236 |
- let message = `mandatory parameter 'shape_reason' missing`; |
|
3237 |
- throw (new Error(message)); |
|
3238 |
- } |
|
3239 |
- if (defaultvalue === undefined) { |
|
3240 |
- defaultvalue = (soft ? null : Promise.resolve(null)); |
|
3241 |
- } |
|
3242 |
- return { |
|
3243 |
- "soft": soft, |
|
3244 |
- "shape_result": _make(shape_result), |
|
3245 |
- "shape_reason": _make(shape_reason), |
|
3246 |
- "defaultvalue": defaultvalue, |
|
3247 |
- }; |
|
3248 |
- } |
|
3249 |
- /** |
|
3250 |
- * @author fenris |
|
3251 |
- */ |
|
3252 |
- function promise_stance(parameters, bindings, _stance) { |
|
3253 |
- return { |
|
3254 |
- "name": "promise", |
|
3255 |
- "parameters": { |
|
3256 |
- "soft": parameters.soft, |
|
3257 |
- "shape_result": _stance(parameters.shape_result, bindings), |
|
3258 |
- "shape_reason": _stance(parameters.shape_reason, bindings) |
|
3259 |
- } |
|
3260 |
- }; |
|
3261 |
- } |
|
3262 |
- /** |
|
3263 |
- * @author fenris |
|
3264 |
- * @todo closer look not possible? |
|
3265 |
- */ |
|
3266 |
- function promise_inspect(parameters, value, _inspect) { |
|
3267 |
- let inspection = lib_shape.inspection_create(); |
|
3268 |
- if (value == undefined) { |
|
3269 |
- if (parameters.soft) { |
|
3270 |
- // all good |
|
3271 |
- } |
|
3272 |
- else { |
|
3273 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
3274 |
- } |
|
3275 |
- } |
|
3276 |
- else { |
|
3277 |
- let jstype_actual = typeof (value); |
|
3278 |
- let jstype_expected = "object"; |
|
3279 |
- if (jstype_actual === jstype_expected) { |
|
3280 |
- if (value instanceof Promise /*<any, any>*/) { |
|
3281 |
- // all good? |
|
3282 |
- } |
|
3283 |
- else { |
|
3284 |
- lib_shape.inspection_add(inspection, `values is not an Promise-instance`); |
|
3285 |
- } |
|
3286 |
- } |
|
3287 |
- else { |
|
3288 |
- lib_shape.inspection_add(inspection, `expected JS-type '${jstype_expected}' but got '${jstype_actual}'`); |
|
3289 |
- } |
|
3290 |
- } |
|
3291 |
- return inspection; |
|
3292 |
- } |
|
3293 |
- /** |
|
3294 |
- * @author fenris |
|
3295 |
- */ |
|
3296 |
- function promise_show(parameters, _show) { |
|
3297 |
- let str; |
|
3298 |
- // core |
|
3299 |
- { |
|
3300 |
- str = "promise"; |
|
3301 |
- } |
|
3302 |
- // in/out |
|
3303 |
- { |
|
3304 |
- str += ("<" |
|
3305 |
- + |
|
3306 |
- [ |
|
3307 |
- _show(parameters.shape_result), |
|
3308 |
- _show(parameters.shape_reason), |
|
3309 |
- ].join(",") |
|
3310 |
- + |
|
3311 |
- ">"); |
|
3312 |
- } |
|
3313 |
- // soft |
|
3314 |
- { |
|
3315 |
- if (parameters.soft) { |
|
3316 |
- str = `~${str}`; |
|
3317 |
- } |
|
3318 |
- } |
|
3319 |
- return str; |
|
3320 |
- } |
|
3321 |
- /** |
|
3322 |
- * @author fenris |
|
3323 |
- */ |
|
3324 |
- lib_shape.register({ |
|
3325 |
- "name": "promise", |
|
3326 |
- "make": promise_make, |
|
3327 |
- "inspect": promise_inspect, |
|
3328 |
- "stance": promise_stance, |
|
3329 |
- "show": promise_show, |
|
3330 |
- }); |
|
3331 |
-})(lib_shape || (lib_shape = {})); |
|
3332 |
-/* |
|
3333 |
-This file is part of »bacterio-plankton:shape«. |
|
3334 |
- |
|
3335 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
3336 |
-<info@greenscale.de> |
|
3337 |
- |
|
3338 |
-»bacterio-plankton:shape« is free software: you can redistribute it and/or modify |
|
3339 |
-it under the terms of the GNU Lesser General Public License as published by |
|
3340 |
-the Free Software Foundation, either version 3 of the License, or |
|
3341 |
-(at your option) any later version. |
|
3342 |
- |
|
3343 |
-»bacterio-plankton:shape« is distributed in the hope that it will be useful, |
|
3344 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3345 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3346 |
-GNU Lesser General Public License for more details. |
|
3347 |
- |
|
3348 |
-You should have received a copy of the GNU Lesser General Public License |
|
3349 |
-along with »bacterio-plankton:shape«. If not, see <http://www.gnu.org/licenses/>. |
|
3350 |
- */ |
|
3351 |
-var lib_shape; |
|
3352 |
-(function (lib_shape) { |
|
3353 |
- /** |
|
3354 |
- * @author fenris |
|
3355 |
- * @todo use a treemap-function (but first make one :P) |
|
3356 |
- */ |
|
3357 |
- function adjust_labels(shape, transformator) { |
|
3358 |
- if (false) { |
|
3359 |
- } |
|
3360 |
- else if (shape.name === "enumeration") { |
|
3361 |
- return { |
|
3362 |
- "name": "enumeration", |
|
3363 |
- "parameters": { |
|
3364 |
- "soft": shape.parameters["soft"], |
|
3365 |
- "shape_option": adjust_labels(shape.parameters["shape_option"], transformator), |
|
3366 |
- "options": shape.parameters["options"].map(option => { |
|
3367 |
- return { |
|
3368 |
- "value": option.value, |
|
3369 |
- "label": transformator(option.label), |
|
3370 |
- }; |
|
3371 |
- }), |
|
3372 |
- "defaultvalue": shape.parameters["defaultvalue"], |
|
3373 |
- } |
|
3374 |
- }; |
|
3375 |
- } |
|
3376 |
- else if (shape.name === "array") { |
|
3377 |
- return { |
|
3378 |
- "name": "array", |
|
3379 |
- "parameters": { |
|
3380 |
- "soft": shape.parameters["soft"], |
|
3381 |
- "shape_element": adjust_labels(shape.parameters["shape_element"], transformator), |
|
3382 |
- "defaultvalue": shape.parameters["defaultvalue"], |
|
3383 |
- } |
|
3384 |
- }; |
|
3385 |
- } |
|
3386 |
- else if (shape.name === "record") { |
|
3387 |
- return { |
|
3388 |
- "name": "record", |
|
3389 |
- "parameters": { |
|
3390 |
- "soft": shape.parameters["soft"], |
|
3391 |
- "fields": shape.parameters["fields"].map(field => { |
|
3392 |
- return { |
|
3393 |
- "name": field.name, |
|
3394 |
- "shape": adjust_labels(field.shape, transformator), |
|
3395 |
- "label": transformator(field.label), |
|
3396 |
- }; |
|
3397 |
- }), |
|
3398 |
- "defaultvalue": shape.parameters["defaultvalue"], |
|
3399 |
- } |
|
3400 |
- }; |
|
3401 |
- } |
|
3402 |
- // lil' hacky … |
|
3403 |
- else { |
|
3404 |
- // shape["label"] = ((shape["label"] == null) ? null : transformator(shape["label"])); |
|
3405 |
- return shape; |
|
3406 |
- } |
|
3407 |
- } |
|
3408 |
- lib_shape.adjust_labels = adjust_labels; |
|
3409 |
- /** |
|
3410 |
- * @author fenris |
|
3411 |
- */ |
|
3412 |
- function register_(id, factory) { |
|
3413 |
- const message = "not implemented; dummy impl"; |
|
3414 |
- console.warn(message); |
|
3415 |
- } |
|
3416 |
- lib_shape.register_ = register_; |
|
3417 |
- /** |
|
3418 |
- * @author fenris |
|
3419 |
- */ |
|
3420 |
- function retrieve_(id) { |
|
3421 |
- const message = "not implemented; returning dummy"; |
|
3422 |
- console.warn(message); |
|
3423 |
- return { "name": "any" }; |
|
3424 |
- } |
|
3425 |
- lib_shape.retrieve_ = retrieve_; |
|
3426 |
-})(lib_shape || (lib_shape = {})); |
|
3427 |
-/* |
|
3428 |
-This file is part of »bacterio-plankton:trait«. |
|
3429 |
- |
|
3430 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
3431 |
- |
|
3432 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
3433 |
-it under the terms of the GNU Lesser General Public License as published by |
|
3434 |
-the Free Software Foundation, either version 3 of the License, or |
|
3435 |
-(at your option) any later version. |
|
3436 |
- |
|
3437 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
3438 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3439 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3440 |
-GNU Lesser General Public License for more details. |
|
3441 |
- |
|
3442 |
-You should have received a copy of the GNU Lesser General Public License |
|
3443 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
3444 |
- */ |
|
3445 |
-var lib_trait; |
|
3446 |
-(function (lib_trait) { |
|
3447 |
- /** |
|
3448 |
- * @author fenris |
|
3449 |
- */ |
|
3450 |
- function domain_make(_a, _make) { |
|
3451 |
- var _b = _a["soft"], soft = _b === void 0 ? false : _b, kind = _a["kind"]; |
|
3452 |
- return { |
|
3453 |
- "soft": soft, |
|
3454 |
- "kind": kind |
|
3455 |
- }; |
|
3456 |
- } |
|
3457 |
- /** |
|
3458 |
- * @author fenris |
|
3459 |
- */ |
|
3460 |
- function domain_inspect(parameters, value, _inspect) { |
|
3461 |
- var inspection = lib_shape.inspection_create(); |
|
3462 |
- if (value == undefined) { |
|
3463 |
- if (parameters.soft) { |
|
3464 |
- // all good |
|
3465 |
- } |
|
3466 |
- else { |
|
3467 |
- lib_shape.inspection_add(inspection, "null is not allowed"); |
|
3468 |
- } |
|
3469 |
- } |
|
3470 |
- else { |
|
3471 |
- var jstype_actual = typeof (value); |
|
3472 |
- var jstype_expected = "object"; |
|
3473 |
- if (jstype_actual === jstype_expected) { |
|
3474 |
- if ("domain" in value) { |
|
3475 |
- var domain_actual = value["domain"]["kind"]; |
|
3476 |
- var domain_expected = parameters.kind; |
|
3477 |
- if (domain_actual == domain_expected) { |
|
3478 |
- // all good? |
|
3479 |
- } |
|
3480 |
- else { |
|
3481 |
- lib_shape.inspection_add(inspection, "expected domain-kind '" + domain_expected + "' but got '" + domain_actual + "'"); |
|
3482 |
- } |
|
3483 |
- } |
|
3484 |
- else { |
|
3485 |
- lib_shape.inspection_add(inspection, "field 'domain' missing"); |
|
3486 |
- } |
|
3487 |
- } |
|
3488 |
- else { |
|
3489 |
- lib_shape.inspection_add(inspection, "expected JS-type '" + jstype_expected + "' but got '" + jstype_actual + "'"); |
|
3490 |
- } |
|
3491 |
- } |
|
3492 |
- return inspection; |
|
3493 |
- } |
|
3494 |
- /** |
|
3495 |
- * @author fenris |
|
3496 |
- */ |
|
3497 |
- function domain_stance(parameters, bindings, _stance) { |
|
3498 |
- return { |
|
3499 |
- "name": "domain", |
|
3500 |
- "parameters": { |
|
3501 |
- "soft": parameters.soft, |
|
3502 |
- "kind": parameters.kind |
|
3503 |
- } |
|
3504 |
- }; |
|
3505 |
- } |
|
3506 |
- /** |
|
3507 |
- * @author fenris |
|
3508 |
- */ |
|
3509 |
- function domain_show(parameters, _show) { |
|
3510 |
- var str; |
|
3511 |
- // core |
|
3512 |
- { |
|
3513 |
- str = ("#" + parameters.kind); |
|
3514 |
- } |
|
3515 |
- /* |
|
3516 |
- // parameters |
|
3517 |
- { |
|
3518 |
- str += (":" + JSON.stringify(parameters.parameters)) |
|
3519 |
- } |
|
3520 |
- */ |
|
3521 |
- // soft |
|
3522 |
- { |
|
3523 |
- if (parameters.soft) { |
|
3524 |
- str = "~" + str; |
|
3525 |
- } |
|
3526 |
- } |
|
3527 |
- return str; |
|
3528 |
- } |
|
3529 |
- /** |
|
3530 |
- * @author fenris |
|
3531 |
- */ |
|
3532 |
- lib_shape.register({ |
|
3533 |
- "name": "domain", |
|
3534 |
- "make": domain_make, |
|
3535 |
- "inspect": domain_inspect, |
|
3536 |
- "stance": domain_stance, |
|
3537 |
- "show": domain_show |
|
3538 |
- }); |
|
3539 |
-})(lib_trait || (lib_trait = {})); |
|
3540 |
-/* |
|
3541 |
-This file is part of »bacterio-plankton:trait«. |
|
3542 |
- |
|
3543 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
3544 |
- |
|
3545 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
3546 |
-it under the terms of the GNU Lesser General Public License as published by |
|
3547 |
-the Free Software Foundation, either version 3 of the License, or |
|
3548 |
-(at your option) any later version. |
|
3549 |
- |
|
3550 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
3551 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3552 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3553 |
-GNU Lesser General Public License for more details. |
|
3554 |
- |
|
3555 |
-You should have received a copy of the GNU Lesser General Public License |
|
3556 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
3557 |
- */ |
|
3558 |
-/** |
|
3559 |
- * @author fenris |
|
3560 |
- */ |
|
3561 |
-var lib_trait; |
|
3562 |
-(function (lib_trait) { |
|
3563 |
- /** |
|
3564 |
- * @author fenris |
|
3565 |
- */ |
|
3566 |
- lib_trait._verbosity = 1; |
|
3567 |
- /** |
|
3568 |
- * @author fenris |
|
3569 |
- */ |
|
3570 |
- lib_trait._logprefix = "[lib_trait] "; |
|
3571 |
- /** |
|
3572 |
- * @desc holds all defined traits |
|
3573 |
- * @author fenris |
|
3574 |
- */ |
|
3575 |
- var _pool = {}; |
|
3576 |
- /** |
|
3577 |
- * @author fenris |
|
3578 |
- */ |
|
3579 |
- var _typechecker = function (value, shape, logger) { |
|
3580 |
- var messages = lib_shape.inspect(shape, value).messages; |
|
3581 |
- messages.forEach(logger); |
|
3582 |
- return (messages.length === 0); |
|
3583 |
- }; |
|
3584 |
- /** |
|
3585 |
- * @author fenris |
|
3586 |
- */ |
|
3587 |
- function log(_a) { |
|
3588 |
- var message = _a["message"], _b = _a["kind"], kind = _b === void 0 ? "log" : _b, _c = _a["level"], level = _c === void 0 ? 0 : _c; |
|
3589 |
- if (level <= lib_trait._verbosity) { |
|
3590 |
- var message_ = "" + lib_trait._logprefix + message; |
|
3591 |
- switch (kind) { |
|
3592 |
- default: |
|
3593 |
- case "log": { |
|
3594 |
- console.log(message_); |
|
3595 |
- break; |
|
3596 |
- } |
|
3597 |
- case "information": |
|
3598 |
- case "info": { |
|
3599 |
- console.info(message_); |
|
3600 |
- break; |
|
3601 |
- } |
|
3602 |
- case "warning": |
|
3603 |
- case "warn": { |
|
3604 |
- console.warn(message_); |
|
3605 |
- break; |
|
3606 |
- } |
|
3607 |
- case "error": |
|
3608 |
- case "err": { |
|
3609 |
- console.error(message_); |
|
3610 |
- break; |
|
3611 |
- } |
|
3612 |
- } |
|
3613 |
- } |
|
3614 |
- } |
|
3615 |
- /** |
|
3616 |
- * @author fenris |
|
3617 |
- */ |
|
3618 |
- function set_typechecker(typechecker) { |
|
3619 |
- _typechecker = typechecker; |
|
3620 |
- } |
|
3621 |
- lib_trait.set_typechecker = set_typechecker; |
|
3622 |
- /** |
|
3623 |
- * @author fenris |
|
3624 |
- */ |
|
3625 |
- function domain_instance(domain, value) { |
|
3626 |
- return { "domain": domain, "value": value }; |
|
3627 |
- } |
|
3628 |
- lib_trait.domain_instance = domain_instance; |
|
3629 |
- /** |
|
3630 |
- * @desc adds a trait |
|
3631 |
- * @author fenris |
|
3632 |
- */ |
|
3633 |
- function define(trait_id, variable_conditions, facets_raw) { |
|
3634 |
- if (trait_id in _pool) { |
|
3635 |
- var message = "trait '" + trait_id + "' already registered"; |
|
3636 |
- throw (new Error(message)); |
|
3637 |
- } |
|
3638 |
- else { |
|
3639 |
- var trait_1 = { |
|
3640 |
- "variables": {}, |
|
3641 |
- "facets": {}, |
|
3642 |
- "attendants": {} |
|
3643 |
- }; |
|
3644 |
- Object.keys(variable_conditions).forEach(function (variable_name) { |
|
3645 |
- var variable = { |
|
3646 |
- "conditions": variable_conditions[variable_name], |
|
3647 |
- "bindings": {} |
|
3648 |
- }; |
|
3649 |
- trait_1.variables[variable_name] = variable; |
|
3650 |
- }); |
|
3651 |
- Object.keys(facets_raw).forEach(function (facet_name) { |
|
3652 |
- var facet_raw = facets_raw[facet_name]; |
|
3653 |
- var facet = { |
|
3654 |
- "shape": lib_shape.make(facet_raw.shape || { "name": "any" }), |
|
3655 |
- "description": facet_raw.description, |
|
3656 |
- "implementation": facet_raw.implementation, |
|
3657 |
- "handlers": {} |
|
3658 |
- }; |
|
3659 |
- trait_1.facets[facet_name] = facet; |
|
3660 |
- }); |
|
3661 |
- _pool[trait_id] = trait_1; |
|
3662 |
- } |
|
3663 |
- } |
|
3664 |
- lib_trait.define = define; |
|
3665 |
- /** |
|
3666 |
- * @desc adhoc binding |
|
3667 |
- * @author fenris |
|
3668 |
- */ |
|
3669 |
- function attend(trait_id, domain_kind, bindings, handlers, condition) { |
|
3670 |
- if (condition === void 0) { condition = null; } |
|
3671 |
- var strict_binding = true; |
|
3672 |
- var strict_handling = true; |
|
3673 |
- if (!_pool.hasOwnProperty(trait_id)) { |
|
3674 |
- var message = "no trait '" + trait_id + "'"; |
|
3675 |
- throw (new Error(message)); |
|
3676 |
- } |
|
3677 |
- else { |
|
3678 |
- var trait_2 = _pool[trait_id]; |
|
3679 |
- // assignments |
|
3680 |
- { |
|
3681 |
- // variables |
|
3682 |
- { |
|
3683 |
- Object.keys(bindings).forEach(function (variable_name) { |
|
3684 |
- if (!trait_2.variables.hasOwnProperty(variable_name)) { |
|
3685 |
- var message = ""; |
|
3686 |
- message += "no variable '" + variable_name + "'"; |
|
3687 |
- message += " to bind in trait '" + trait_id + "'"; |
|
3688 |
- log({ "message": message, "kind": "warning" }); |
|
3689 |
- // throw (new Error(message)); |
|
3690 |
- } |
|
3691 |
- else { |
|
3692 |
- var variable = trait_2.variables[variable_name]; |
|
3693 |
- if (variable.bindings.hasOwnProperty(domain_kind)) { |
|
3694 |
- var message = ""; |
|
3695 |
- message += "variable '" + variable_name + "'"; |
|
3696 |
- message += " already bound for domain '" + domain_kind + "'"; |
|
3697 |
- message += " in trait '" + trait_id + "'"; |
|
3698 |
- throw (new Error(message)); |
|
3699 |
- } |
|
3700 |
- else { |
|
3701 |
- variable.bindings[domain_kind] = lib_shape.make(bindings[variable_name]); |
|
3702 |
- } |
|
3703 |
- } |
|
3704 |
- }); |
|
3705 |
- } |
|
3706 |
- // facets |
|
3707 |
- { |
|
3708 |
- Object.keys(handlers).forEach(function (facet_name) { |
|
3709 |
- if (!trait_2.facets.hasOwnProperty(facet_name)) { |
|
3710 |
- var message = ""; |
|
3711 |
- message += "no facet '" + facet_name + "'"; |
|
3712 |
- message += " to implement at trait '" + trait_id + "'"; |
|
3713 |
- log({ "kind": "warning", "message": message }); |
|
3714 |
- // throw (new Error(message)); |
|
3715 |
- } |
|
3716 |
- else { |
|
3717 |
- var facet = trait_2.facets[facet_name]; |
|
3718 |
- var intrinsic = (facet.implementation != undefined); |
|
3719 |
- if (intrinsic) { |
|
3720 |
- var message = "shadowing intrinsic facet '" + facet_name + "'"; |
|
3721 |
- console.warn(message); |
|
3722 |
- } |
|
3723 |
- else { |
|
3724 |
- // do nothing |
|
3725 |
- } |
|
3726 |
- if (facet.handlers.hasOwnProperty(domain_kind)) { |
|
3727 |
- var message = ""; |
|
3728 |
- message += "facet '" + facet_name + "'"; |
|
3729 |
- message += " already implemented in domain '" + domain_kind + "'"; |
|
3730 |
- message += " at trait '" + trait_id + "'"; |
|
3731 |
- throw (new Error(message)); |
|
3732 |
- } |
|
3733 |
- else { |
|
3734 |
- facet.handlers[domain_kind] = handlers[facet_name]; |
|
3735 |
- } |
|
3736 |
- } |
|
3737 |
- }); |
|
3738 |
- } |
|
3739 |
- // attendants |
|
3740 |
- { |
|
3741 |
- trait_2.attendants[domain_kind] = { |
|
3742 |
- "condition": condition |
|
3743 |
- }; |
|
3744 |
- } |
|
3745 |
- } |
|
3746 |
- // checks |
|
3747 |
- { |
|
3748 |
- var messages_1 = []; |
|
3749 |
- // variables |
|
3750 |
- { |
|
3751 |
- if (strict_binding) { |
|
3752 |
- var variable_names_given_1 = Object.keys(bindings); |
|
3753 |
- var variable_names_present = Object.keys(trait_2.variables); |
|
3754 |
- var variable_names_missing = variable_names_present.filter(function (variable_name) { return (!variable_names_given_1.some(function (variable_name_) { return (variable_name == variable_name_); })); }); |
|
3755 |
- variable_names_missing.forEach(function (variable_name) { |
|
3756 |
- var message = "binding missing for variable '" + variable_name + "'"; |
|
3757 |
- messages_1.push(message); |
|
3758 |
- }); |
|
3759 |
- } |
|
3760 |
- else { |
|
3761 |
- // do nothing |
|
3762 |
- } |
|
3763 |
- } |
|
3764 |
- // facets |
|
3765 |
- { |
|
3766 |
- if (strict_handling) { |
|
3767 |
- var facet_names_given_1 = Object.keys(handlers); |
|
3768 |
- var facet_names_needed = (Object.keys(trait_2.facets).filter(function (facet_name) { return (trait_2.facets[facet_name].implementation == undefined); })); |
|
3769 |
- var facet_names_missing = (facet_names_needed.filter(function (facet_name) { return (!facet_names_given_1.some(function (facet_name_) { return (facet_name === facet_name_); })); })); |
|
3770 |
- facet_names_missing.forEach(function (facet_name) { |
|
3771 |
- var message = "implementation missing for the facet '" + facet_name + "'"; |
|
3772 |
- messages_1.push(message); |
|
3773 |
- }); |
|
3774 |
- } |
|
3775 |
- else { |
|
3776 |
- // do nothing |
|
3777 |
- } |
|
3778 |
- } |
|
3779 |
- if (messages_1.length > 0) { |
|
3780 |
- var message = ""; |
|
3781 |
- message += "assignment of domain '" + domain_kind + "'"; |
|
3782 |
- message += " to trait '" + trait_id + "'"; |
|
3783 |
- message += " incomplete: " + messages_1.join(", "); |
|
3784 |
- throw (new Error(message)); |
|
3785 |
- } |
|
3786 |
- } |
|
3787 |
- } |
|
3788 |
- } |
|
3789 |
- lib_trait.attend = attend; |
|
3790 |
- /** |
|
3791 |
- * @desc calls a facet from a trait according to a given domain |
|
3792 |
- * @author fenris |
|
3793 |
- */ |
|
3794 |
- function call(trait_id, facet_name, domain, check) { |
|
3795 |
- if (check === void 0) { check = true; } |
|
3796 |
- if (!_pool.hasOwnProperty(trait_id)) { |
|
3797 |
- var message = "no trait '" + trait_id + "'"; |
|
3798 |
- throw (new Error(message)); |
|
3799 |
- } |
|
3800 |
- else { |
|
3801 |
- var trait_3 = _pool[trait_id]; |
|
3802 |
- if (!trait_3.facets.hasOwnProperty(facet_name)) { |
|
3803 |
- var message = "no facet '" + facet_name + "' in trait '" + trait_id + "'"; |
|
3804 |
- throw (new Error(message)); |
|
3805 |
- } |
|
3806 |
- else { |
|
3807 |
- var facet = trait_3.facets[facet_name]; |
|
3808 |
- var intrinsic = (facet.implementation !== undefined); |
|
3809 |
- var result = void 0; |
|
3810 |
- if (intrinsic) { |
|
3811 |
- result = facet.implementation(function (facet_name_) { return call(trait_id, facet_name_, domain, check); }); |
|
3812 |
- } |
|
3813 |
- else { |
|
3814 |
- if (!facet.handlers.hasOwnProperty(domain.kind)) { |
|
3815 |
- var message = ""; |
|
3816 |
- message += "implementation missing"; |
|
3817 |
- message += " at trait '" + trait_id + "'"; |
|
3818 |
- message += " for facet '" + facet_name + "'"; |
|
3819 |
- message += " in domain '" + domain.kind + "'"; |
|
3820 |
- throw (new Error(message)); |
|
3821 |
- } |
|
3822 |
- else { |
|
3823 |
- var show_shape = (function (shape) { return lib_shape.show(shape); }); |
|
3824 |
- var handler = facet.handlers[domain.kind]; |
|
3825 |
- var bindings_1 = {}; |
|
3826 |
- Object.keys(trait_3.variables).forEach(function (variable_name) { |
|
3827 |
- bindings_1[variable_name] = trait_3.variables[variable_name].bindings[domain.kind]; |
|
3828 |
- }); |
|
3829 |
- result = handler(domain.parameters); |
|
3830 |
- if (check |
|
3831 |
- && |
|
3832 |
- (_typechecker !== null) |
|
3833 |
- && |
|
3834 |
- (facet.shape !== undefined)) { |
|
3835 |
- var shape = lib_shape.stance(facet.shape, bindings_1); |
|
3836 |
- // console.info("expected shape of result: " + lib_shape.show(shape)); console.info("result: ", result); |
|
3837 |
- var valid = _typechecker(result, shape, function (message) { return log({ "kind": "warning", "message": "[typechecker] [result] " + message }); }); |
|
3838 |
- if (!valid) { |
|
3839 |
- var message = ""; |
|
3840 |
- message += "result '" + instance_show(result) + "'"; |
|
3841 |
- message += " doesn't match the expected type '" + show_shape(shape) + "'"; |
|
3842 |
- message += " at trait '" + trait_id + "'"; |
|
3843 |
- message += " for facet '" + facet_name + "'"; |
|
3844 |
- message += " in domain '" + domain.kind + "'"; |
|
3845 |
- log({ "kind": "warning", "message": message }); |
|
3846 |
- } |
|
3847 |
- { |
|
3848 |
- var condition = trait_3.attendants[domain.kind].condition; |
|
3849 |
- if (condition != null) { |
|
3850 |
- var attends = function (trait_id_, domain_) { |
|
3851 |
- return (_pool.hasOwnProperty(trait_id_) && _pool[trait_id_].attendants.hasOwnProperty(domain_.kind)); |
|
3852 |
- }; |
|
3853 |
- if (!condition(attends)(domain.parameters)) { |
|
3854 |
- var message = ""; |
|
3855 |
- message += "condition not fulfilled"; |
|
3856 |
- message += " at trait '" + trait_id + "'"; |
|
3857 |
- message += " for facet '" + facet_name + "'"; |
|
3858 |
- message += " in domain '" + domain.kind + "'"; |
|
3859 |
- log({ "kind": "warning", "message": message }); |
|
3860 |
- } |
|
3861 |
- else { |
|
3862 |
- // do nothing |
|
3863 |
- } |
|
3864 |
- } |
|
3865 |
- else { |
|
3866 |
- // do nothing |
|
3867 |
- } |
|
3868 |
- } |
|
3869 |
- } |
|
3870 |
- } |
|
3871 |
- } |
|
3872 |
- return result; |
|
3873 |
- } |
|
3874 |
- } |
|
3875 |
- } |
|
3876 |
- lib_trait.call = call; |
|
3877 |
- /** |
|
3878 |
- * @author fenris |
|
3879 |
- */ |
|
3880 |
- function explain(trait_id) { |
|
3881 |
- if (!_pool.hasOwnProperty(trait_id)) { |
|
3882 |
- var message = "no trait '" + trait_id + "'"; |
|
3883 |
- throw (new Error(message)); |
|
3884 |
- } |
|
3885 |
- else { |
|
3886 |
- var trait_4 = _pool[trait_id]; |
|
3887 |
- var str_1 = ""; |
|
3888 |
- // head |
|
3889 |
- { |
|
3890 |
- str_1 += "<<" + trait_id + ">>"; |
|
3891 |
- str_1 += (" " |
|
3892 |
- + |
|
3893 |
- "(" |
|
3894 |
- + |
|
3895 |
- (Object.keys(trait_4.variables) |
|
3896 |
- .map(function (variable_name) { |
|
3897 |
- var shape = lib_shape.make({ |
|
3898 |
- "name": "variable", |
|
3899 |
- "parameters": { |
|
3900 |
- "name": variable_name |
|
3901 |
- } |
|
3902 |
- }); |
|
3903 |
- return lib_shape.show(shape); |
|
3904 |
- }) |
|
3905 |
- .join(",")) |
|
3906 |
- + |
|
3907 |
- ")"); |
|
3908 |
- str_1 += "\n"; |
|
3909 |
- } |
|
3910 |
- // facets |
|
3911 |
- { |
|
3912 |
- Object.keys(trait_4.facets) |
|
3913 |
- .forEach(function (facet_name) { |
|
3914 |
- var facet = trait_4.facets[facet_name]; |
|
3915 |
- // str += "\t"; |
|
3916 |
- str_1 += "* "; |
|
3917 |
- str_1 += ((facet.implementation != undefined) ? ("[" + facet_name + "]") : facet_name); |
|
3918 |
- str_1 += (" : " + lib_shape.show(facet.shape)); |
|
3919 |
- if (facet.description !== undefined) { |
|
3920 |
- str_1 += (" ~ " + "" + facet.description + ""); |
|
3921 |
- } |
|
3922 |
- str_1 += "\n"; |
|
3923 |
- }); |
|
3924 |
- } |
|
3925 |
- return str_1; |
|
3926 |
- } |
|
3927 |
- } |
|
3928 |
- lib_trait.explain = explain; |
|
3929 |
- /** |
|
3930 |
- * @author fenris |
|
3931 |
- */ |
|
3932 |
- function explain_all() { |
|
3933 |
- return Object.keys(_pool).map(function (trait_id) { return explain(trait_id); }).join("\n"); |
|
3934 |
- } |
|
3935 |
- lib_trait.explain_all = explain_all; |
|
3936 |
-})(lib_trait || (lib_trait = {})); |
|
3937 |
-/* |
|
3938 |
-This file is part of »bacterio-plankton:trait«. |
|
3939 |
- |
|
3940 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
3941 |
- |
|
3942 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
3943 |
-it under the terms of the GNU Lesser General Public License as published by |
|
3944 |
-the Free Software Foundation, either version 3 of the License, or |
|
3945 |
-(at your option) any later version. |
|
3946 |
- |
|
3947 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
3948 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
3949 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
3950 |
-GNU Lesser General Public License for more details. |
|
3951 |
- |
|
3952 |
-You should have received a copy of the GNU Lesser General Public License |
|
3953 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
3954 |
- */ |
|
3955 |
-/** |
|
3956 |
- * @author fenris |
|
3957 |
- */ |
|
3958 |
-var lib_trait; |
|
3959 |
-(function (lib_trait) { |
|
3960 |
- /** |
|
3961 |
- * @desc the ability to check for equality with another element of the same domain |
|
3962 |
- * @author fenris |
|
3963 |
- */ |
|
3964 |
- function define_collatable() { |
|
3965 |
- lib_trait.define("collatable", { |
|
3966 |
- "value": [] |
|
3967 |
- }, { |
|
3968 |
- "collate": { |
|
3969 |
- "shape": { |
|
3970 |
- "name": "function", |
|
3971 |
- "parameters": { |
|
3972 |
- "shape_input": { |
|
3973 |
- "name": "variable", |
|
3974 |
- "parameters": { |
|
3975 |
- "name": "value" |
|
3976 |
- } |
|
3977 |
- }, |
|
3978 |
- "shape_output": { |
|
3979 |
- "name": "function", |
|
3980 |
- "parameters": { |
|
3981 |
- "shape_input": { |
|
3982 |
- "name": "variable", |
|
3983 |
- "parameters": { |
|
3984 |
- "name": "value" |
|
3985 |
- } |
|
3986 |
- }, |
|
3987 |
- "shape_output": { |
|
3988 |
- "name": "boolean" |
|
3989 |
- } |
|
3990 |
- } |
|
3991 |
- } |
|
3992 |
- } |
|
3993 |
- } |
|
3994 |
- } |
|
3995 |
- }); |
|
3996 |
- lib_trait.attend("collatable", "crude", { |
|
3997 |
- "value": { |
|
3998 |
- "name": "any" |
|
3999 |
- } |
|
4000 |
- }, { |
|
4001 |
- "collate": function () { return function (instance) { return function (other) { |
|
4002 |
- if (typeof (instance) === "object") { |
|
4003 |
- if (instance == null) { |
|
4004 |
- return (other == null); |
|
4005 |
- } |
|
4006 |
- else { |
|
4007 |
- if ("_collate" in instance) { |
|
4008 |
- return instance["_collate"](other); |
|
4009 |
- } |
|
4010 |
- else { |
|
4011 |
- var message = ("[collate]" + " " + "object has no such method"); |
|
4012 |
- throw (new Error(message)); |
|
4013 |
- } |
|
4014 |
- } |
|
4015 |
- } |
|
4016 |
- else { |
|
4017 |
- if (lib_trait._verbosity >= 1) { |
|
4018 |
- var message = ("[collate]" + " " + "primitive value; using default implementation"); |
|
4019 |
- console.warn(message); |
|
4020 |
- } |
|
4021 |
- return (instance === other); |
|
4022 |
- } |
|
4023 |
- }; }; } |
|
4024 |
- }); |
|
4025 |
- } |
|
4026 |
- lib_trait.define_collatable = define_collatable; |
|
4027 |
- /** |
|
4028 |
- * @author fenris |
|
4029 |
- */ |
|
4030 |
- function _collate(instance, other, domain) { |
|
4031 |
- if (domain === void 0) { domain = { "kind": "crude" }; } |
|
4032 |
- return lib_trait.call("collatable", "collate", domain)(instance)(other); |
|
4033 |
- } |
|
4034 |
- lib_trait._collate = _collate; |
|
4035 |
- define_collatable(); |
|
4036 |
-})(lib_trait || (lib_trait = {})); |
|
4037 |
-/* |
|
4038 |
-This file is part of »bacterio-plankton:trait«. |
|
4039 |
- |
|
4040 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
4041 |
- |
|
4042 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
4043 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4044 |
-the Free Software Foundation, either version 3 of the License, or |
|
4045 |
-(at your option) any later version. |
|
4046 |
- |
|
4047 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
4048 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4049 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4050 |
-GNU Lesser General Public License for more details. |
|
4051 |
- |
|
4052 |
-You should have received a copy of the GNU Lesser General Public License |
|
4053 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
4054 |
- */ |
|
4055 |
-/** |
|
4056 |
- * @author fenris |
|
4057 |
- */ |
|
4058 |
-var lib_trait; |
|
4059 |
-(function (lib_trait) { |
|
4060 |
- /** |
|
4061 |
- * @desc the ability to compare with another element of the same domain for determining if the first is "smaller than or equal to" the latter |
|
4062 |
- * @author fenris |
|
4063 |
- */ |
|
4064 |
- function define_comparable() { |
|
4065 |
- lib_trait.define("comparable", { |
|
4066 |
- "value": [] |
|
4067 |
- }, { |
|
4068 |
- "compare": { |
|
4069 |
- "shape": { |
|
4070 |
- "name": "function", |
|
4071 |
- "parameters": { |
|
4072 |
- "shape_input": { |
|
4073 |
- "name": "variable", |
|
4074 |
- "parameters": { |
|
4075 |
- "name": "value" |
|
4076 |
- } |
|
4077 |
- }, |
|
4078 |
- "shape_output": { |
|
4079 |
- "name": "function", |
|
4080 |
- "parameters": { |
|
4081 |
- "shape_input": { |
|
4082 |
- "name": "variable", |
|
4083 |
- "parameters": { |
|
4084 |
- "name": "value" |
|
4085 |
- } |
|
4086 |
- }, |
|
4087 |
- "shape_output": { |
|
4088 |
- "name": "boolean" |
|
4089 |
- } |
|
4090 |
- } |
|
4091 |
- } |
|
4092 |
- } |
|
4093 |
- } |
|
4094 |
- } |
|
4095 |
- }); |
|
4096 |
- lib_trait.attend("comparable", "crude", { |
|
4097 |
- "value": { |
|
4098 |
- "name": "any" |
|
4099 |
- } |
|
4100 |
- }, { |
|
4101 |
- "compare": function () { return function (instance) { return function (other) { |
|
4102 |
- if (typeof (instance) === "object") { |
|
4103 |
- if ("_compare" in instance) { |
|
4104 |
- return instance["_compare"](other); |
|
4105 |
- } |
|
4106 |
- else { |
|
4107 |
- throw (new Error("[compare]" + " " + "object has no such method")); |
|
4108 |
- } |
|
4109 |
- } |
|
4110 |
- else { |
|
4111 |
- if (lib_trait._verbosity >= 1) { |
|
4112 |
- console.warn("[compare]" + " " + "primitive value; using default implementation"); |
|
4113 |
- } |
|
4114 |
- return (instance <= other); |
|
4115 |
- } |
|
4116 |
- }; }; } |
|
4117 |
- }); |
|
4118 |
- } |
|
4119 |
- lib_trait.define_comparable = define_comparable; |
|
4120 |
- /** |
|
4121 |
- * @author fenris |
|
4122 |
- */ |
|
4123 |
- function _compare(instance, other, domain) { |
|
4124 |
- if (domain === void 0) { domain = { "kind": "crude" }; } |
|
4125 |
- return lib_trait.call("comparable", "compare", domain)(instance)(other); |
|
4126 |
- } |
|
4127 |
- lib_trait._compare = _compare; |
|
4128 |
- define_comparable(); |
|
4129 |
-})(lib_trait || (lib_trait = {})); |
|
4130 |
-/* |
|
4131 |
-This file is part of »bacterio-plankton:trait«. |
|
4132 |
- |
|
4133 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
4134 |
- |
|
4135 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
4136 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4137 |
-the Free Software Foundation, either version 3 of the License, or |
|
4138 |
-(at your option) any later version. |
|
4139 |
- |
|
4140 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
4141 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4142 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4143 |
-GNU Lesser General Public License for more details. |
|
4144 |
- |
|
4145 |
-You should have received a copy of the GNU Lesser General Public License |
|
4146 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
4147 |
- */ |
|
4148 |
-/** |
|
4149 |
- * @author fenris |
|
4150 |
- */ |
|
4151 |
-var lib_trait; |
|
4152 |
-(function (lib_trait) { |
|
4153 |
- /** |
|
4154 |
- * @desc the ability to create an exact copy |
|
4155 |
- * @author fenris |
|
4156 |
- */ |
|
4157 |
- function define_clonable() { |
|
4158 |
- lib_trait.define("clonable", { |
|
4159 |
- "value": [] |
|
4160 |
- }, { |
|
4161 |
- "clone": { |
|
4162 |
- "shape": { |
|
4163 |
- "name": "function", |
|
4164 |
- "parameters": { |
|
4165 |
- "shape_input": { |
|
4166 |
- "name": "variable", |
|
4167 |
- "parameters": { |
|
4168 |
- "name": "value" |
|
4169 |
- } |
|
4170 |
- }, |
|
4171 |
- "shape_output": { |
|
4172 |
- "name": "variable", |
|
4173 |
- "parameters": { |
|
4174 |
- "name": "value" |
|
4175 |
- } |
|
4176 |
- } |
|
4177 |
- } |
|
4178 |
- } |
|
4179 |
- } |
|
4180 |
- }); |
|
4181 |
- lib_trait.attend("clonable", "crude", { |
|
4182 |
- "value": { |
|
4183 |
- "name": "any" |
|
4184 |
- } |
|
4185 |
- }, { |
|
4186 |
- "clone": function () { return function (instance) { |
|
4187 |
- if (typeof (instance) === "object") { |
|
4188 |
- if ("_clone" in instance) { |
|
4189 |
- return instance["_clone"](); |
|
4190 |
- } |
|
4191 |
- else { |
|
4192 |
- throw (new Error("[clone]" + " " + "object has no such method")); |
|
4193 |
- } |
|
4194 |
- } |
|
4195 |
- else { |
|
4196 |
- if (lib_trait._verbosity >= 1) { |
|
4197 |
- console.warn("[clone]" + " " + "primitive value; using default implementation"); |
|
4198 |
- } |
|
4199 |
- return instance; |
|
4200 |
- } |
|
4201 |
- }; } |
|
4202 |
- }); |
|
4203 |
- } |
|
4204 |
- lib_trait.define_clonable = define_clonable; |
|
4205 |
- /** |
|
4206 |
- * @author fenris |
|
4207 |
- */ |
|
4208 |
- function _clone(instance, domain) { |
|
4209 |
- if (domain === void 0) { domain = { "kind": "crude" }; } |
|
4210 |
- return lib_trait.call("clonable", "clone", domain)(instance); |
|
4211 |
- } |
|
4212 |
- lib_trait._clone = _clone; |
|
4213 |
- define_clonable(); |
|
4214 |
-})(lib_trait || (lib_trait = {})); |
|
4215 |
-/* |
|
4216 |
-This file is part of »bacterio-plankton:trait«. |
|
4217 |
- |
|
4218 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
4219 |
- |
|
4220 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
4221 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4222 |
-the Free Software Foundation, either version 3 of the License, or |
|
4223 |
-(at your option) any later version. |
|
4224 |
- |
|
4225 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
4226 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4227 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4228 |
-GNU Lesser General Public License for more details. |
|
4229 |
- |
|
4230 |
-You should have received a copy of the GNU Lesser General Public License |
|
4231 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
4232 |
- */ |
|
4233 |
-/** |
|
4234 |
- * @author fenris |
|
4235 |
- */ |
|
4236 |
-var lib_trait; |
|
4237 |
-(function (lib_trait) { |
|
4238 |
- /** |
|
4239 |
- * @desc the ability to generate a string out of the element, which identifies it to a high degree |
|
4240 |
- * @author fenris |
|
4241 |
- */ |
|
4242 |
- function define_hashable() { |
|
4243 |
- lib_trait.define("hashable", { |
|
4244 |
- "value": [] |
|
4245 |
- }, { |
|
4246 |
- "hash": { |
|
4247 |
- "shape": { |
|
4248 |
- "name": "function", |
|
4249 |
- "parameters": { |
|
4250 |
- "shape_input": { |
|
4251 |
- "name": "variable", |
|
4252 |
- "parameters": { |
|
4253 |
- "name": "value" |
|
4254 |
- } |
|
4255 |
- }, |
|
4256 |
- "shape_output": { |
|
4257 |
- "name": "string" |
|
4258 |
- } |
|
4259 |
- } |
|
4260 |
- } |
|
4261 |
- } |
|
4262 |
- }); |
|
4263 |
- lib_trait.attend("hashable", "crude", { |
|
4264 |
- "value": { |
|
4265 |
- "name": "any" |
|
4266 |
- } |
|
4267 |
- }, { |
|
4268 |
- "hash": function () { return function (thing) { |
|
4269 |
- if (typeof (thing) === "object") { |
|
4270 |
- if ("_hash" in thing) { |
|
4271 |
- return thing["_hash"](); |
|
4272 |
- } |
|
4273 |
- else { |
|
4274 |
- var message = ("[hash]" + " " + "object has no such method"); |
|
4275 |
- throw (new Error(message)); |
|
4276 |
- } |
|
4277 |
- } |
|
4278 |
- else { |
|
4279 |
- if (lib_trait._verbosity >= 1) { |
|
4280 |
- var message = ("[hash]" + " " + "primitive value; using default implementation"); |
|
4281 |
- console.warn(message); |
|
4282 |
- } |
|
4283 |
- return String(thing); |
|
4284 |
- } |
|
4285 |
- }; } |
|
4286 |
- }); |
|
4287 |
- } |
|
4288 |
- lib_trait.define_hashable = define_hashable; |
|
4289 |
- /** |
|
4290 |
- * @author fenris |
|
4291 |
- */ |
|
4292 |
- function _hash(instance, domain) { |
|
4293 |
- if (domain === void 0) { domain = { "kind": "crude" }; } |
|
4294 |
- return lib_trait.call("hashable", "hash", domain)(instance); |
|
4295 |
- } |
|
4296 |
- lib_trait._hash = _hash; |
|
4297 |
- define_hashable(); |
|
4298 |
-})(lib_trait || (lib_trait = {})); |
|
4299 |
-/* |
|
4300 |
-This file is part of »bacterio-plankton:trait«. |
|
4301 |
- |
|
4302 |
-Copyright 2016-2018 greenscale <info@greenscale.de> |
|
4303 |
- |
|
4304 |
-»bacterio-plankton:trait« is free software: you can redistribute it and/or modify |
|
4305 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4306 |
-the Free Software Foundation, either version 3 of the License, or |
|
4307 |
-(at your option) any later version. |
|
4308 |
- |
|
4309 |
-»bacterio-plankton:trait« is distributed in the hope that it will be callful, |
|
4310 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4311 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4312 |
-GNU Lesser General Public License for more details. |
|
4313 |
- |
|
4314 |
-You should have received a copy of the GNU Lesser General Public License |
|
4315 |
-along with »bacterio-plankton:trait«. If not, see <http://www.gnu.org/licenses/>. |
|
4316 |
- */ |
|
4317 |
-/** |
|
4318 |
- * @author fenris |
|
4319 |
- */ |
|
4320 |
-var lib_trait; |
|
4321 |
-(function (lib_trait) { |
|
4322 |
- /** |
|
4323 |
- * @desc the ability to map the element to a textual representation (most likely not injective) |
|
4324 |
- * @author fenris |
|
4325 |
- */ |
|
4326 |
- function define_showable() { |
|
4327 |
- lib_trait.define("showable", { |
|
4328 |
- "value": [] |
|
4329 |
- }, { |
|
4330 |
- "show": { |
|
4331 |
- "shape": { |
|
4332 |
- "name": "function", |
|
4333 |
- "parameters": { |
|
4334 |
- "shape_input": { |
|
4335 |
- "name": "variable", |
|
4336 |
- "parameters": { |
|
4337 |
- "name": "value" |
|
4338 |
- } |
|
4339 |
- }, |
|
4340 |
- "shape_output": { |
|
4341 |
- "name": "string", |
|
4342 |
- "parameters": { |
|
4343 |
- "soft": false |
|
4344 |
- } |
|
4345 |
- } |
|
4346 |
- } |
|
4347 |
- } |
|
4348 |
- } |
|
4349 |
- }); |
|
4350 |
- lib_trait.attend("showable", "crude", { |
|
4351 |
- "value": { |
|
4352 |
- "name": "any" |
|
4353 |
- } |
|
4354 |
- }, { |
|
4355 |
- "show": function () { return function (instance) { |
|
4356 |
- if (typeof (instance) === "object") { |
|
4357 |
- if (instance == null) { |
|
4358 |
- return "NULL"; |
|
4359 |
- } |
|
4360 |
- else { |
|
4361 |
- if ("_show" in instance) { |
|
4362 |
- return instance["_show"](); |
|
4363 |
- } |
|
4364 |
- else { |
|
4365 |
- // throw (new Error("[show]" + " " + "object has no such method")); |
|
4366 |
- return JSON.stringify(instance); |
|
4367 |
- } |
|
4368 |
- } |
|
4369 |
- } |
|
4370 |
- else { |
|
4371 |
- if (lib_trait._verbosity >= 1) { |
|
4372 |
- var message = ("[show]" + " " + "primitive value; using default implementation"); |
|
4373 |
- // console.warn(message); |
|
4374 |
- } |
|
4375 |
- return String(instance); |
|
4376 |
- } |
|
4377 |
- }; } |
|
4378 |
- }); |
|
4379 |
- } |
|
4380 |
- lib_trait.define_showable = define_showable; |
|
4381 |
- /** |
|
4382 |
- * @author fenris |
|
4383 |
- */ |
|
4384 |
- function _show(instance, domain) { |
|
4385 |
- if (domain === void 0) { domain = { "kind": "crude" }; } |
|
4386 |
- return lib_trait.call("showable", "show", domain)(instance); |
|
4387 |
- } |
|
4388 |
- lib_trait._show = _show; |
|
4389 |
- define_showable(); |
|
4390 |
-})(lib_trait || (lib_trait = {})); |
|
4391 |
-/* |
|
4392 |
-This file is part of »bacterio-plankton:code«. |
|
4393 |
- |
|
4394 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4395 |
-<info@greenscale.de> |
|
4396 |
- |
|
4397 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4398 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4399 |
-the Free Software Foundation, either version 3 of the License, or |
|
4400 |
-(at your option) any later version. |
|
4401 |
- |
|
4402 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4403 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4404 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4405 |
-GNU Lesser General Public License for more details. |
|
4406 |
- |
|
4407 |
-You should have received a copy of the GNU Lesser General Public License |
|
4408 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4409 |
- */ |
|
4410 |
-/* |
|
4411 |
-This file is part of »bacterio-plankton:code«. |
|
4412 |
- |
|
4413 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4414 |
-<info@greenscale.de> |
|
4415 |
- |
|
4416 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4417 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4418 |
-the Free Software Foundation, either version 3 of the License, or |
|
4419 |
-(at your option) any later version. |
|
4420 |
- |
|
4421 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4422 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4423 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4424 |
-GNU Lesser General Public License for more details. |
|
4425 |
- |
|
4426 |
-You should have received a copy of the GNU Lesser General Public License |
|
4427 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4428 |
- */ |
|
4429 |
-var lib_code; |
|
4430 |
-(function (lib_code) { |
|
4431 |
- /** |
|
4432 |
- * @author fenris |
|
4433 |
- */ |
|
4434 |
- lib_trait.define("code", { |
|
4435 |
- "from": null, |
|
4436 |
- "to": null |
|
4437 |
- }, { |
|
4438 |
- "encode": { |
|
4439 |
- "shape": { |
|
4440 |
- "name": "function", |
|
4441 |
- "parameters": { |
|
4442 |
- "shape_input": { |
|
4443 |
- "name": "variable", |
|
4444 |
- "parameters": { |
|
4445 |
- "name": "from" |
|
4446 |
- } |
|
4447 |
- }, |
|
4448 |
- "shape_output": { |
|
4449 |
- "name": "variable", |
|
4450 |
- "parameters": { |
|
4451 |
- "name": "to" |
|
4452 |
- } |
|
4453 |
- } |
|
4454 |
- } |
|
4455 |
- } |
|
4456 |
- }, |
|
4457 |
- "decode": { |
|
4458 |
- "shape": { |
|
4459 |
- "name": "function", |
|
4460 |
- "parameters": { |
|
4461 |
- "shape_input": { |
|
4462 |
- "name": "variable", |
|
4463 |
- "parameters": { |
|
4464 |
- "name": "to" |
|
4465 |
- } |
|
4466 |
- }, |
|
4467 |
- "shape_output": { |
|
4468 |
- "name": "variable", |
|
4469 |
- "parameters": { |
|
4470 |
- "name": "from" |
|
4471 |
- } |
|
4472 |
- } |
|
4473 |
- } |
|
4474 |
- } |
|
4475 |
- } |
|
4476 |
- }); |
|
4477 |
-})(lib_code || (lib_code = {})); |
|
4478 |
-/* |
|
4479 |
-This file is part of »bacterio-plankton:code«. |
|
4480 |
- |
|
4481 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4482 |
-<info@greenscale.de> |
|
4483 |
- |
|
4484 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4485 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4486 |
-the Free Software Foundation, either version 3 of the License, or |
|
4487 |
-(at your option) any later version. |
|
4488 |
- |
|
4489 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4490 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4491 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4492 |
-GNU Lesser General Public License for more details. |
|
4493 |
- |
|
4494 |
-You should have received a copy of the GNU Lesser General Public License |
|
4495 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4496 |
- */ |
|
4497 |
-var lib_code; |
|
4498 |
-(function (lib_code) { |
|
4499 |
- /** |
|
4500 |
- * @author Christian Fraß <frass@greenscale.de> |
|
4501 |
- */ |
|
4502 |
- function custom_encode(function_, from) { |
|
4503 |
- return function_(from); |
|
4504 |
- } |
|
4505 |
- lib_code.custom_encode = custom_encode; |
|
4506 |
- /** |
|
4507 |
- * @author Christian Fraß <frass@greenscale.de> |
|
4508 |
- */ |
|
4509 |
- function custom_decode(function_, to) { |
|
4510 |
- return function_(to); |
|
4511 |
- } |
|
4512 |
- lib_code.custom_decode = custom_decode; |
|
4513 |
-})(lib_code || (lib_code = {})); |
|
4514 |
-/* |
|
4515 |
-This file is part of »bacterio-plankton:code«. |
|
4516 |
- |
|
4517 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4518 |
-<info@greenscale.de> |
|
4519 |
- |
|
4520 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4521 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4522 |
-the Free Software Foundation, either version 3 of the License, or |
|
4523 |
-(at your option) any later version. |
|
4524 |
- |
|
4525 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4526 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4527 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4528 |
-GNU Lesser General Public License for more details. |
|
4529 |
- |
|
4530 |
-You should have received a copy of the GNU Lesser General Public License |
|
4531 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4532 |
- */ |
|
4533 |
-var lib_code; |
|
4534 |
-(function (lib_code) { |
|
4535 |
- /** |
|
4536 |
- * @author fenris |
|
4537 |
- */ |
|
4538 |
- class class_code_custom { |
|
4539 |
- /** |
|
4540 |
- * @author fenris |
|
4541 |
- */ |
|
4542 |
- constructor(encodefunc, decodefunc) { |
|
4543 |
- this.encodefunc = encodefunc; |
|
4544 |
- this.decodefunc = decodefunc; |
|
4545 |
- } |
|
4546 |
- /** |
|
4547 |
- * @implementation |
|
4548 |
- * @author fenris |
|
4549 |
- */ |
|
4550 |
- encode(x) { |
|
4551 |
- return lib_code.custom_encode(this.encodefunc, x); |
|
4552 |
- } |
|
4553 |
- /** |
|
4554 |
- * @implementation |
|
4555 |
- * @author fenris |
|
4556 |
- */ |
|
4557 |
- decode(x) { |
|
4558 |
- return lib_code.custom_decode(this.decodefunc, x); |
|
4559 |
- } |
|
4560 |
- } |
|
4561 |
- lib_code.class_code_custom = class_code_custom; |
|
4562 |
-})(lib_code || (lib_code = {})); |
|
4563 |
-/* |
|
4564 |
-This file is part of »bacterio-plankton:code«. |
|
4565 |
- |
|
4566 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4567 |
-<info@greenscale.de> |
|
4568 |
- |
|
4569 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4570 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4571 |
-the Free Software Foundation, either version 3 of the License, or |
|
4572 |
-(at your option) any later version. |
|
4573 |
- |
|
4574 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4575 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4576 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4577 |
-GNU Lesser General Public License for more details. |
|
4578 |
- |
|
4579 |
-You should have received a copy of the GNU Lesser General Public License |
|
4580 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4581 |
- */ |
|
4582 |
-var lib_code; |
|
4583 |
-(function (lib_code) { |
|
4584 |
- /** |
|
4585 |
- * @author fenris |
|
4586 |
- */ |
|
4587 |
- function inverse_encode(decode, to) { |
|
4588 |
- return decode(to); |
|
4589 |
- } |
|
4590 |
- lib_code.inverse_encode = inverse_encode; |
|
4591 |
- /** |
|
4592 |
- * @author fenris |
|
4593 |
- */ |
|
4594 |
- function inverse_decode(encode, from) { |
|
4595 |
- return encode(from); |
|
4596 |
- } |
|
4597 |
- lib_code.inverse_decode = inverse_decode; |
|
4598 |
-})(lib_code || (lib_code = {})); |
|
4599 |
-/* |
|
4600 |
-This file is part of »bacterio-plankton:code«. |
|
4601 |
- |
|
4602 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4603 |
-<info@greenscale.de> |
|
4604 |
- |
|
4605 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4606 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4607 |
-the Free Software Foundation, either version 3 of the License, or |
|
4608 |
-(at your option) any later version. |
|
4609 |
- |
|
4610 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4611 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4612 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4613 |
-GNU Lesser General Public License for more details. |
|
4614 |
- |
|
4615 |
-You should have received a copy of the GNU Lesser General Public License |
|
4616 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4617 |
- */ |
|
4618 |
-var lib_code; |
|
4619 |
-(function (lib_code) { |
|
4620 |
- /** |
|
4621 |
- * @author fenris |
|
4622 |
- */ |
|
4623 |
- lib_trait.attend("code", "inverse", { |
|
4624 |
- "from": { |
|
4625 |
- "name": "any" |
|
4626 |
- }, |
|
4627 |
- "to": { |
|
4628 |
- "name": "any" |
|
4629 |
- } |
|
4630 |
- }, { |
|
4631 |
- "encode": (domain_parameters) => (x) => { |
|
4632 |
- return (lib_code.inverse_encode(y_ => lib_trait.call("code", "decode", domain_parameters.domain_subject)(y_), x)); |
|
4633 |
- }, |
|
4634 |
- "decode": (domain_parameters) => (y) => { |
|
4635 |
- return (lib_code.inverse_decode(x_ => lib_trait.call("code", "encode", domain_parameters.domain_subject)(x_), y)); |
|
4636 |
- } |
|
4637 |
- }); |
|
4638 |
-})(lib_code || (lib_code = {})); |
|
4639 |
-/* |
|
4640 |
-This file is part of »bacterio-plankton:code«. |
|
4641 |
- |
|
4642 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4643 |
-<info@greenscale.de> |
|
4644 |
- |
|
4645 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4646 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4647 |
-the Free Software Foundation, either version 3 of the License, or |
|
4648 |
-(at your option) any later version. |
|
4649 |
- |
|
4650 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4651 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4652 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4653 |
-GNU Lesser General Public License for more details. |
|
4654 |
- |
|
4655 |
-You should have received a copy of the GNU Lesser General Public License |
|
4656 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4657 |
- */ |
|
4658 |
-var lib_code; |
|
4659 |
-(function (lib_code) { |
|
4660 |
- /** |
|
4661 |
- * @author fenris |
|
4662 |
- */ |
|
4663 |
- class class_code_inverse { |
|
4664 |
- /** |
|
4665 |
- * @author fenris |
|
4666 |
- */ |
|
4667 |
- constructor(subject) { |
|
4668 |
- this.subject = subject; |
|
4669 |
- } |
|
4670 |
- /** |
|
4671 |
- * @implementation |
|
4672 |
- * @author fenris |
|
4673 |
- */ |
|
4674 |
- encode(to) { |
|
4675 |
- return lib_code.inverse_encode(x => this.subject.decode(x), to); |
|
4676 |
- } |
|
4677 |
- /** |
|
4678 |
- * @implementation |
|
4679 |
- * @author fenris |
|
4680 |
- */ |
|
4681 |
- decode(from) { |
|
4682 |
- return lib_code.inverse_decode(x => this.subject.encode(x), from); |
|
4683 |
- } |
|
4684 |
- } |
|
4685 |
- lib_code.class_code_inverse = class_code_inverse; |
|
4686 |
-})(lib_code || (lib_code = {})); |
|
4687 |
-/* |
|
4688 |
-This file is part of »bacterio-plankton:code«. |
|
4689 |
- |
|
4690 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4691 |
-<info@greenscale.de> |
|
4692 |
- |
|
4693 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4694 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4695 |
-the Free Software Foundation, either version 3 of the License, or |
|
4696 |
-(at your option) any later version. |
|
4697 |
- |
|
4698 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4699 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4700 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4701 |
-GNU Lesser General Public License for more details. |
|
4702 |
- |
|
4703 |
-You should have received a copy of the GNU Lesser General Public License |
|
4704 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4705 |
- */ |
|
4706 |
-var lib_code; |
|
4707 |
-(function (lib_code) { |
|
4708 |
- /** |
|
4709 |
- * @author fenris |
|
4710 |
- */ |
|
4711 |
- function pair_encode(encode_first, encode_second, from) { |
|
4712 |
- let between = encode_first(from); |
|
4713 |
- let to = encode_second(between); |
|
4714 |
- return to; |
|
4715 |
- } |
|
4716 |
- lib_code.pair_encode = pair_encode; |
|
4717 |
- /** |
|
4718 |
- * @author fenris |
|
4719 |
- */ |
|
4720 |
- function pair_decode(decode_first, decode_second, to) { |
|
4721 |
- let between = decode_second(to); |
|
4722 |
- let from = decode_first(between); |
|
4723 |
- return from; |
|
4724 |
- } |
|
4725 |
- lib_code.pair_decode = pair_decode; |
|
4726 |
-})(lib_code || (lib_code = {})); |
|
4727 |
-/* |
|
4728 |
-This file is part of »bacterio-plankton:code«. |
|
4729 |
- |
|
4730 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4731 |
-<info@greenscale.de> |
|
4732 |
- |
|
4733 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4734 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4735 |
-the Free Software Foundation, either version 3 of the License, or |
|
4736 |
-(at your option) any later version. |
|
4737 |
- |
|
4738 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4739 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4740 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4741 |
-GNU Lesser General Public License for more details. |
|
4742 |
- |
|
4743 |
-You should have received a copy of the GNU Lesser General Public License |
|
4744 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4745 |
- */ |
|
4746 |
-var lib_code; |
|
4747 |
-(function (lib_code) { |
|
4748 |
- /** |
|
4749 |
- * @author fenris |
|
4750 |
- */ |
|
4751 |
- lib_trait.attend("code", "pair", { |
|
4752 |
- "from": { |
|
4753 |
- "name": "any" |
|
4754 |
- }, |
|
4755 |
- "to": { |
|
4756 |
- "name": "any" |
|
4757 |
- } |
|
4758 |
- }, { |
|
4759 |
- "encode": (domain_parameters) => (x) => { |
|
4760 |
- return (lib_code.pair_encode(x_ => lib_trait.call("code", "encode", domain_parameters.domain_first)(x_), x_ => lib_trait.call("code", "encode", domain_parameters.domain_second)(x_), x)); |
|
4761 |
- }, |
|
4762 |
- "decode": (domain_parameters) => (y) => { |
|
4763 |
- return (lib_code.pair_decode(y_ => lib_trait.call("code", "decode", domain_parameters.domain_first)(y_), y_ => lib_trait.call("code", "decode", domain_parameters.domain_second)(y_), y)); |
|
4764 |
- } |
|
4765 |
- }); |
|
4766 |
-})(lib_code || (lib_code = {})); |
|
4767 |
-/* |
|
4768 |
-This file is part of »bacterio-plankton:code«. |
|
4769 |
- |
|
4770 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4771 |
-<info@greenscale.de> |
|
4772 |
- |
|
4773 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4774 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4775 |
-the Free Software Foundation, either version 3 of the License, or |
|
4776 |
-(at your option) any later version. |
|
4777 |
- |
|
4778 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4779 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4780 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4781 |
-GNU Lesser General Public License for more details. |
|
4782 |
- |
|
4783 |
-You should have received a copy of the GNU Lesser General Public License |
|
4784 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4785 |
- */ |
|
4786 |
-var lib_code; |
|
4787 |
-(function (lib_code) { |
|
4788 |
- /** |
|
4789 |
- * @author fenris |
|
4790 |
- */ |
|
4791 |
- class class_code_pair { |
|
4792 |
- /** |
|
4793 |
- * @author fenris |
|
4794 |
- */ |
|
4795 |
- constructor(first, second) { |
|
4796 |
- this.first = first; |
|
4797 |
- this.second = second; |
|
4798 |
- } |
|
4799 |
- /** |
|
4800 |
- * @implementation |
|
4801 |
- * @author fenris |
|
4802 |
- */ |
|
4803 |
- encode(from) { |
|
4804 |
- return lib_code.pair_encode(x => this.first.encode(x), x => this.second.encode(x), from); |
|
4805 |
- } |
|
4806 |
- /** |
|
4807 |
- * @implementation |
|
4808 |
- * @author fenris |
|
4809 |
- */ |
|
4810 |
- decode(to) { |
|
4811 |
- return lib_code.pair_decode(x => this.first.decode(x), x => this.second.decode(x), to); |
|
4812 |
- } |
|
4813 |
- } |
|
4814 |
- lib_code.class_code_pair = class_code_pair; |
|
4815 |
-})(lib_code || (lib_code = {})); |
|
4816 |
-/* |
|
4817 |
-This file is part of »bacterio-plankton:code«. |
|
4818 |
- |
|
4819 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4820 |
-<info@greenscale.de> |
|
4821 |
- |
|
4822 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4823 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4824 |
-the Free Software Foundation, either version 3 of the License, or |
|
4825 |
-(at your option) any later version. |
|
4826 |
- |
|
4827 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4828 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4829 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4830 |
-GNU Lesser General Public License for more details. |
|
4831 |
- |
|
4832 |
-You should have received a copy of the GNU Lesser General Public License |
|
4833 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4834 |
- */ |
|
4835 |
-var lib_code; |
|
4836 |
-(function (lib_code) { |
|
4837 |
- /** |
|
4838 |
- * @author fenris |
|
4839 |
- */ |
|
4840 |
- function chain_encode(encode_links, from) { |
|
4841 |
- let value = from; |
|
4842 |
- encode_links |
|
4843 |
- .forEach((link) => { |
|
4844 |
- value = link(value); |
|
4845 |
- }); |
|
4846 |
- return value; |
|
4847 |
- } |
|
4848 |
- lib_code.chain_encode = chain_encode; |
|
4849 |
- /** |
|
4850 |
- * @author fenris |
|
4851 |
- */ |
|
4852 |
- function chain_decode(decode_links, to) { |
|
4853 |
- let value = to; |
|
4854 |
- decode_links |
|
4855 |
- .reverse() |
|
4856 |
- .forEach((link) => { |
|
4857 |
- value = link(value); |
|
4858 |
- }); |
|
4859 |
- return value; |
|
4860 |
- } |
|
4861 |
- lib_code.chain_decode = chain_decode; |
|
4862 |
-})(lib_code || (lib_code = {})); |
|
4863 |
-/* |
|
4864 |
-This file is part of »bacterio-plankton:code«. |
|
4865 |
- |
|
4866 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4867 |
-<info@greenscale.de> |
|
4868 |
- |
|
4869 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4870 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4871 |
-the Free Software Foundation, either version 3 of the License, or |
|
4872 |
-(at your option) any later version. |
|
4873 |
- |
|
4874 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4875 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4876 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4877 |
-GNU Lesser General Public License for more details. |
|
4878 |
- |
|
4879 |
-You should have received a copy of the GNU Lesser General Public License |
|
4880 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4881 |
- */ |
|
4882 |
-var lib_code; |
|
4883 |
-(function (lib_code) { |
|
4884 |
- /** |
|
4885 |
- * @author fenris |
|
4886 |
- */ |
|
4887 |
- class class_code_chain { |
|
4888 |
- /** |
|
4889 |
- * @author fenris |
|
4890 |
- */ |
|
4891 |
- constructor(links) { |
|
4892 |
- this.links = links; |
|
4893 |
- } |
|
4894 |
- /** |
|
4895 |
- * @implementation |
|
4896 |
- * @author fenris |
|
4897 |
- */ |
|
4898 |
- encode(from) { |
|
4899 |
- return lib_code.chain_encode(this.links.map((link) => (x => link.encode(x))), from); |
|
4900 |
- } |
|
4901 |
- /** |
|
4902 |
- * @implementation |
|
4903 |
- * @author fenris |
|
4904 |
- */ |
|
4905 |
- decode(to) { |
|
4906 |
- return lib_code.chain_decode(this.links.map((link) => (x => link.decode(x))), to); |
|
4907 |
- } |
|
4908 |
- } |
|
4909 |
- lib_code.class_code_chain = class_code_chain; |
|
4910 |
-})(lib_code || (lib_code = {})); |
|
4911 |
-/* |
|
4912 |
-This file is part of »bacterio-plankton:code«. |
|
4913 |
- |
|
4914 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4915 |
-<info@greenscale.de> |
|
4916 |
- |
|
4917 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4918 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4919 |
-the Free Software Foundation, either version 3 of the License, or |
|
4920 |
-(at your option) any later version. |
|
4921 |
- |
|
4922 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4923 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4924 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4925 |
-GNU Lesser General Public License for more details. |
|
4926 |
- |
|
4927 |
-You should have received a copy of the GNU Lesser General Public License |
|
4928 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4929 |
- */ |
|
4930 |
-var lib_code; |
|
4931 |
-(function (lib_code) { |
|
4932 |
- /** |
|
4933 |
- * @author Christian Fraß <frass@greenscale.de> |
|
4934 |
- */ |
|
4935 |
- function flatten_encode(from, keys = null) { |
|
4936 |
- if (keys === null) { |
|
4937 |
- if (from.length > 0) { |
|
4938 |
- keys = Object.keys(from[0]); |
|
4939 |
- } |
|
4940 |
- else { |
|
4941 |
- throw (new Error("encoding impossible")); |
|
4942 |
- } |
|
4943 |
- } |
|
4944 |
- return { |
|
4945 |
- "keys": keys, |
|
4946 |
- "data": from.map((line) => keys.map((name) => line[name])), |
|
4947 |
- }; |
|
4948 |
- } |
|
4949 |
- lib_code.flatten_encode = flatten_encode; |
|
4950 |
- /** |
|
4951 |
- * @author Christian Fraß <frass@greenscale.de> |
|
4952 |
- */ |
|
4953 |
- function flatten_decode(to) { |
|
4954 |
- return (to.data |
|
4955 |
- .map((dataset) => { |
|
4956 |
- let dataset_ = {}; |
|
4957 |
- dataset |
|
4958 |
- .forEach((value, index) => { |
|
4959 |
- const name = to.keys[index]; |
|
4960 |
- dataset_[name] = value; |
|
4961 |
- }); |
|
4962 |
- return dataset_; |
|
4963 |
- })); |
|
4964 |
- } |
|
4965 |
- lib_code.flatten_decode = flatten_decode; |
|
4966 |
-})(lib_code || (lib_code = {})); |
|
4967 |
-/* |
|
4968 |
-This file is part of »bacterio-plankton:code«. |
|
4969 |
- |
|
4970 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
4971 |
-<info@greenscale.de> |
|
4972 |
- |
|
4973 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
4974 |
-it under the terms of the GNU Lesser General Public License as published by |
|
4975 |
-the Free Software Foundation, either version 3 of the License, or |
|
4976 |
-(at your option) any later version. |
|
4977 |
- |
|
4978 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
4979 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4980 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4981 |
-GNU Lesser General Public License for more details. |
|
4982 |
- |
|
4983 |
-You should have received a copy of the GNU Lesser General Public License |
|
4984 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
4985 |
- */ |
|
4986 |
-var lib_code; |
|
4987 |
-(function (lib_code) { |
|
4988 |
- /** |
|
4989 |
- * @author fenris |
|
4990 |
- */ |
|
4991 |
- class class_code_flatten { |
|
4992 |
- /** |
|
4993 |
- * @author fenris |
|
4994 |
- */ |
|
4995 |
- constructor() { |
|
4996 |
- } |
|
4997 |
- /** |
|
4998 |
- * @implementation |
|
4999 |
- * @author fenris |
|
5000 |
- */ |
|
5001 |
- encode(x) { |
|
5002 |
- return lib_code.flatten_encode(x); |
|
5003 |
- } |
|
5004 |
- /** |
|
5005 |
- * @implementation |
|
5006 |
- * @author fenris |
|
5007 |
- */ |
|
5008 |
- decode(x) { |
|
5009 |
- return lib_code.flatten_decode(x); |
|
5010 |
- } |
|
5011 |
- } |
|
5012 |
- lib_code.class_code_flatten = class_code_flatten; |
|
5013 |
-})(lib_code || (lib_code = {})); |
|
5014 |
-/* |
|
5015 |
-This file is part of »bacterio-plankton:code«. |
|
5016 |
- |
|
5017 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5018 |
-<info@greenscale.de> |
|
5019 |
- |
|
5020 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5021 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5022 |
-the Free Software Foundation, either version 3 of the License, or |
|
5023 |
-(at your option) any later version. |
|
5024 |
- |
|
5025 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5026 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5027 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5028 |
-GNU Lesser General Public License for more details. |
|
5029 |
- |
|
5030 |
-You should have received a copy of the GNU Lesser General Public License |
|
5031 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5032 |
- */ |
|
5033 |
-var lib_code; |
|
5034 |
-(function (lib_code) { |
|
5035 |
- /** |
|
5036 |
- * @author fenris |
|
5037 |
- */ |
|
5038 |
- const _prefix = "DATE:"; |
|
5039 |
- /** |
|
5040 |
- * @author fenris |
|
5041 |
- */ |
|
5042 |
- function jsdate_encode(date) { |
|
5043 |
- let isostring = date.toISOString(); |
|
5044 |
- let date_ = (_prefix + isostring); |
|
5045 |
- return date_; |
|
5046 |
- } |
|
5047 |
- lib_code.jsdate_encode = jsdate_encode; |
|
5048 |
- /** |
|
5049 |
- * @author fenris |
|
5050 |
- */ |
|
5051 |
- function jsdate_decode(date_) { |
|
5052 |
- if ((typeof (date_) === "string") && (date_.startsWith(_prefix))) { |
|
5053 |
- let isostring = date_.slice(_prefix.length); |
|
5054 |
- let timestamp = Date.parse(isostring); |
|
5055 |
- if (!isNaN(timestamp)) { |
|
5056 |
- let date = (new Date(timestamp)); |
|
5057 |
- return date; |
|
5058 |
- } |
|
5059 |
- else { |
|
5060 |
- let message = ("'" + isostring + "' does not seem to be an ISO-string of a date"); |
|
5061 |
- throw (new Error(message)); |
|
5062 |
- } |
|
5063 |
- } |
|
5064 |
- else { |
|
5065 |
- let message = ("expected an encoded date object to be a string starting with '" + _prefix + "'"); |
|
5066 |
- throw (new Error(message)); |
|
5067 |
- } |
|
5068 |
- } |
|
5069 |
- lib_code.jsdate_decode = jsdate_decode; |
|
5070 |
-})(lib_code || (lib_code = {})); |
|
5071 |
-/* |
|
5072 |
-This file is part of »bacterio-plankton:code«. |
|
5073 |
- |
|
5074 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5075 |
-<info@greenscale.de> |
|
5076 |
- |
|
5077 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5078 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5079 |
-the Free Software Foundation, either version 3 of the License, or |
|
5080 |
-(at your option) any later version. |
|
5081 |
- |
|
5082 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5083 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5084 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5085 |
-GNU Lesser General Public License for more details. |
|
5086 |
- |
|
5087 |
-You should have received a copy of the GNU Lesser General Public License |
|
5088 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5089 |
- */ |
|
5090 |
-var lib_code; |
|
5091 |
-(function (lib_code) { |
|
5092 |
- /** |
|
5093 |
- * @author fenris |
|
5094 |
- */ |
|
5095 |
- lib_trait.attend("code", "jsdate", { |
|
5096 |
- "from": { |
|
5097 |
- "name": "date" |
|
5098 |
- }, |
|
5099 |
- "to": { |
|
5100 |
- "name": "string" |
|
5101 |
- } |
|
5102 |
- }, { |
|
5103 |
- "encode": () => (x) => { |
|
5104 |
- return lib_code.jsdate_encode(x); |
|
5105 |
- }, |
|
5106 |
- "decode": () => (y) => { |
|
5107 |
- return lib_code.jsdate_decode(y); |
|
5108 |
- } |
|
5109 |
- }); |
|
5110 |
-})(lib_code || (lib_code = {})); |
|
5111 |
-/* |
|
5112 |
-This file is part of »bacterio-plankton:code«. |
|
5113 |
- |
|
5114 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5115 |
-<info@greenscale.de> |
|
5116 |
- |
|
5117 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5118 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5119 |
-the Free Software Foundation, either version 3 of the License, or |
|
5120 |
-(at your option) any later version. |
|
5121 |
- |
|
5122 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5123 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5124 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5125 |
-GNU Lesser General Public License for more details. |
|
5126 |
- |
|
5127 |
-You should have received a copy of the GNU Lesser General Public License |
|
5128 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5129 |
- */ |
|
5130 |
-var lib_code; |
|
5131 |
-(function (lib_code) { |
|
5132 |
- /** |
|
5133 |
- * @author fenris |
|
5134 |
- */ |
|
5135 |
- class class_code_jsdate { |
|
5136 |
- /** |
|
5137 |
- * @author fenris |
|
5138 |
- */ |
|
5139 |
- constructor() { |
|
5140 |
- } |
|
5141 |
- /** |
|
5142 |
- * @implementation |
|
5143 |
- * @author fenris |
|
5144 |
- */ |
|
5145 |
- encode(x) { |
|
5146 |
- return lib_code.jsdate_encode(x); |
|
5147 |
- } |
|
5148 |
- /** |
|
5149 |
- * @implementation |
|
5150 |
- * @author fenris |
|
5151 |
- */ |
|
5152 |
- decode(x) { |
|
5153 |
- return lib_code.jsdate_decode(x); |
|
5154 |
- } |
|
5155 |
- } |
|
5156 |
- lib_code.class_code_jsdate = class_code_jsdate; |
|
5157 |
-})(lib_code || (lib_code = {})); |
|
5158 |
-/* |
|
5159 |
-This file is part of »bacterio-plankton:code«. |
|
5160 |
- |
|
5161 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5162 |
-<info@greenscale.de> |
|
5163 |
- |
|
5164 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5165 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5166 |
-the Free Software Foundation, either version 3 of the License, or |
|
5167 |
-(at your option) any later version. |
|
5168 |
- |
|
5169 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5170 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5171 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5172 |
-GNU Lesser General Public License for more details. |
|
5173 |
- |
|
5174 |
-You should have received a copy of the GNU Lesser General Public License |
|
5175 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5176 |
- */ |
|
5177 |
-var lib_code; |
|
5178 |
-(function (lib_code) { |
|
5179 |
- /** |
|
5180 |
- * @author fenris |
|
5181 |
- */ |
|
5182 |
- function json_encode(x, formatted = false) { |
|
5183 |
- return JSON.stringify(x, undefined, formatted ? "\t" : undefined); |
|
5184 |
- } |
|
5185 |
- lib_code.json_encode = json_encode; |
|
5186 |
- /** |
|
5187 |
- * @author fenris |
|
5188 |
- */ |
|
5189 |
- function json_decode(x) { |
|
5190 |
- return JSON.parse(x); |
|
5191 |
- } |
|
5192 |
- lib_code.json_decode = json_decode; |
|
5193 |
-})(lib_code || (lib_code = {})); |
|
5194 |
-/* |
|
5195 |
-This file is part of »bacterio-plankton:code«. |
|
5196 |
- |
|
5197 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5198 |
-<info@greenscale.de> |
|
5199 |
- |
|
5200 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5201 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5202 |
-the Free Software Foundation, either version 3 of the License, or |
|
5203 |
-(at your option) any later version. |
|
5204 |
- |
|
5205 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5206 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5207 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5208 |
-GNU Lesser General Public License for more details. |
|
5209 |
- |
|
5210 |
-You should have received a copy of the GNU Lesser General Public License |
|
5211 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5212 |
- */ |
|
5213 |
-var lib_code; |
|
5214 |
-(function (lib_code) { |
|
5215 |
- /** |
|
5216 |
- * @author fenris |
|
5217 |
- */ |
|
5218 |
- lib_trait.attend("code", "json", { |
|
5219 |
- "from": { |
|
5220 |
- "name": "any" |
|
5221 |
- }, |
|
5222 |
- "to": { |
|
5223 |
- "name": "string" |
|
5224 |
- } |
|
5225 |
- }, { |
|
5226 |
- "encode": () => (x) => { |
|
5227 |
- return lib_code.json_encode(x); |
|
5228 |
- }, |
|
5229 |
- "decode": () => (y) => { |
|
5230 |
- return lib_code.json_decode(y); |
|
5231 |
- } |
|
5232 |
- }); |
|
5233 |
-})(lib_code || (lib_code = {})); |
|
5234 |
-/* |
|
5235 |
-This file is part of »bacterio-plankton:code«. |
|
5236 |
- |
|
5237 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5238 |
-<info@greenscale.de> |
|
5239 |
- |
|
5240 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5241 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5242 |
-the Free Software Foundation, either version 3 of the License, or |
|
5243 |
-(at your option) any later version. |
|
5244 |
- |
|
5245 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5246 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5247 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5248 |
-GNU Lesser General Public License for more details. |
|
5249 |
- |
|
5250 |
-You should have received a copy of the GNU Lesser General Public License |
|
5251 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5252 |
- */ |
|
5253 |
-var lib_code; |
|
5254 |
-(function (lib_code) { |
|
5255 |
- /** |
|
5256 |
- * @author fenris |
|
5257 |
- */ |
|
5258 |
- class class_code_json { |
|
5259 |
- /** |
|
5260 |
- * @author fenris |
|
5261 |
- */ |
|
5262 |
- constructor() { |
|
5263 |
- } |
|
5264 |
- /** |
|
5265 |
- * @implementation |
|
5266 |
- * @author fenris |
|
5267 |
- */ |
|
5268 |
- encode(x) { |
|
5269 |
- return lib_code.json_encode(x); |
|
5270 |
- } |
|
5271 |
- /** |
|
5272 |
- * @implementation |
|
5273 |
- * @author fenris |
|
5274 |
- */ |
|
5275 |
- decode(x) { |
|
5276 |
- return lib_code.json_decode(x); |
|
5277 |
- } |
|
5278 |
- } |
|
5279 |
- lib_code.class_code_json = class_code_json; |
|
5280 |
-})(lib_code || (lib_code = {})); |
|
5281 |
-/* |
|
5282 |
-This file is part of »bacterio-plankton:code«. |
|
5283 |
- |
|
5284 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5285 |
-<info@greenscale.de> |
|
5286 |
- |
|
5287 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5288 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5289 |
-the Free Software Foundation, either version 3 of the License, or |
|
5290 |
-(at your option) any later version. |
|
5291 |
- |
|
5292 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5293 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5294 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5295 |
-GNU Lesser General Public License for more details. |
|
5296 |
- |
|
5297 |
-You should have received a copy of the GNU Lesser General Public License |
|
5298 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5299 |
- */ |
|
5300 |
-var lib_code; |
|
5301 |
-(function (lib_code) { |
|
5302 |
- /** |
|
5303 |
- * @author Christian Fraß <frass@greenscale.de> |
|
5304 |
- * @todo escaping |
|
5305 |
- */ |
|
5306 |
- function csv_encode(from, { "delimiter": delimiter = ",", "linebreak": linebreak = "\n", } = {}) { |
|
5307 |
- return (([] |
|
5308 |
- .concat((from.head !== null) |
|
5309 |
- ? [from.head] |
|
5310 |
- : []) |
|
5311 |
- .concat(from.data)) |
|
5312 |
- .map((dataset) => dataset.join(delimiter)) |
|
5313 |
- .join(linebreak)); |
|
5314 |
- } |
|
5315 |
- lib_code.csv_encode = csv_encode; |
|
5316 |
- /** |
|
5317 |
- * @author Christian Fraß <frass@greenscale.de> |
|
5318 |
- */ |
|
5319 |
- function csv_decode(to, { "delimiter": delimiter = ",", "linebreak": linebreak = "\n", "with_head": with_head = true, } = {}) { |
|
5320 |
- const array = (to.split(linebreak) |
|
5321 |
- .map((line) => line.split(delimiter))); |
|
5322 |
- return (with_head |
|
5323 |
- ? ({ |
|
5324 |
- "head": array[0], |
|
5325 |
- "data": array.slice(1), |
|
5326 |
- }) |
|
5327 |
- : ({ |
|
5328 |
- "head": null, |
|
5329 |
- "data": array, |
|
5330 |
- })); |
|
5331 |
- } |
|
5332 |
- lib_code.csv_decode = csv_decode; |
|
5333 |
-})(lib_code || (lib_code = {})); |
|
5334 |
-/* |
|
5335 |
-This file is part of »bacterio-plankton:code«. |
|
5336 |
- |
|
5337 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5338 |
-<info@greenscale.de> |
|
5339 |
- |
|
5340 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5341 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5342 |
-the Free Software Foundation, either version 3 of the License, or |
|
5343 |
-(at your option) any later version. |
|
5344 |
- |
|
5345 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5346 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5347 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5348 |
-GNU Lesser General Public License for more details. |
|
5349 |
- |
|
5350 |
-You should have received a copy of the GNU Lesser General Public License |
|
5351 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5352 |
- */ |
|
5353 |
-var lib_code; |
|
5354 |
-(function (lib_code) { |
|
5355 |
- /** |
|
5356 |
- * @author fenris |
|
5357 |
- */ |
|
5358 |
- class class_code_csv { |
|
5359 |
- /** |
|
5360 |
- * @author fenris |
|
5361 |
- */ |
|
5362 |
- constructor() { |
|
5363 |
- } |
|
5364 |
- /** |
|
5365 |
- * @implementation |
|
5366 |
- * @author fenris |
|
5367 |
- */ |
|
5368 |
- encode(x) { |
|
5369 |
- return lib_code.csv_encode(x); |
|
5370 |
- } |
|
5371 |
- /** |
|
5372 |
- * @implementation |
|
5373 |
- * @author fenris |
|
5374 |
- */ |
|
5375 |
- decode(x) { |
|
5376 |
- return lib_code.csv_decode(x); |
|
5377 |
- } |
|
5378 |
- } |
|
5379 |
- lib_code.class_code_csv = class_code_csv; |
|
5380 |
-})(lib_code || (lib_code = {})); |
|
5381 |
-/* |
|
5382 |
-This file is part of »bacterio-plankton:code«. |
|
5383 |
- |
|
5384 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5385 |
-<info@greenscale.de> |
|
5386 |
- |
|
5387 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5388 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5389 |
-the Free Software Foundation, either version 3 of the License, or |
|
5390 |
-(at your option) any later version. |
|
5391 |
- |
|
5392 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5393 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5394 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5395 |
-GNU Lesser General Public License for more details. |
|
5396 |
- |
|
5397 |
-You should have received a copy of the GNU Lesser General Public License |
|
5398 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5399 |
- */ |
|
5400 |
-var lib_code; |
|
5401 |
-(function (lib_code) { |
|
5402 |
- /** |
|
5403 |
- * @author fenris |
|
5404 |
- */ |
|
5405 |
- function uri_encode(x) { |
|
5406 |
- return encodeURIComponent(x); |
|
5407 |
- } |
|
5408 |
- lib_code.uri_encode = uri_encode; |
|
5409 |
- /** |
|
5410 |
- * @author fenris |
|
5411 |
- */ |
|
5412 |
- function uri_decode(x) { |
|
5413 |
- return decodeURIComponent(x); |
|
5414 |
- } |
|
5415 |
- lib_code.uri_decode = uri_decode; |
|
5416 |
-})(lib_code || (lib_code = {})); |
|
5417 |
-/* |
|
5418 |
-This file is part of »bacterio-plankton:code«. |
|
5419 |
- |
|
5420 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5421 |
-<info@greenscale.de> |
|
5422 |
- |
|
5423 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5424 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5425 |
-the Free Software Foundation, either version 3 of the License, or |
|
5426 |
-(at your option) any later version. |
|
5427 |
- |
|
5428 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5429 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5430 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5431 |
-GNU Lesser General Public License for more details. |
|
5432 |
- |
|
5433 |
-You should have received a copy of the GNU Lesser General Public License |
|
5434 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5435 |
- */ |
|
5436 |
-var lib_code; |
|
5437 |
-(function (lib_code) { |
|
5438 |
- /** |
|
5439 |
- * @author fenris |
|
5440 |
- */ |
|
5441 |
- lib_trait.attend("code", "uri", { |
|
5442 |
- "from": { |
|
5443 |
- "name": "string" |
|
5444 |
- }, |
|
5445 |
- "to": { |
|
5446 |
- "name": "string" |
|
5447 |
- } |
|
5448 |
- }, { |
|
5449 |
- "encode": () => (x) => { |
|
5450 |
- return lib_code.uri_encode(x); |
|
5451 |
- }, |
|
5452 |
- "decode": () => (y) => { |
|
5453 |
- return lib_code.uri_decode(y); |
|
5454 |
- } |
|
5455 |
- }); |
|
5456 |
-})(lib_code || (lib_code = {})); |
|
5457 |
-/* |
|
5458 |
-This file is part of »bacterio-plankton:code«. |
|
5459 |
- |
|
5460 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5461 |
-<info@greenscale.de> |
|
5462 |
- |
|
5463 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5464 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5465 |
-the Free Software Foundation, either version 3 of the License, or |
|
5466 |
-(at your option) any later version. |
|
5467 |
- |
|
5468 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5469 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5470 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5471 |
-GNU Lesser General Public License for more details. |
|
5472 |
- |
|
5473 |
-You should have received a copy of the GNU Lesser General Public License |
|
5474 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5475 |
- */ |
|
5476 |
-var lib_code; |
|
5477 |
-(function (lib_code) { |
|
5478 |
- /** |
|
5479 |
- * @author fenris |
|
5480 |
- */ |
|
5481 |
- class class_code_uri { |
|
5482 |
- /** |
|
5483 |
- * @author fenris |
|
5484 |
- */ |
|
5485 |
- constructor() { |
|
5486 |
- } |
|
5487 |
- /** |
|
5488 |
- * @implementation |
|
5489 |
- * @author fenris |
|
5490 |
- */ |
|
5491 |
- encode(x) { |
|
5492 |
- return lib_code.uri_encode(x); |
|
5493 |
- } |
|
5494 |
- /** |
|
5495 |
- * @implementation |
|
5496 |
- * @author fenris |
|
5497 |
- */ |
|
5498 |
- decode(x) { |
|
5499 |
- return lib_code.uri_decode(x); |
|
5500 |
- } |
|
5501 |
- } |
|
5502 |
- lib_code.class_code_uri = class_code_uri; |
|
5503 |
-})(lib_code || (lib_code = {})); |
|
5504 |
-/* |
|
5505 |
-This file is part of »bacterio-plankton:code«. |
|
5506 |
- |
|
5507 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5508 |
-<info@greenscale.de> |
|
5509 |
- |
|
5510 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5511 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5512 |
-the Free Software Foundation, either version 3 of the License, or |
|
5513 |
-(at your option) any later version. |
|
5514 |
- |
|
5515 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5516 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5517 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5518 |
-GNU Lesser General Public License for more details. |
|
5519 |
- |
|
5520 |
-You should have received a copy of the GNU Lesser General Public License |
|
5521 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5522 |
- */ |
|
5523 |
-var lib_code; |
|
5524 |
-(function (lib_code) { |
|
5525 |
- /** |
|
5526 |
- * @author fenris |
|
5527 |
- */ |
|
5528 |
- function base64_encode(x) { |
|
5529 |
- return btoa(x); |
|
5530 |
- } |
|
5531 |
- lib_code.base64_encode = base64_encode; |
|
5532 |
- /** |
|
5533 |
- * @author fenris |
|
5534 |
- */ |
|
5535 |
- function base64_decode(x) { |
|
5536 |
- return atob(x); |
|
5537 |
- } |
|
5538 |
- lib_code.base64_decode = base64_decode; |
|
5539 |
-})(lib_code || (lib_code = {})); |
|
5540 |
-/* |
|
5541 |
-This file is part of »bacterio-plankton:code«. |
|
5542 |
- |
|
5543 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5544 |
-<info@greenscale.de> |
|
5545 |
- |
|
5546 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5547 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5548 |
-the Free Software Foundation, either version 3 of the License, or |
|
5549 |
-(at your option) any later version. |
|
5550 |
- |
|
5551 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5552 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5553 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5554 |
-GNU Lesser General Public License for more details. |
|
5555 |
- |
|
5556 |
-You should have received a copy of the GNU Lesser General Public License |
|
5557 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5558 |
- */ |
|
5559 |
-var lib_code; |
|
5560 |
-(function (lib_code) { |
|
5561 |
- /** |
|
5562 |
- * @author fenris |
|
5563 |
- */ |
|
5564 |
- lib_trait.attend("code", "base64", { |
|
5565 |
- "from": { |
|
5566 |
- "name": "string" |
|
5567 |
- }, |
|
5568 |
- "to": { |
|
5569 |
- "name": "string" |
|
5570 |
- } |
|
5571 |
- }, { |
|
5572 |
- "encode": () => (x) => { |
|
5573 |
- return lib_code.base64_encode(x); |
|
5574 |
- }, |
|
5575 |
- "decode": () => (y) => { |
|
5576 |
- return lib_code.base64_decode(y); |
|
5577 |
- } |
|
5578 |
- }); |
|
5579 |
-})(lib_code || (lib_code = {})); |
|
5580 |
-/* |
|
5581 |
-This file is part of »bacterio-plankton:code«. |
|
5582 |
- |
|
5583 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5584 |
-<info@greenscale.de> |
|
5585 |
- |
|
5586 |
-»bacterio-plankton:code« is free software: you can redistribute it and/or modify |
|
5587 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5588 |
-the Free Software Foundation, either version 3 of the License, or |
|
5589 |
-(at your option) any later version. |
|
5590 |
- |
|
5591 |
-»bacterio-plankton:code« is distributed in the hope that it will be useful, |
|
5592 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5593 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5594 |
-GNU Lesser General Public License for more details. |
|
5595 |
- |
|
5596 |
-You should have received a copy of the GNU Lesser General Public License |
|
5597 |
-along with »bacterio-plankton:code«. If not, see <http://www.gnu.org/licenses/>. |
|
5598 |
- */ |
|
5599 |
-var lib_code; |
|
5600 |
-(function (lib_code) { |
|
5601 |
- /** |
|
5602 |
- * @author fenris |
|
5603 |
- */ |
|
5604 |
- class class_code_base64 { |
|
5605 |
- /** |
|
5606 |
- * @author fenris |
|
5607 |
- */ |
|
5608 |
- constructor() { |
|
5609 |
- } |
|
5610 |
- /** |
|
5611 |
- * @implementation |
|
5612 |
- * @author fenris |
|
5613 |
- */ |
|
5614 |
- encode(x) { |
|
5615 |
- return lib_code.base64_encode(x); |
|
5616 |
- } |
|
5617 |
- /** |
|
5618 |
- * @implementation |
|
5619 |
- * @author fenris |
|
5620 |
- */ |
|
5621 |
- decode(x) { |
|
5622 |
- return lib_code.base64_decode(x); |
|
5623 |
- } |
|
5624 |
- } |
|
5625 |
- lib_code.class_code_base64 = class_code_base64; |
|
5626 |
-})(lib_code || (lib_code = {})); |
|
5627 |
-/* |
|
5628 |
-This file is part of »bacterio-plankton:string«. |
|
5629 |
- |
|
5630 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5631 |
-<info@greenscale.de> |
|
5632 |
- |
|
5633 |
-»bacterio-plankton:string« is free software: you can redistribute it and/or modify |
|
5634 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5635 |
-the Free Software Foundation, either version 3 of the License, or |
|
5636 |
-(at your option) any later version. |
|
5637 |
- |
|
5638 |
-»bacterio-plankton:string« is distributed in the hope that it will be useful, |
|
5639 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5640 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5641 |
-GNU Lesser General Public License for more details. |
|
5642 |
- |
|
5643 |
-You should have received a copy of the GNU Lesser General Public License |
|
5644 |
-along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>. |
|
5645 |
- */ |
|
5646 |
-var plain_text_to_html = function (text) { |
|
5647 |
- var ret = text; |
|
5648 |
- ret = ret.replace(/ /g, " "); // convert multiple whitespace to forced ones |
|
5649 |
- ret = ret.split("\n").join("<br/>"); |
|
5650 |
- return ret; |
|
5651 |
-}; |
|
5652 |
-/** |
|
5653 |
- * @desc makes a valid |
|
5654 |
- */ |
|
5655 |
-var format_sentence = function (str, rtl, caseSense) { |
|
5656 |
- if (rtl === void 0) { rtl = false; } |
|
5657 |
- if (caseSense === void 0) { caseSense = true; } |
|
5658 |
- if (str === "") { |
|
5659 |
- return str; |
|
5660 |
- } |
|
5661 |
- else { |
|
5662 |
- var marks = { |
|
5663 |
- ".": true, |
|
5664 |
- "?": true, |
|
5665 |
- "!": true |
|
5666 |
- }; |
|
5667 |
- var default_mark = "."; |
|
5668 |
- var ret = str.split(""); |
|
5669 |
- if (!rtl) { |
|
5670 |
- ret[0] = ret[0].toLocaleUpperCase(); |
|
5671 |
- if (!(ret[ret.length - 1] in marks)) { |
|
5672 |
- ret.push(default_mark); |
|
5673 |
- } |
|
5674 |
- } |
|
5675 |
- else { |
|
5676 |
- ret[ret.length - 1] = ret[ret.length - 1].toLocaleUpperCase(); |
|
5677 |
- if (!(ret[0] in marks)) { |
|
5678 |
- ret.unshift(default_mark); |
|
5679 |
- } |
|
5680 |
- } |
|
5681 |
- return ret.join(""); |
|
5682 |
- } |
|
5683 |
-}; |
|
5684 |
-var fill_string_template = function (template_string, object, fabric, delimiter, default_string, sloppy) { |
|
5685 |
- if (fabric === void 0) { fabric = function (object, key) { return object[key]; }; } |
|
5686 |
- if (delimiter === void 0) { delimiter = "%"; } |
|
5687 |
- if (default_string === void 0) { default_string = null; } |
|
5688 |
- function get_tags(str) { |
|
5689 |
- var r = new RegExp(delimiter + "[^\\s^" + delimiter + "]+" + delimiter, "gi"); |
|
5690 |
- return ((str.match(r) || []).map(function (e) { |
|
5691 |
- return e.slice(delimiter.length, e.length - delimiter.length); |
|
5692 |
- })); |
|
5693 |
- } |
|
5694 |
- function replace_tag(str, tag, value) { |
|
5695 |
- var r = new RegExp(delimiter + tag + delimiter, "gi"); |
|
5696 |
- return str.replace(r, value); |
|
5697 |
- } |
|
5698 |
- function replace_tags(str, obj) { |
|
5699 |
- return (get_tags(str).reduce(function (ret, key) { |
|
5700 |
- var value = ""; |
|
5701 |
- try { |
|
5702 |
- value = fabric(obj, key); |
|
5703 |
- if ((!sloppy && (value === void 0)) || (sloppy && (value == void 0))) { |
|
5704 |
- value = default_string; |
|
5705 |
- } |
|
5706 |
- } |
|
5707 |
- catch (e) { |
|
5708 |
- console.warn("invalid placeholder " + key); |
|
5709 |
- value = default_string; |
|
5710 |
- } |
|
5711 |
- return replace_tag(ret, key, value); |
|
5712 |
- }, str)); |
|
5713 |
- } |
|
5714 |
- return replace_tags(template_string, object); |
|
5715 |
-}; |
|
5716 |
-var make_string_template = function (_template, _fabrics) { |
|
5717 |
- if (_fabrics === void 0) { _fabrics = {}; } |
|
5718 |
- function replace_tag(str, tag, value) { |
|
5719 |
- var r = new RegExp("%" + tag + "%", "gi"); |
|
5720 |
- return str.replace(r, value); |
|
5721 |
- } |
|
5722 |
- function replace_tags(str, obj) { |
|
5723 |
- return (Object.keys(obj).reduce(function (ret, key) { |
|
5724 |
- return replace_tag(ret, key, _fabrics[key] || obj[key]); |
|
5725 |
- }, str)); |
|
5726 |
- } |
|
5727 |
- return (function (tags) { |
|
5728 |
- return replace_tags(_template, tags); |
|
5729 |
- }); |
|
5730 |
-}; |
|
5731 |
-var make_eml_header = (function () { |
|
5732 |
- var _template = ""; |
|
5733 |
- _template += "From: %from%\n"; |
|
5734 |
- _template += "To: %recipient%\n"; |
|
5735 |
- _template += "Subject: %subject%\n"; |
|
5736 |
- _template += "X-Mailer: greenscale-plankton.emlgen\n"; |
|
5737 |
- return make_string_template(_template); |
|
5738 |
-})(); |
|
5739 |
-var make_eml_body = (function () { |
|
5740 |
- var exports = {}; |
|
5741 |
- exports["simple_body"] = make_string_template("Content-Type: %contenttype%\n\n%body%\n\n"); |
|
5742 |
- // very basic implementation |
|
5743 |
- // parts = [{contenttype:"text/html; charset=UTF-8", body: "<h1>foo</h1>" }, {...}] |
|
5744 |
- exports["body_boundrary"] = function (parts, boundrary) { |
|
5745 |
- var _template = ""; |
|
5746 |
- _template += "--%boundrary%\n"; |
|
5747 |
- _template += "Content-Type: %contenttype%\n\n%body%\n\n"; |
|
5748 |
- //_template += "--%boundrary%--\n\n"; |
|
5749 |
- var maker = make_string_template(_template); |
|
5750 |
- return (parts.reduce(function (prev, curr) { |
|
5751 |
- curr.boundrary = boundrary; |
|
5752 |
- return [prev, maker(curr)].join(""); |
|
5753 |
- }, "")); |
|
5754 |
- }; |
|
5755 |
- // body must be base64 encoded! |
|
5756 |
- exports["attachment_boundrary"] = function (parts, boundrary) { |
|
5757 |
- var _template = ""; |
|
5758 |
- _template += "--%boundrary%\n"; |
|
5759 |
- _template += "Content-Type: %contenttype%\n"; |
|
5760 |
- _template += "Content-Transfer-Encoding: base64\n"; |
|
5761 |
- _template += "Content-Disposition: %disposition%; filename=\"%name%\"\n\n"; |
|
5762 |
- _template += "%body%\n\n"; |
|
5763 |
- //_template += "--%boundrary%--\n\n"; |
|
5764 |
- var maker = make_string_template(_template); |
|
5765 |
- return (parts.reduce(function (prev, curr) { |
|
5766 |
- curr.boundrary = boundrary; |
|
5767 |
- if (curr.disposition === void 0) |
|
5768 |
- curr.disposition = "inline"; |
|
5769 |
- return [prev, maker(curr)].join(""); |
|
5770 |
- }, "")); |
|
5771 |
- }; |
|
5772 |
- exports["gen_boundrary"] = function () { |
|
5773 |
- return ("xxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) { |
|
5774 |
- var r = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0, v = c == "x" ? r : (r & 0x3 | 0x8); |
|
5775 |
- return v.toString(16); |
|
5776 |
- })); |
|
5777 |
- }; |
|
5778 |
- // simple implementation without alternatives (old rfc) |
|
5779 |
- exports["complete_boundrary"] = function (bodyparts, attachments) { |
|
5780 |
- var ret = ""; |
|
5781 |
- var boundrary = exports["gen_boundrary"](); |
|
5782 |
- ret += exports["body_boundrary"](bodyparts, boundrary); |
|
5783 |
- ret += exports["attachment_boundrary"](attachments, boundrary); |
|
5784 |
- ret += "--" + boundrary + "--\n\nINVISIBLE!!!!"; |
|
5785 |
- return (exports["simple_body"]({ |
|
5786 |
- "contenttype": sprintf("multipart/mixed; boundary=%s", [boundrary]), |
|
5787 |
- "body": ret |
|
5788 |
- })); |
|
5789 |
- }; |
|
5790 |
- return exports; |
|
5791 |
-})(); |
|
5792 |
-/* |
|
5793 |
-This file is part of »bacterio-plankton:string«. |
|
5794 |
- |
|
5795 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
5796 |
-<info@greenscale.de> |
|
5797 |
- |
|
5798 |
-»bacterio-plankton:string« is free software: you can redistribute it and/or modify |
|
5799 |
-it under the terms of the GNU Lesser General Public License as published by |
|
5800 |
-the Free Software Foundation, either version 3 of the License, or |
|
5801 |
-(at your option) any later version. |
|
5802 |
- |
|
5803 |
-»bacterio-plankton:string« is distributed in the hope that it will be useful, |
|
5804 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5805 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5806 |
-GNU Lesser General Public License for more details. |
|
5807 |
- |
|
5808 |
-You should have received a copy of the GNU Lesser General Public License |
|
5809 |
-along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>. |
|
5810 |
- */ |
|
5811 |
-var lib_string; |
|
5812 |
-(function (lib_string) { |
|
5813 |
- /** |
|
5814 |
- * @author fenris |
|
5815 |
- */ |
|
5816 |
- var hexdigits = 4; |
|
5817 |
- /** |
|
5818 |
- * @author fenris |
|
5819 |
- */ |
|
5820 |
- var index_max = (1 << (4 * hexdigits)); |
|
5821 |
- /** |
|
5822 |
- * @author fenris |
|
5823 |
- */ |
|
5824 |
- var index_is = 0; |
|
5825 |
- /** |
|
5826 |
- * @author neuc,frac |
|
5827 |
- */ |
|
5828 |
- function empty(str) { |
|
5829 |
- return (str.trim() === ""); |
|
5830 |
- } |
|
5831 |
- lib_string.empty = empty; |
|
5832 |
- /** |
|
5833 |
- * @desc returns a unique string |
|
5834 |
- * @param {string} prefix an optional prefix for the generated string |
|
5835 |
- * @return {string} |
|
5836 |
- * @author fenris |
|
5837 |
- */ |
|
5838 |
- function generate(prefix) { |
|
5839 |
- if (prefix === void 0) { prefix = "string_"; } |
|
5840 |
- if (index_is > index_max) { |
|
5841 |
- throw (new Error("[string_generate] out of valid indices")); |
|
5842 |
- } |
|
5843 |
- else { |
|
5844 |
- return lib_string.sprintf(prefix + "%0" + hexdigits.toString() + "X", [index_is++]); |
|
5845 |
- } |
|
5846 |
- } |
|
5847 |
- lib_string.generate = generate; |
|
5848 |
- /** |
|
5849 |
- * @desc splits a string, but returns an empty list, if the string is empty |
|
5850 |
- * @param {string} chain |
|
5851 |
- * @param {string} separator |
|
5852 |
- * @return {Array<string>} |
|
5853 |
- * @author fenris |
|
5854 |
- */ |
|
5855 |
- function split(chain, separator) { |
|
5856 |
- if (separator === void 0) { separator = " "; } |
|
5857 |
- if (chain.length == 0) { |
|
5858 |
- return []; |
|
5859 |
- } |
|
5860 |
- else { |
|
5861 |
- return chain.split(separator); |
|
5862 |
- } |
|
5863 |
- } |
|
5864 |
- lib_string.split = split; |
|
5865 |
- /** |
|
5866 |
- * @author neu3no |
|
5867 |
- */ |
|
5868 |
- function explode(str, needle, max) { |
|
5869 |
- var temp = str.split(needle); |
|
5870 |
- var right = temp.splice(max - 1); |
|
5871 |
- temp.push(right.join(needle)); |
|
5872 |
- return temp; |
|
5873 |
- } |
|
5874 |
- lib_string.explode = explode; |
|
5875 |
- /** |
|
5876 |
- * @desc concats a given word with itself n times |
|
5877 |
- * @param {string} word |
|
5878 |
- * @param {int} |
|
5879 |
- * @return {string} |
|
5880 |
- * @author fenris |
|
5881 |
- */ |
|
5882 |
- function repeat(word, count) { |
|
5883 |
- // return ((count == 0) ? "" : (word + repeat(word, count-1))); |
|
5884 |
- var result = ""; |
|
5885 |
- for (var n = 0; n < count; n += 1) { |
|
5886 |
- result += word; |
|
5887 |
- } |
|
5888 |
- return result; |
|
5889 |
- } |
|
5890 |
- lib_string.repeat = repeat; |
|
5891 |
- /** |
|
5892 |
- * @desc lengthens a string by repeatedly appending or prepending another string |
|
5893 |
- * @param {string} word the string to pad |
|
5894 |
- * @param {int} length the length, which the result shall have |
|
5895 |
- * @param {string} symbol the string, which will be added (multiple times) |
|
5896 |
- * @param {boolean} [prepend]; whether to prepend (~true) or append (~false); default: false |
|
5897 |
- * @return {string} the padded string |
|
5898 |
- * @author fenris |
|
5899 |
- */ |
|
5900 |
- function pad(word, length, symbol, mode) { |
|
5901 |
- if (symbol === void 0) { symbol = " "; } |
|
5902 |
- if (mode === void 0) { mode = "append"; } |
|
5903 |
- switch (mode) { |
|
5904 |
- case "prepend": { |
|
5905 |
- // insert symbols only at the beginning |
|
5906 |
- while (word.length < length) |
|
5907 |
- word = symbol + word; |
|
5908 |
- return word.substring(word.length - length); |
|
5909 |
- break; |
|
5910 |
- } |
|
5911 |
- case "append": { |
|
5912 |
- // insert symbols only at the end |
|
5913 |
- while (word.length < length) |
|
5914 |
- word = word + symbol; |
|
5915 |
- return word.substring(0, length); |
|
5916 |
- break; |
|
5917 |
- } |
|
5918 |
- case "widen": { |
|
5919 |
- // insert symbols at both sides |
|
5920 |
- var left = (((length - word.length) & 1) === 0); |
|
5921 |
- while (word.length < length) { |
|
5922 |
- word = (left |
|
5923 |
- ? (symbol + word) |
|
5924 |
- : (word + symbol)); |
|
5925 |
- left = (!left); |
|
5926 |
- } |
|
5927 |
- return word.substring(0, length); |
|
5928 |
- break; |
|
5929 |
- } |
|
5930 |
- default: { |
|
5931 |
- var message = ("unhandled mode '" + mode + "'"); |
|
5932 |
- console.warn(message); |
|
5933 |
- return word; |
|
5934 |
- break; |
|
5935 |
- } |
|
5936 |
- } |
|
5937 |
- } |
|
5938 |
- lib_string.pad = pad; |
|
5939 |
- /** |
|
5940 |
- * @desc checks if a given string conttains a certain substring |
|
5941 |
- * @param {string} string |
|
5942 |
- * @param {string} part |
|
5943 |
- * @return {boolean} |
|
5944 |
- * @author fenris |
|
5945 |
- */ |
|
5946 |
- function contains(chain, part) { |
|
5947 |
- if (typeof (chain) !== "string") { |
|
5948 |
- return false; |
|
5949 |
- } |
|
5950 |
- return (chain.indexOf(part) >= 0); |
|
5951 |
- } |
|
5952 |
- lib_string.contains = contains; |
|
5953 |
- /** |
|
5954 |
- * @desc checks if a given string starts with a certain substring |
|
5955 |
- * @param {string} string |
|
5956 |
- * @param {string} part |
|
5957 |
- * @return {boolean} |
|
5958 |
- * @author fenris |
|
5959 |
- */ |
|
5960 |
- function startsWith(chain, part) { |
|
5961 |
- if (typeof (chain) !== "string") { |
|
5962 |
- return false; |
|
5963 |
- } |
|
5964 |
- // return (string.indexOf(part) === 0); |
|
5965 |
- return ((function (m, n) { |
|
5966 |
- if (n === 0) { |
|
5967 |
- return true; |
|
5968 |
- } |
|
5969 |
- else { |
|
5970 |
- if (m === 0) { |
|
5971 |
- return false; |
|
5972 |
- } |
|
5973 |
- else { |
|
5974 |
- return ((chain[0] == part[0]) |
|
5975 |
- && |
|
5976 |
- startsWith(chain.substring(1), part.substring(1))); |
|
5977 |
- } |
|
5978 |
- } |
|
5979 |
- })(chain.length, part.length)); |
|
5980 |
- } |
|
5981 |
- lib_string.startsWith = startsWith; |
|
5982 |
- /** |
|
5983 |
- * @desc checks if a given string ends with a certain substring |
|
5984 |
- * @param {string} string |
|
5985 |
- * @param {string} part |
|
5986 |
- * @return {boolean} |
|
5987 |
- * @author fenris |
|
5988 |
- */ |
|
5989 |
- function endsWith(chain, part) { |
|
5990 |
- if (typeof (chain) !== "string") { |
|
5991 |
- return false; |
|
5992 |
- } |
|
5993 |
- // return (string.lastIndexOf(part) === string.length-part.length); |
|
5994 |
- return ((function (m, n) { |
|
5995 |
- if (n === 0) { |
|
5996 |
- return true; |
|
5997 |
- } |
|
5998 |
- else { |
|
5999 |
- if (m === 0) { |
|
6000 |
- return false; |
|
6001 |
- } |
|
6002 |
- else { |
|
6003 |
- // console.info(("(" + string[m-1] + " == " + part[n-1] + ")") + " = " + String(string[m-1] == part[n-1])); |
|
6004 |
- return ((chain[m - 1] === part[n - 1]) |
|
6005 |
- && |
|
6006 |
- endsWith(chain.substring(0, m - 1), part.substring(0, n - 1))); |
|
6007 |
- } |
|
6008 |
- } |
|
6009 |
- })(chain.length, part.length)); |
|
6010 |
- } |
|
6011 |
- lib_string.endsWith = endsWith; |
|
6012 |
- /** |
|
6013 |
- * @desc count the occourrences of a string in a string |
|
6014 |
- * @param string haystack_string the string wich should be examined |
|
6015 |
- * @param string needle_string the string which should be counted |
|
6016 |
- * @author neuc |
|
6017 |
- */ |
|
6018 |
- function count_occourrences(haystack_string, needle_string, check_escape) { |
|
6019 |
- var cnt = 0; |
|
6020 |
- var pos = -1; |
|
6021 |
- do { |
|
6022 |
- pos = haystack_string.indexOf(needle_string, pos + 1); |
|
6023 |
- if ((!check_escape) || (haystack_string[pos - 1] != "\\")) { |
|
6024 |
- cnt++; |
|
6025 |
- } |
|
6026 |
- } while (pos >= 0); |
|
6027 |
- return (cnt - 1); |
|
6028 |
- } |
|
6029 |
- lib_string.count_occourrences = count_occourrences; |
|
6030 |
- /** |
|
6031 |
- * @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object |
|
6032 |
- * @author fenris |
|
6033 |
- */ |
|
6034 |
- function coin(str, args) { |
|
6035 |
- Object.keys(args).forEach(function (key) { |
|
6036 |
- // old syntax |
|
6037 |
- { |
|
6038 |
- var value = args[key]; |
|
6039 |
- var regexp_argument = new RegExp("\\${" + key + "}"); |
|
6040 |
- str = str.replace(regexp_argument, value); |
|
6041 |
- } |
|
6042 |
- // new syntax |
|
6043 |
- { |
|
6044 |
- var value = args[key]; |
|
6045 |
- var regexp_argument = new RegExp("{{" + key + "}}"); |
|
6046 |
- str = str.replace(regexp_argument, value); |
|
6047 |
- } |
|
6048 |
- }); |
|
6049 |
- return str; |
|
6050 |
- } |
|
6051 |
- lib_string.coin = coin; |
|
6052 |
- /** |
|
6053 |
- * @author fenris |
|
6054 |
- */ |
|
6055 |
- lib_string.stance = coin; |
|
6056 |
- /** |
|
6057 |
- * @author fenris |
|
6058 |
- */ |
|
6059 |
- function url_encode(_a) { |
|
6060 |
- var _b = _a === void 0 ? {} : _a, _c = _b["protocol"], protocol = _c === void 0 ? null : _c, _d = _b["host"], host = _d === void 0 ? null : _d, _e = _b["port"], port = _e === void 0 ? null : _e, _f = _b["path"], path = _f === void 0 ? null : _f, _g = _b["arguments"], arguments_ = _g === void 0 ? null : _g; |
|
6061 |
- var url = ""; |
|
6062 |
- // protocol |
|
6063 |
- { |
|
6064 |
- if (protocol != null) { |
|
6065 |
- url = protocol + ":" + url; |
|
6066 |
- } |
|
6067 |
- } |
|
6068 |
- // host |
|
6069 |
- { |
|
6070 |
- if (host != null) { |
|
6071 |
- url = url + "//" + host; |
|
6072 |
- } |
|
6073 |
- } |
|
6074 |
- // port |
|
6075 |
- { |
|
6076 |
- if (port != null) { |
|
6077 |
- url = url + ":" + port.toString(); |
|
6078 |
- } |
|
6079 |
- } |
|
6080 |
- // path |
|
6081 |
- { |
|
6082 |
- if (path != null) { |
|
6083 |
- var path_ = encodeURI(path); |
|
6084 |
- url = "" + url + path_; |
|
6085 |
- } |
|
6086 |
- } |
|
6087 |
- // arguments |
|
6088 |
- { |
|
6089 |
- if (arguments_ != null) { |
|
6090 |
- var suffix = Object.keys(arguments_).map(function (key) { return key + "=" + arguments_[key]; }).join("&"); |
|
6091 |
- var suffix_ = encodeURI(suffix); |
|
6092 |
- url = url + "?" + suffix_; |
|
6093 |
- } |
|
6094 |
- } |
|
6095 |
- return url; |
|
6096 |
- } |
|
6097 |
- lib_string.url_encode = url_encode; |
|
6098 |
- /** |
|
6099 |
- * @author fenris |
|
6100 |
- */ |
|
6101 |
- lib_string.make_url = url_encode; |
|
6102 |
- /** |
|
6103 |
- * @author fenris |
|
6104 |
- * @todo arguments |
|
6105 |
- */ |
|
6106 |
- function url_decode(url) { |
|
6107 |
- var regexp = new RegExp("^([^:]*)://([^:]*):([^/]*)/(.*)$"); |
|
6108 |
- var matching = regexp.exec(url); |
|
6109 |
- if (matching === null) { |
|
6110 |
- return null; |
|
6111 |
- } |
|
6112 |
- else { |
|
6113 |
- var components = { |
|
6114 |
- "protocol": matching[1], |
|
6115 |
- "host": matching[2], |
|
6116 |
- "port": parseInt(matching[3]), |
|
6117 |
- "path": ("/" + matching[4]) |
|
6118 |
- }; |
|
6119 |
- return components; |
|
6120 |
- } |
|
6121 |
- } |
|
6122 |
- lib_string.url_decode = url_decode; |
|
6123 |
- /** |
|
6124 |
- * @author fenris |
|
6125 |
- */ |
|
6126 |
- function cut(str, length, delimiter) { |
|
6127 |
- if (delimiter === void 0) { delimiter = "…"; } |
|
6128 |
- if (str.length <= length) { |
|
6129 |
- return str; |
|
6130 |
- } |
|
6131 |
- else { |
|
6132 |
- return (str.slice(0, length - delimiter.length) + delimiter); |
|
6133 |
- } |
|
6134 |
- } |
|
6135 |
- lib_string.cut = cut; |
|
6136 |
-})(lib_string || (lib_string = {})); |
|
6137 |
-/* |
|
6138 |
-This file is part of »bacterio-plankton:string«. |
|
6139 |
- |
|
6140 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
6141 |
-<info@greenscale.de> |
|
6142 |
- |
|
6143 |
-»bacterio-plankton:string« is free software: you can redistribute it and/or modify |
|
6144 |
-it under the terms of the GNU Lesser General Public License as published by |
|
6145 |
-the Free Software Foundation, either version 3 of the License, or |
|
6146 |
-(at your option) any later version. |
|
6147 |
- |
|
6148 |
-»bacterio-plankton:string« is distributed in the hope that it will be useful, |
|
6149 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
6150 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
6151 |
-GNU Lesser General Public License for more details. |
|
6152 |
- |
|
6153 |
-You should have received a copy of the GNU Lesser General Public License |
|
6154 |
-along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>. |
|
6155 |
- */ |
|
6156 |
-var lib_string; |
|
6157 |
-(function (lib_string) { |
|
6158 |
- var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/; |
|
6159 |
- var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g; |
|
6160 |
- function split_format(format) { |
|
6161 |
- var tmp = format.match(pattern); |
|
6162 |
- if (tmp === null) |
|
6163 |
- return null; |
|
6164 |
- return { |
|
6165 |
- 'flags': tmp[1].split(""), |
|
6166 |
- 'width': Number(tmp[2]), |
|
6167 |
- 'precision': tmp[3] === '' ? null : Number(tmp[3]), |
|
6168 |
- 'specifier': tmp[4], |
|
6169 |
- 'string': format |
|
6170 |
- }; |
|
6171 |
- } |
|
6172 |
- function make_err(format, arg, should) { |
|
6173 |
- return ("[sprintf]" + " " + "argument for '" + format.string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!"); |
|
6174 |
- } |
|
6175 |
- function test_arg(format, arg, should) { |
|
6176 |
- if (typeof arg !== should) { |
|
6177 |
- console.warn(make_err(format, arg, should)); |
|
6178 |
- return false; |
|
6179 |
- } |
|
6180 |
- return true; |
|
6181 |
- } |
|
6182 |
- function string_fill(str, char, len, left) { |
|
6183 |
- while (str.length < len) { |
|
6184 |
- if (left) { |
|
6185 |
- str += char; |
|
6186 |
- } |
|
6187 |
- else { |
|
6188 |
- str = char + str; |
|
6189 |
- } |
|
6190 |
- } |
|
6191 |
- return str; |
|
6192 |
- } |
|
6193 |
- /** |
|
6194 |
- * the known_parameters are used to parse the different identifiers for the welln known syntax: |
|
6195 |
- * flag width precision identifier |
|
6196 |
- * %{[0#+- ]}{[0-9]*}.{[0-9]*}[fFdiueEgGsoxXaAsn] |
|
6197 |
- * flags: |
|
6198 |
- * 0 - fill with '0' instead of ' ' if the string length < width |
|
6199 |
- * # - not implemented |
|
6200 |
- * - - left-justified -> fill on the right side to reach width |
|
6201 |
- * + - force using '+' on positive numbers |
|
6202 |
- * ' ' - add a single space before positive numbers |
|
6203 |
- * |
|
6204 |
- * identifiers |
|
6205 |
- * %f, %F - interpret given number as float, width: the minimal total width (fill with ' ' or '0' if the |
|
6206 |
- * resulting string is too short, precision: cut more then given decimal places |
|
6207 |
- * %d, %i, %u - interpret number as integer, decimal places will be cut. width: like float, precision: |
|
6208 |
- * fill with '0' on right side until length given in precision is reached |
|
6209 |
- * %e - interpret as float and write as scientifical number, width & precision like in float |
|
6210 |
- * %E - same es %e but uppercase 'E' |
|
6211 |
- * %g - use the shortest string of %f or %e |
|
6212 |
- * %G - use the shortest string of %E or %E |
|
6213 |
- * %s - simply print a string |
|
6214 |
- * %o - print the given number in octal notation |
|
6215 |
- * %x - print the given number in hex notation |
|
6216 |
- * %X - same as %x but with uppercase characters |
|
6217 |
- * %a - alias to %x |
|
6218 |
- * %A - alias to %X |
|
6219 |
- * %n - just print nothing |
|
6220 |
- * @type {{}} |
|
6221 |
- */ |
|
6222 |
- var known_params = {}; |
|
6223 |
- known_params["f"] = function (format, arg) { |
|
6224 |
- if (!test_arg(format, arg, "number")) |
|
6225 |
- return "Ø"; |
|
6226 |
- var tmp = Math.abs(arg); |
|
6227 |
- var sign = (arg < 0) ? -1 : 1; |
|
6228 |
- var tmp_result = null; |
|
6229 |
- if (format.precision !== null) { |
|
6230 |
- tmp = Math.floor(Math.pow(10, format.precision) * tmp) / Math.pow(10, format.precision); |
|
6231 |
- var tmp_ = (tmp * sign).toString().split("."); |
|
6232 |
- if (tmp_.length === 1) |
|
6233 |
- tmp_.push(""); |
|
6234 |
- tmp_[1] = string_fill(tmp_[1], "0", format.precision, true); |
|
6235 |
- tmp_result = tmp_.join("."); |
|
6236 |
- } |
|
6237 |
- else { |
|
6238 |
- tmp_result = (sign * tmp).toString(); |
|
6239 |
- } |
|
6240 |
- if ((format.flags.indexOf(" ") >= 0) && (arg >= 0)) { |
|
6241 |
- tmp_result = " " + tmp; |
|
6242 |
- } |
|
6243 |
- else if ((format.flags.indexOf("+") >= 0) && (arg >= 0)) { |
|
6244 |
- tmp_result = "+" + tmp; |
|
6245 |
- } |
|
6246 |
- tmp_result = string_fill(tmp, (format.flags.indexOf("0") >= 0) ? "0" : " ", format.width, (format.flags.indexOf("-") >= 0)); |
|
6247 |
- return tmp_result; |
|
6248 |
- }; |
|
6249 |
- known_params["F"] = known_params["f"]; |
|
6250 |
- known_params["d"] = function (format, arg) { |
|
6251 |
- if (!test_arg(format, arg, 'number')) |
|
6252 |
- return 'Ø'; |
|
6253 |
- var tmp = (((arg < 0 && format.specifier !== 'u') ? -1 : 1) * Math.floor(Math.abs(arg))).toString(); |
|
6254 |
- if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf(' ') >= 0 && arg >= 0) { |
|
6255 |
- tmp = ' ' + tmp; |
|
6256 |
- } |
|
6257 |
- else if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf('+') >= 0 && arg >= 0) { |
|
6258 |
- tmp = '+' + tmp; |
|
6259 |
- } |
|
6260 |
- tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
6261 |
- tmp = string_fill(tmp, '0', format.precision === null ? 0 : format.precision, false); |
|
6262 |
- return tmp; |
|
6263 |
- }; |
|
6264 |
- known_params["i"] = known_params["d"]; |
|
6265 |
- known_params["u"] = known_params["d"]; |
|
6266 |
- known_params["e"] = function (format, arg) { |
|
6267 |
- if (!test_arg(format, arg, 'number')) |
|
6268 |
- return 'Ø'; |
|
6269 |
- var tmp = arg.toExponential(format.precision === null ? undefined : format.precision).toString(); |
|
6270 |
- if (format.flags.indexOf(' ') >= 0 && arg >= 0) { |
|
6271 |
- tmp = ' ' + tmp; |
|
6272 |
- } |
|
6273 |
- else if (format.flags.indexOf('+') >= 0 && arg >= 0) { |
|
6274 |
- tmp = '+' + tmp; |
|
6275 |
- } |
|
6276 |
- tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
6277 |
- return tmp; |
|
6278 |
- }; |
|
6279 |
- known_params["E"] = function (format, arg) { |
|
6280 |
- return known_params["e"](format, arg).toUpperCase(); |
|
6281 |
- }; |
|
6282 |
- known_params["g"] = function (format, arg) { |
|
6283 |
- if (!test_arg(format, arg, 'number')) |
|
6284 |
- return 'Ø'; |
|
6285 |
- var tmpf = known_params["f"](format, arg); |
|
6286 |
- var tmpe = known_params["e"](format, arg); |
|
6287 |
- if (tmpf.length < tmpe.length) { |
|
6288 |
- return tmpf; |
|
6289 |
- } |
|
6290 |
- else { |
|
6291 |
- return tmpe; |
|
6292 |
- } |
|
6293 |
- }; |
|
6294 |
- known_params["G"] = function (format, arg) { |
|
6295 |
- return known_params["g"](format, arg).toUpperCase(); |
|
6296 |
- }; |
|
6297 |
- known_params["s"] = function (format, arg) { |
|
6298 |
- if (!test_arg(format, arg, 'string')) |
|
6299 |
- return 'o.O'; |
|
6300 |
- var tmp = format.precision !== null ? arg.substr(0, format.precision) : arg; |
|
6301 |
- tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); |
|
6302 |
- return tmp; |
|
6303 |
- }; |
|
6304 |
- known_params["o"] = function (format, arg) { |
|
6305 |
- if (!test_arg(format, arg, 'number')) |
|
6306 |
- return 'Ø'; |
|
6307 |
- var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); |
|
6308 |
- return known_params["s"](format, tmp.toString(8)); |
|
6309 |
- }; |
|
6310 |
- known_params["x"] = function (format, arg) { |
|
6311 |
- if (!test_arg(format, arg, 'number')) |
|
6312 |
- return 'Ø'; |
|
6313 |
- var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); |
|
6314 |
- return known_params["s"](format, tmp.toString(16)); |
|
6315 |
- }; |
|
6316 |
- known_params["a"] = known_params["x"]; |
|
6317 |
- known_params["X"] = function (format, arg) { |
|
6318 |
- if (!test_arg(format, arg, 'number')) |
|
6319 |
- return 'Ø'; |
|
6320 |
- return known_params["x"](format, arg).toUpperCase(); |
|
6321 |
- }; |
|
6322 |
- known_params["A"] = known_params["X"]; |
|
6323 |
- known_params["c"] = function (format, arg) { |
|
6324 |
- var tmp = ""; |
|
6325 |
- if (typeof arg === "number") { |
|
6326 |
- tmp = String.fromCharCode(arg); |
|
6327 |
- } |
|
6328 |
- else if ((typeof arg === "string") && (arg.length === 1)) { |
|
6329 |
- tmp = arg[0]; |
|
6330 |
- } |
|
6331 |
- else { |
|
6332 |
- console.warn(make_err(format, arg, "number|string") + " and if string it needs to have the length of 1!"); |
|
6333 |
- } |
|
6334 |
- return known_params["s"](format, tmp); |
|
6335 |
- }; |
|
6336 |
- known_params["n"] = function () { |
|
6337 |
- return ""; |
|
6338 |
- }; |
|
6339 |
- var decompose = function (chain, regexp) { |
|
6340 |
- var result = regexp.exec(chain); |
|
6341 |
- if (result == null) { |
|
6342 |
- return null; |
|
6343 |
- } |
|
6344 |
- else { |
|
6345 |
- var front = chain.substring(0, result.index); |
|
6346 |
- var back = chain.substring(result.index + result[0].length); |
|
6347 |
- return { "front": front, "match": result[0], "back": back }; |
|
6348 |
- } |
|
6349 |
- }; |
|
6350 |
- /** |
|
6351 |
- * an implementation of c sprintf |
|
6352 |
- * @param {string} string format string |
|
6353 |
- * @param {array} args arguments which should be filled into |
|
6354 |
- * @returns {string} |
|
6355 |
- */ |
|
6356 |
- lib_string.sprintf = function (input, args, original) { |
|
6357 |
- if (args === void 0) { args = []; } |
|
6358 |
- if (original === void 0) { original = null; } |
|
6359 |
- if (original == null) |
|
6360 |
- original = input; |
|
6361 |
- var components = decompose(input, pattern); |
|
6362 |
- if (components == null) { |
|
6363 |
- if (args.length > 0) { |
|
6364 |
- console.warn("[sprintf] superfluous arguments while formatting '" + original + "': ", args); |
|
6365 |
- } |
|
6366 |
- return input; |
|
6367 |
- } |
|
6368 |
- else { |
|
6369 |
- var arg; |
|
6370 |
- var rest; |
|
6371 |
- if (args.length > 0) { |
|
6372 |
- arg = args[0]; |
|
6373 |
- rest = args.slice(1); |
|
6374 |
- } |
|
6375 |
- else { |
|
6376 |
- console.warn("[sprintf] out of arguments while formatting '" + original + "'"); |
|
6377 |
- arg = null; |
|
6378 |
- rest = []; |
|
6379 |
- return input; |
|
6380 |
- } |
|
6381 |
- var fmt = split_format(components["match"]); |
|
6382 |
- return (components["front"] |
|
6383 |
- + known_params[fmt.specifier](fmt, arg) |
|
6384 |
- + lib_string.sprintf(components["back"], rest, original)); |
|
6385 |
- } |
|
6386 |
- }; |
|
6387 |
- /** |
|
6388 |
- * an implementation of c printf |
|
6389 |
- * @param {string} string format string |
|
6390 |
- * @param {array} args arguments which should be filled into |
|
6391 |
- * @returns {string} |
|
6392 |
- */ |
|
6393 |
- function printf(format, args) { |
|
6394 |
- console.log(lib_string.sprintf(format, args)); |
|
6395 |
- } |
|
6396 |
- lib_string.printf = printf; |
|
6397 |
-})(lib_string || (lib_string = {})); |
|
6398 |
-var sprintf = lib_string.sprintf; |
|
6399 |
-var printf = lib_string.printf; |
|
6400 |
-/* |
|
6401 |
-This file is part of »bacterio-plankton:string«. |
|
6402 |
- |
|
6403 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
6404 |
-<info@greenscale.de> |
|
6405 |
- |
|
6406 |
-»bacterio-plankton:string« is free software: you can redistribute it and/or modify |
|
6407 |
-it under the terms of the GNU Lesser General Public License as published by |
|
6408 |
-the Free Software Foundation, either version 3 of the License, or |
|
6409 |
-(at your option) any later version. |
|
6410 |
- |
|
6411 |
-»bacterio-plankton:string« is distributed in the hope that it will be useful, |
|
6412 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
6413 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
6414 |
-GNU Lesser General Public License for more details. |
|
6415 |
- |
|
6416 |
-You should have received a copy of the GNU Lesser General Public License |
|
6417 |
-along with »bacterio-plankton:string«. If not, see <http://www.gnu.org/licenses/>. |
|
6418 |
- */ |
|
6419 |
-var make_logger = (function () { |
|
6420 |
- var _loggers = {}; |
|
6421 |
- var make_logger = function (prefix, current_loglevel) { |
|
6422 |
- var log = []; |
|
6423 |
- var level = [ |
|
6424 |
- "LOG", "INFO", "WARNING", "DEBUG" |
|
6425 |
- ]; |
|
6426 |
- var logger = function (obj, lvl) { |
|
6427 |
- var txt = obj.txt || obj; |
|
6428 |
- if (lvl == void 0) |
|
6429 |
- lvl = 0; |
|
6430 |
- var date = new Date(); |
|
6431 |
- log.push({ |
|
6432 |
- "message": sprintf("%s [%s:%s] %s", [date.toString(), level[lvl], prefix, txt]), |
|
6433 |
- "timeStamp": +(date) |
|
6434 |
- }); |
|
6435 |
- if (lvl <= current_loglevel) { |
|
6436 |
- var msg = ["[" + prefix + "]", txt]; |
|
6437 |
- if (obj.arg) |
|
6438 |
- msg = ["[" + prefix + "]"].concat(Array.prototype.slice.call(obj.arg)); |
|
6439 |
- if (lvl === 0) |
|
6440 |
- console["_log"].apply(console, msg); |
|
6441 |
- else if (lvl === 1) |
|
6442 |
- console["_info"].apply(console, msg); |
|
6443 |
- else if (lvl === 2) |
|
6444 |
- console["_warn"].apply(console, msg); |
|
6445 |
- else if (lvl >= 3) |
|
6446 |
- console["_log"].apply(console, msg); |
|
6447 |
- } |
|
6448 |
- }; |
|
6449 |
- _loggers[prefix] = { |
|
6450 |
- "logger": logger, |
|
6451 |
- "log": log |
|
6452 |
- }; |
|
6453 |
- return logger; |
|
6454 |
- }; |
|
6455 |
- make_logger["loggers"] = _loggers; |
|
6456 |
- make_logger["complete_log"] = function () { |
|
6457 |
- var logs = Object.keys(_loggers) |
|
6458 |
- .reduce(function (p, c) { |
|
6459 |
- return [].concat(p, _loggers[c].log); |
|
6460 |
- }, []); |
|
6461 |
- logs.sort(function (x, y) { |
|
6462 |
- return ((x.timeStamp > y.timeStamp) ? -1 : +1); |
|
6463 |
- }); |
|
6464 |
- return logs.map(function (x, i, a) { |
|
6465 |
- return x.message; |
|
6466 |
- }); |
|
6467 |
- }; |
|
6468 |
- if ( /*!track_exports*/true) { |
|
6469 |
- var _log_all = function (log, lvl, next) { |
|
6470 |
- if (next === void 0) { next = function () { }; } |
|
6471 |
- return function () { |
|
6472 |
- var msg = []; |
|
6473 |
- for (var i = 0; i < arguments.length; i++) { |
|
6474 |
- if (typeof arguments[i] === "string") { |
|
6475 |
- msg.push(arguments[i]); |
|
6476 |
- } |
|
6477 |
- else { |
|
6478 |
- msg.push(JSON.stringify(arguments[i])); |
|
6479 |
- } |
|
6480 |
- } |
|
6481 |
- var obj = { |
|
6482 |
- txt: msg.join("\t"), |
|
6483 |
- arg: arguments |
|
6484 |
- }; |
|
6485 |
- log(obj, lvl); |
|
6486 |
- next(); |
|
6487 |
- }; |
|
6488 |
- }; |
|
6489 |
- { |
|
6490 |
- var __warn = make_logger("deprecated console.warn", 99); |
|
6491 |
- var __error = make_logger("deprecated console.error", 99); |
|
6492 |
- var __log = make_logger("deprecated console.log", 99); |
|
6493 |
- var __info = make_logger("deprecated console.info", 99); |
|
6494 |
- // bad ass |
|
6495 |
- console["_log"] = console.log; |
|
6496 |
- console["_error"] = console.error; |
|
6497 |
- console["_warn"] = console.warn; |
|
6498 |
- console["_info"] = console.info; |
|
6499 |
- /* |
|
6500 |
- console["log"] = _log_all(__log, 0); |
|
6501 |
- console["error"] = _log_all(__error, 2); |
|
6502 |
- console["warn"] = _log_all(__warn, 2); |
|
6503 |
- console["info"] = _log_all(__info, 0); |
|
6504 |
- */ |
|
6505 |
- } |
|
6506 |
- /* |
|
6507 |
- { |
|
6508 |
- make_logger["send_log"] = function(){ |
|
6509 |
- eml_log( |
|
6510 |
- function () { |
|
6511 |
- alert("fehlerbericht wurde gesendet!"); |
|
6512 |
- } |
|
6513 |
- ); |
|
6514 |
- }; |
|
6515 |
- var error_log = make_logger("global.error", 99); |
|
6516 |
- window.onerror = _log_all( |
|
6517 |
- error_log, |
|
6518 |
- 1, |
|
6519 |
- function(){ |
|
6520 |
- if (global_config == undefined) { |
|
6521 |
- return false; |
|
6522 |
- } |
|
6523 |
- if (global_config.report_error) { |
|
6524 |
- make_logger["send_log"](); |
|
6525 |
- } |
|
6526 |
- } |
|
6527 |
- ); |
|
6528 |
- } |
|
6529 |
- */ |
|
6530 |
- } |
|
6531 |
- return make_logger; |
|
6532 |
-})(); |
|
6533 |
-/* |
|
6534 |
-This file is part of »bacterio-plankton:call«. |
|
6535 |
- |
|
6536 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
6537 |
-<info@greenscale.de> |
|
6538 |
- |
|
6539 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
6540 |
-it under the terms of the GNU Lesser General Public License as published by |
|
6541 |
-the Free Software Foundation, either version 3 of the License, or |
|
6542 |
-(at your option) any later version. |
|
6543 |
- |
|
6544 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
6545 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
6546 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
6547 |
-GNU Lesser General Public License for more details. |
|
6548 |
- |
|
6549 |
-You should have received a copy of the GNU Lesser General Public License |
|
6550 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
6551 |
- */ |
|
6552 |
-"use strict"; |
|
6553 |
-/* |
|
6554 |
-This file is part of »bacterio-plankton:call«. |
|
6555 |
- |
|
6556 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
6557 |
-<info@greenscale.de> |
|
6558 |
- |
|
6559 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
6560 |
-it under the terms of the GNU Lesser General Public License as published by |
|
6561 |
-the Free Software Foundation, either version 3 of the License, or |
|
6562 |
-(at your option) any later version. |
|
6563 |
- |
|
6564 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
6565 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
6566 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
6567 |
-GNU Lesser General Public License for more details. |
|
6568 |
- |
|
6569 |
-You should have received a copy of the GNU Lesser General Public License |
|
6570 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
6571 |
- */ |
|
6572 |
-var lib_call; |
|
6573 |
-(function (lib_call) { |
|
6574 |
- /** |
|
6575 |
- * @desc hacked class for postfix function application |
|
6576 |
- * @author fenris |
|
6577 |
- */ |
|
6578 |
- class class_valuewrapper { |
|
6579 |
- /** |
|
6580 |
- * @desc [constructor] |
|
6581 |
- * @author fenris |
|
6582 |
- */ |
|
6583 |
- constructor(value) { |
|
6584 |
- this.value = value; |
|
6585 |
- } |
|
6586 |
- /** |
|
6587 |
- * @desc [accessor] applies a function and returns a new valuewrapper |
|
6588 |
- * @author fenris |
|
6589 |
- */ |
|
6590 |
- pass(function_) { |
|
6591 |
- return (new class_valuewrapper(function_(this.value))); |
|
6592 |
- } |
|
6593 |
- /** |
|
6594 |
- * @desc [accessor] gives the wrapped value |
|
6595 |
- * @author fenris |
|
6596 |
- */ |
|
6597 |
- extract() { |
|
6598 |
- return this.value; |
|
6599 |
- } |
|
6600 |
- } |
|
6601 |
- lib_call.class_valuewrapper = class_valuewrapper; |
|
6602 |
- /** |
|
6603 |
- * @desc shortcut for constructing a valuewrapper-object |
|
6604 |
- * @author fenris |
|
6605 |
- */ |
|
6606 |
- function vw(value) { |
|
6607 |
- return (new class_valuewrapper(value)); |
|
6608 |
- } |
|
6609 |
- lib_call.vw = vw; |
|
6610 |
- /** |
|
6611 |
- * @author fenris |
|
6612 |
- */ |
|
6613 |
- function use(input, function_) { |
|
6614 |
- return function_(input); |
|
6615 |
- } |
|
6616 |
- lib_call.use = use; |
|
6617 |
- /** |
|
6618 |
- * @desc just the identity; useful for some callbacks etc. |
|
6619 |
- * @author fenris |
|
6620 |
- */ |
|
6621 |
- function id(x) { |
|
6622 |
- return x; |
|
6623 |
- } |
|
6624 |
- lib_call.id = id; |
|
6625 |
- /** |
|
6626 |
- * @desc composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions) |
|
6627 |
- * @param {function} function_f |
|
6628 |
- * @param {function} function_g |
|
6629 |
- * @author fenris |
|
6630 |
- */ |
|
6631 |
- function compose(function_f, function_g) { |
|
6632 |
- return (function (x) { |
|
6633 |
- // return function_g(function_f(x)); |
|
6634 |
- return function_g(function_f.apply(function_f, lib_call.args2list(arguments))); |
|
6635 |
- }); |
|
6636 |
- } |
|
6637 |
- lib_call.compose = compose; |
|
6638 |
- /** |
|
6639 |
- * @desc transforms a function with sequential input into a function with leveled input; example: add(2,3) = curryfy(add)(2)(3) |
|
6640 |
- * @param {function} f |
|
6641 |
- * @param {int} n (don't set manually) |
|
6642 |
- * @return {function} the currified version of the in put function |
|
6643 |
- * @author fenris |
|
6644 |
- */ |
|
6645 |
- function curryfy(f, n = f.length) { |
|
6646 |
- switch (n) { |
|
6647 |
- case 0: { |
|
6648 |
- throw (new Error("[curryfy] impossible")); |
|
6649 |
- // break; |
|
6650 |
- } |
|
6651 |
- case 1: { |
|
6652 |
- return f; |
|
6653 |
- // break; |
|
6654 |
- } |
|
6655 |
- default: { |
|
6656 |
- return (function (x) { |
|
6657 |
- return (curryfy(function () { return f.apply(f, [x].concat(lib_call.args2list(arguments))); }, n - 1)); |
|
6658 |
- }); |
|
6659 |
- // break; |
|
6660 |
- } |
|
6661 |
- } |
|
6662 |
- } |
|
6663 |
- lib_call.curryfy = curryfy; |
|
6664 |
-})(lib_call || (lib_call = {})); |
|
6665 |
-var lib_call; |
|
6666 |
-(function (lib_call) { |
|
6667 |
- /** |
|
6668 |
- * @author fenris |
|
6669 |
- */ |
|
6670 |
- function executor_resolve(result) { |
|
6671 |
- return ((resolve, reject) => resolve(result)); |
|
6672 |
- } |
|
6673 |
- lib_call.executor_resolve = executor_resolve; |
|
6674 |
- /** |
|
6675 |
- * @author fenris |
|
6676 |
- */ |
|
6677 |
- function executor_reject(reason) { |
|
6678 |
- return ((resolve, reject) => reject(reason)); |
|
6679 |
- } |
|
6680 |
- lib_call.executor_reject = executor_reject; |
|
6681 |
- /** |
|
6682 |
- * @author fenris |
|
6683 |
- */ |
|
6684 |
- function executor_transform(executor, transform_result, transform_reason) { |
|
6685 |
- return ((resolve, reject) => { |
|
6686 |
- executor(result => resolve(transform_result(result)), reason => reject(transform_reason(reason))); |
|
6687 |
- }); |
|
6688 |
- } |
|
6689 |
- lib_call.executor_transform = executor_transform; |
|
6690 |
- /** |
|
6691 |
- * @author fenris |
|
6692 |
- */ |
|
6693 |
- function executor_transform_default(executor, transform_result, wrap_string = null) { |
|
6694 |
- let transform_reason = (error => ((wrap_string == null) ? error : new class_error(wrap_string, [error]))); |
|
6695 |
- return (executor_transform(executor, transform_result, transform_reason)); |
|
6696 |
- } |
|
6697 |
- lib_call.executor_transform_default = executor_transform_default; |
|
6698 |
- /** |
|
6699 |
- * @author fenris |
|
6700 |
- */ |
|
6701 |
- function executor_compose_sequential(first, second) { |
|
6702 |
- return ((resolve, reject) => { |
|
6703 |
- first(result => { |
|
6704 |
- second(result)(resolve, reject); |
|
6705 |
- }, reason => { |
|
6706 |
- reject(reason); |
|
6707 |
- }); |
|
6708 |
- }); |
|
6709 |
- } |
|
6710 |
- lib_call.executor_compose_sequential = executor_compose_sequential; |
|
6711 |
- /** |
|
6712 |
- * @author fenris |
|
6713 |
- */ |
|
6714 |
- function executor_chain(state, executors) { |
|
6715 |
- return ((resolve, reject) => { |
|
6716 |
- if (executors.length == 0) { |
|
6717 |
- return resolve(state); |
|
6718 |
- } |
|
6719 |
- else { |
|
6720 |
- return executors[0](state)(result => { |
|
6721 |
- executor_chain(result, executors.slice(1))(resolve, reject); |
|
6722 |
- }, reject); |
|
6723 |
- } |
|
6724 |
- }); |
|
6725 |
- /* |
|
6726 |
- */ |
|
6727 |
- /* |
|
6728 |
- if (executors.length == 0) { |
|
6729 |
- return executor_resolve<type_state, type_error>(state); |
|
6730 |
- } |
|
6731 |
- else if (executors.length == 1) { |
|
6732 |
- return executors[0](state); |
|
6733 |
- } |
|
6734 |
- else { |
|
6735 |
- return ( |
|
6736 |
- executor_chain<type_state, type_error>( |
|
6737 |
- state, |
|
6738 |
- [ |
|
6739 |
- state => (resolve, reject) => executors[0](state)(result => executors[1](result)(resolve, reject), reject) |
|
6740 |
- ].concat(executors.slice(2)) |
|
6741 |
- ) |
|
6742 |
- ); |
|
6743 |
- } |
|
6744 |
- */ |
|
6745 |
- /* |
|
6746 |
- return ( |
|
6747 |
- executors.reduce( |
|
6748 |
- (chain, current) => executor_compose_sequential<type_state, type_state, type_error>(chain, current, deferred), |
|
6749 |
- executor_resolve<type_state, type_error>(state) |
|
6750 |
- ) |
|
6751 |
- ); |
|
6752 |
- */ |
|
6753 |
- } |
|
6754 |
- lib_call.executor_chain = executor_chain; |
|
6755 |
- /** |
|
6756 |
- * @author fenris |
|
6757 |
- */ |
|
6758 |
- function executor_first(executors) { |
|
6759 |
- /* |
|
6760 |
- return ( |
|
6761 |
- (resolve, reject) => { |
|
6762 |
- if (executors.length == 0) { |
|
6763 |
- reject(new Error("all failed")); |
|
6764 |
- } |
|
6765 |
- else { |
|
6766 |
- executors[0]( |
|
6767 |
- result => { |
|
6768 |
- resolve(result); |
|
6769 |
- }, |
|
6770 |
- reason => { |
|
6771 |
- executor_first<type_result, type_reason>(executors.slice(1))(resolve, reject); |
|
6772 |
- } |
|
6773 |
- ) |
|
6774 |
- } |
|
6775 |
- } |
|
6776 |
- ); |
|
6777 |
- */ |
|
6778 |
- return ((resolve, reject) => { |
|
6779 |
- executor_chain([], executors.map(executor => reasons => (resolve_, reject_) => { |
|
6780 |
- executor(result => reject_(result), reason => resolve_(reasons.concat([reason]))); |
|
6781 |
- }))(errors => reject(errors), result => resolve(result)); |
|
6782 |
- }); |
|
6783 |
- } |
|
6784 |
- lib_call.executor_first = executor_first; |
|
6785 |
- /** |
|
6786 |
- * @author fenris |
|
6787 |
- */ |
|
6788 |
- function executor_condense(executors) { |
|
6789 |
- return (executor_chain([], executors.map(executor => result => (resolve, reject) => { |
|
6790 |
- executor(element => resolve(result.concat([element])), reject); |
|
6791 |
- }))); |
|
6792 |
- } |
|
6793 |
- lib_call.executor_condense = executor_condense; |
|
6794 |
- /** |
|
6795 |
- * @author fenris |
|
6796 |
- * @deprecated use condense |
|
6797 |
- */ |
|
6798 |
- function executor_filter(executors, predicate) { |
|
6799 |
- return (executor_chain([], executors.map(executor => result => (resolve, reject) => { |
|
6800 |
- executor(element => resolve(predicate(element) ? result.concat([element]) : result), reject); |
|
6801 |
- }))); |
|
6802 |
- } |
|
6803 |
- lib_call.executor_filter = executor_filter; |
|
6804 |
- /** |
|
6805 |
- * @author fenris |
|
6806 |
- * @deprecated use condense |
|
6807 |
- */ |
|
6808 |
- function executor_map(executors, transformator) { |
|
6809 |
- return (executor_chain([], executors.map(executor => result => (resolve, reject) => { |
|
6810 |
- executor(element1 => resolve(result.concat([transformator(element1)])), reject); |
|
6811 |
- }))); |
|
6812 |
- } |
|
6813 |
- lib_call.executor_map = executor_map; |
|
6814 |
- /** |
|
6815 |
- * @author fenris |
|
6816 |
- * @deprecated use condense |
|
6817 |
- */ |
|
6818 |
- function executor_reduce(executors, initial, accumulator) { |
|
6819 |
- return (executor_chain(initial, executors.map(executor => result => (resolve, reject) => { |
|
6820 |
- executor(element => resolve(accumulator(result, element)), reject); |
|
6821 |
- }))); |
|
6822 |
- } |
|
6823 |
- lib_call.executor_reduce = executor_reduce; |
|
6824 |
-})(lib_call || (lib_call = {})); |
|
6825 |
-/* |
|
6826 |
-This file is part of »bacterio-plankton:call«. |
|
6827 |
- |
|
6828 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
6829 |
-<info@greenscale.de> |
|
6830 |
- |
|
6831 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
6832 |
-it under the terms of the GNU Lesser General Public License as published by |
|
6833 |
-the Free Software Foundation, either version 3 of the License, or |
|
6834 |
-(at your option) any later version. |
|
6835 |
- |
|
6836 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
6837 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
6838 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
6839 |
-GNU Lesser General Public License for more details. |
|
6840 |
- |
|
6841 |
-You should have received a copy of the GNU Lesser General Public License |
|
6842 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
6843 |
- */ |
|
6844 |
-var lib_call; |
|
6845 |
-(function (lib_call) { |
|
6846 |
- /** |
|
6847 |
- * @author fenris |
|
6848 |
- */ |
|
6849 |
- function promise_reject(reason) { |
|
6850 |
- return Promise.reject(reason); |
|
6851 |
- } |
|
6852 |
- lib_call.promise_reject = promise_reject; |
|
6853 |
- /** |
|
6854 |
- * @author fenris |
|
6855 |
- */ |
|
6856 |
- function promise_resolve(result) { |
|
6857 |
- return Promise.resolve(result); |
|
6858 |
- } |
|
6859 |
- lib_call.promise_resolve = promise_resolve; |
|
6860 |
- /** |
|
6861 |
- * @author fenris |
|
6862 |
- */ |
|
6863 |
- function promise_make(executor) { |
|
6864 |
- return (new Promise(executor)); |
|
6865 |
- } |
|
6866 |
- lib_call.promise_make = promise_make; |
|
6867 |
- /** |
|
6868 |
- * @author fenris |
|
6869 |
- */ |
|
6870 |
- function promise_then_close(promise, resolver, rejector) { |
|
6871 |
- promise.then(resolver, rejector); |
|
6872 |
- } |
|
6873 |
- lib_call.promise_then_close = promise_then_close; |
|
6874 |
- /** |
|
6875 |
- * @author fenris |
|
6876 |
- */ |
|
6877 |
- function promise_then_append(promise, resolver, rejector = null) { |
|
6878 |
- if (rejector == null) { |
|
6879 |
- rejector = (reason) => promise_reject(reason); |
|
6880 |
- } |
|
6881 |
- return (promise.then(resolver, rejector)); |
|
6882 |
- } |
|
6883 |
- lib_call.promise_then_append = promise_then_append; |
|
6884 |
- /** |
|
6885 |
- * @author fenris |
|
6886 |
- */ |
|
6887 |
- function promise_all(promises) { |
|
6888 |
- return Promise.all(promises); |
|
6889 |
- } |
|
6890 |
- lib_call.promise_all = promise_all; |
|
6891 |
- /** |
|
6892 |
- * @author fenris |
|
6893 |
- */ |
|
6894 |
- function promise_chain(promises, start = undefined) { |
|
6895 |
- return (promises.reduce((chain, promise) => promise_then_append(chain, promise), promise_resolve(start))); |
|
6896 |
- } |
|
6897 |
- lib_call.promise_chain = promise_chain; |
|
6898 |
- /** |
|
6899 |
- * @author fenris |
|
6900 |
- */ |
|
6901 |
- function promise_condense(promises) { |
|
6902 |
- return (promise_chain(promises.map(promise => result => promise_then_append(promise(), element => promise_resolve(result.concat([element])))), [])); |
|
6903 |
- } |
|
6904 |
- lib_call.promise_condense = promise_condense; |
|
6905 |
- /** |
|
6906 |
- * @author fenris |
|
6907 |
- */ |
|
6908 |
- function promise_group(promises, serial = false) { |
|
6909 |
- const decorate = function (promise, name) { |
|
6910 |
- return (() => promise_then_append(promise(), value => promise_resolve({ "key": name, "value": value }))); |
|
6911 |
- }; |
|
6912 |
- const convert = function (array) { |
|
6913 |
- let object = {}; |
|
6914 |
- array.forEach(({ "key": key, "value": value }) => { object[key] = value; }); |
|
6915 |
- return object; |
|
6916 |
- }; |
|
6917 |
- if (serial) { |
|
6918 |
- return (promise_then_append(promise_condense(Object.keys(promises) |
|
6919 |
- .map(name => decorate(promises[name], name))), list => promise_resolve(convert(list)))); |
|
6920 |
- } |
|
6921 |
- else { |
|
6922 |
- return (promise_then_append(promise_all(Object.keys(promises) |
|
6923 |
- .map(name => decorate(promises[name], name)) |
|
6924 |
- .map(promise => promise())), list => promise_resolve(convert(list)))); |
|
6925 |
- } |
|
6926 |
- } |
|
6927 |
- lib_call.promise_group = promise_group; |
|
6928 |
- /** |
|
6929 |
- * @author fenris |
|
6930 |
- */ |
|
6931 |
- function promise_wrap(promise, transformator_result, transformator_reason = lib_call.id) { |
|
6932 |
- return (promise_make((resolve, reject) => { |
|
6933 |
- promise_then_close(promise, result => resolve(transformator_result(result)), reason => reject(transformator_reason(reason))); |
|
6934 |
- })); |
|
6935 |
- } |
|
6936 |
- lib_call.promise_wrap = promise_wrap; |
|
6937 |
- /** |
|
6938 |
- * @author fenris |
|
6939 |
- */ |
|
6940 |
- function promise_show(label) { |
|
6941 |
- return (result => promise_make((resolve, reject) => { |
|
6942 |
- lib_log.info(label + ": " + instance_show(result)); |
|
6943 |
- resolve(result); |
|
6944 |
- })); |
|
6945 |
- } |
|
6946 |
- lib_call.promise_show = promise_show; |
|
6947 |
- /** |
|
6948 |
- * @author fenris |
|
6949 |
- */ |
|
6950 |
- function promise_log(result) { |
|
6951 |
- return promise_show("log"); |
|
6952 |
- } |
|
6953 |
- lib_call.promise_log = promise_log; |
|
6954 |
- /** |
|
6955 |
- * @author fenris |
|
6956 |
- */ |
|
6957 |
- function promise_attach(state, promise, name) { |
|
6958 |
- return (promise_wrap(promise, result => { |
|
6959 |
- state[name] = result; |
|
6960 |
- return state; |
|
6961 |
- })); |
|
6962 |
- } |
|
6963 |
- lib_call.promise_attach = promise_attach; |
|
6964 |
- /** |
|
6965 |
- * @author fenris |
|
6966 |
- */ |
|
6967 |
- function promise_delay(promise, delay) { |
|
6968 |
- return promise_make((resolve, reject) => { |
|
6969 |
- lib_call.timeout(() => { |
|
6970 |
- promise_then_close(promise, resolve, reject); |
|
6971 |
- return null; |
|
6972 |
- }, delay); |
|
6973 |
- }); |
|
6974 |
- } |
|
6975 |
- lib_call.promise_delay = promise_delay; |
|
6976 |
- /** |
|
6977 |
- * @author fenris |
|
6978 |
- */ |
|
6979 |
- function promise_to_executor(promise) { |
|
6980 |
- return ((resolve, reject) => promise.then(resolve, reject)); |
|
6981 |
- } |
|
6982 |
- lib_call.promise_to_executor = promise_to_executor; |
|
6983 |
-})(lib_call || (lib_call = {})); |
|
6984 |
-/* |
|
6985 |
-This file is part of »bacterio-plankton:call«. |
|
6986 |
- |
|
6987 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
6988 |
-<info@greenscale.de> |
|
6989 |
- |
|
6990 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
6991 |
-it under the terms of the GNU Lesser General Public License as published by |
|
6992 |
-the Free Software Foundation, either version 3 of the License, or |
|
6993 |
-(at your option) any later version. |
|
6994 |
- |
|
6995 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
6996 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
6997 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
6998 |
-GNU Lesser General Public License for more details. |
|
6999 |
- |
|
7000 |
-You should have received a copy of the GNU Lesser General Public License |
|
7001 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
7002 |
- */ |
|
7003 |
-var lib_call; |
|
7004 |
-(function (lib_call) { |
|
7005 |
- lib_call.initializer_state_initial = 0; |
|
7006 |
- lib_call.initializer_state_waiting = 1; |
|
7007 |
- lib_call.initializer_state_successful = 2; |
|
7008 |
- lib_call.initializer_state_failed = 3; |
|
7009 |
- /** |
|
7010 |
- * @author fenris |
|
7011 |
- */ |
|
7012 |
- function initializer_make(fetcher) { |
|
7013 |
- let subject = { |
|
7014 |
- "fetcher": fetcher, |
|
7015 |
- "state": lib_call.initializer_state_initial, |
|
7016 |
- "queue": [], |
|
7017 |
- "result": undefined, |
|
7018 |
- "reason": undefined, |
|
7019 |
- }; |
|
7020 |
- return subject; |
|
7021 |
- } |
|
7022 |
- lib_call.initializer_make = initializer_make; |
|
7023 |
- /** |
|
7024 |
- * @author fenris |
|
7025 |
- */ |
|
7026 |
- function initializer_actuate(subject) { |
|
7027 |
- switch (subject.state) { |
|
7028 |
- case lib_call.initializer_state_successful: { |
|
7029 |
- subject.queue.forEach(entry => entry.resolve(subject.result)); |
|
7030 |
- break; |
|
7031 |
- } |
|
7032 |
- case lib_call.initializer_state_failed: { |
|
7033 |
- subject.queue.forEach(entry => entry.reject(subject.reason)); |
|
7034 |
- break; |
|
7035 |
- } |
|
7036 |
- default: { |
|
7037 |
- let message = `unhandled state ${subject.state}`; |
|
7038 |
- throw (new Error(message)); |
|
7039 |
- break; |
|
7040 |
- } |
|
7041 |
- } |
|
7042 |
- } |
|
7043 |
- /** |
|
7044 |
- * @author fenris |
|
7045 |
- */ |
|
7046 |
- function initializer_reset(subject) { |
|
7047 |
- subject.state = lib_call.initializer_state_initial; |
|
7048 |
- subject.queue = []; |
|
7049 |
- } |
|
7050 |
- lib_call.initializer_reset = initializer_reset; |
|
7051 |
- /** |
|
7052 |
- * @author fenris |
|
7053 |
- */ |
|
7054 |
- function initializer_state(subject) { |
|
7055 |
- return subject.state; |
|
7056 |
- } |
|
7057 |
- lib_call.initializer_state = initializer_state; |
|
7058 |
- /** |
|
7059 |
- * @author fenris |
|
7060 |
- */ |
|
7061 |
- function initializer_get(subject) { |
|
7062 |
- switch (subject.state) { |
|
7063 |
- case lib_call.initializer_state_initial: { |
|
7064 |
- subject.state = lib_call.initializer_state_waiting; |
|
7065 |
- return (lib_call.promise_make((resolve, reject) => { |
|
7066 |
- subject.queue.push({ "resolve": resolve, "reject": reject }); |
|
7067 |
- subject.fetcher().then(result => { |
|
7068 |
- subject.state = lib_call.initializer_state_successful; |
|
7069 |
- subject.result = result; |
|
7070 |
- initializer_actuate(subject); |
|
7071 |
- }, reason => { |
|
7072 |
- subject.state = lib_call.initializer_state_failed; |
|
7073 |
- subject.reason = reason; |
|
7074 |
- initializer_actuate(subject); |
|
7075 |
- }); |
|
7076 |
- })); |
|
7077 |
- break; |
|
7078 |
- } |
|
7079 |
- case lib_call.initializer_state_waiting: { |
|
7080 |
- return (lib_call.promise_make((resolve, reject) => { |
|
7081 |
- subject.queue.push({ "resolve": resolve, "reject": reject }); |
|
7082 |
- })); |
|
7083 |
- break; |
|
7084 |
- } |
|
7085 |
- case lib_call.initializer_state_successful: { |
|
7086 |
- return (lib_call.promise_resolve(subject.result)); |
|
7087 |
- break; |
|
7088 |
- } |
|
7089 |
- case lib_call.initializer_state_failed: { |
|
7090 |
- return (lib_call.promise_reject(subject.reason)); |
|
7091 |
- break; |
|
7092 |
- } |
|
7093 |
- default: { |
|
7094 |
- let message = `unhandled state ${subject.state}`; |
|
7095 |
- throw (new Error(message)); |
|
7096 |
- break; |
|
7097 |
- } |
|
7098 |
- } |
|
7099 |
- } |
|
7100 |
- lib_call.initializer_get = initializer_get; |
|
7101 |
- /** |
|
7102 |
- * @author fenris |
|
7103 |
- */ |
|
7104 |
- function initializer_get_sync(subject) { |
|
7105 |
- switch (subject.state) { |
|
7106 |
- case lib_call.initializer_state_successful: { |
|
7107 |
- return subject.result; |
|
7108 |
- break; |
|
7109 |
- } |
|
7110 |
- case lib_call.initializer_state_failed: { |
|
7111 |
- throw subject.reason; |
|
7112 |
- break; |
|
7113 |
- } |
|
7114 |
- default: { |
|
7115 |
- let message = `unhandled state ${subject.state}`; |
|
7116 |
- throw (new Error(message)); |
|
7117 |
- break; |
|
7118 |
- } |
|
7119 |
- } |
|
7120 |
- } |
|
7121 |
- /** |
|
7122 |
- * @author fenris |
|
7123 |
- */ |
|
7124 |
- function initializer_set_sync(subject, result) { |
|
7125 |
- switch (subject.state) { |
|
7126 |
- case lib_call.initializer_state_successful: { |
|
7127 |
- subject.result = result; |
|
7128 |
- break; |
|
7129 |
- } |
|
7130 |
- case lib_call.initializer_state_failed: { |
|
7131 |
- subject.state = lib_call.initializer_state_successful; |
|
7132 |
- subject.result = result; |
|
7133 |
- break; |
|
7134 |
- } |
|
7135 |
- default: { |
|
7136 |
- let message = `unhandled state ${subject.state}`; |
|
7137 |
- throw (new Error(message)); |
|
7138 |
- break; |
|
7139 |
- } |
|
7140 |
- } |
|
7141 |
- } |
|
7142 |
-})(lib_call || (lib_call = {})); |
|
7143 |
-/* |
|
7144 |
-This file is part of »bacterio-plankton:call«. |
|
7145 |
- |
|
7146 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7147 |
-<info@greenscale.de> |
|
7148 |
- |
|
7149 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
7150 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7151 |
-the Free Software Foundation, either version 3 of the License, or |
|
7152 |
-(at your option) any later version. |
|
7153 |
- |
|
7154 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
7155 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7156 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7157 |
-GNU Lesser General Public License for more details. |
|
7158 |
- |
|
7159 |
-You should have received a copy of the GNU Lesser General Public License |
|
7160 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
7161 |
- */ |
|
7162 |
-var lib_call; |
|
7163 |
-(function (lib_call) { |
|
7164 |
- /* |
|
7165 |
- The core idea of this library is to provide means for asynchronous program flow. The old-school way to do is, |
|
7166 |
- is to use callbacks. While this approach is simple and easy to understand, it has some disadvantages. As an |
|
7167 |
- attempt to relief and improve this, the promise-system was introduced. In principle it solves most of the |
|
7168 |
- problems found in the callback-approach; however it has some downsides as well: |
|
7169 |
- |
|
7170 |
- - Convolution of multiple principles |
|
7171 |
- Promises unite the ideas of asynchronous program flow and error handling. |
|
7172 |
- |
|
7173 |
- - Instant execution |
|
7174 |
- Creating a promise results in the instant execution of the given executor prodecure. While this might be |
|
7175 |
- convenient in some cases, it can be quite disturbing and counter-intuitive in others. |
|
7176 |
- |
|
7177 |
- - Broken typing |
|
7178 |
- The Promise system doesn't distinguish between an appending "then" (i.e. passing a function, which returns a |
|
7179 |
- new promise) and a closing "then" (i.e. passing a function, which has no return value). On top of that it |
|
7180 |
- allows returning simple values in an appending "then", which results in an implicit call of the executors |
|
7181 |
- "resolve"-function. The price for these "pragmatic" features is that the whole system can't be typed well. |
|
7182 |
- And even though JavaScript is not a strictly typed language, it was a quite questionable decision to design |
|
7183 |
- the promise system in a way, which breaks typing from the start. |
|
7184 |
- |
|
7185 |
- The deferral-system forseeks to solve these issues while retaining the advantages of the promise-system. |
|
7186 |
- */ |
|
7187 |
- /** |
|
7188 |
- * @author fenris |
|
7189 |
- * @desc activates the deferral and handles its output according to a given procedure |
|
7190 |
- * @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument |
|
7191 |
- */ |
|
7192 |
- function deferral_use(deferral, input, procedure) { |
|
7193 |
- deferral.representation(input).then(value => { |
|
7194 |
- procedure(value); |
|
7195 |
- }, reason => { |
|
7196 |
- throw reason; |
|
7197 |
- }); |
|
7198 |
- } |
|
7199 |
- lib_call.deferral_use = deferral_use; |
|
7200 |
- /** |
|
7201 |
- * @author fenris |
|
7202 |
- * @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject") |
|
7203 |
- */ |
|
7204 |
- function deferral_make(handler) { |
|
7205 |
- return ({ |
|
7206 |
- "representation": ((input) => (new Promise((resolve, reject) => { |
|
7207 |
- handler(input, resolve); |
|
7208 |
- }))) |
|
7209 |
- }); |
|
7210 |
- } |
|
7211 |
- lib_call.deferral_make = deferral_make; |
|
7212 |
- /** |
|
7213 |
- * @author fenris |
|
7214 |
- * @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject") |
|
7215 |
- */ |
|
7216 |
- function deferral_wrap(function_) { |
|
7217 |
- return (deferral_make((input, convey) => convey(function_(input)))); |
|
7218 |
- } |
|
7219 |
- lib_call.deferral_wrap = deferral_wrap; |
|
7220 |
- /** |
|
7221 |
- * @author fenris |
|
7222 |
- */ |
|
7223 |
- function deferral_id() { |
|
7224 |
- return (deferral_make((input, convey) => convey(input))); |
|
7225 |
- } |
|
7226 |
- lib_call.deferral_id = deferral_id; |
|
7227 |
- /** |
|
7228 |
- * @author fenris |
|
7229 |
- */ |
|
7230 |
- function deferral_const(value) { |
|
7231 |
- return (deferral_make((input, convey) => convey(value))); |
|
7232 |
- } |
|
7233 |
- lib_call.deferral_const = deferral_const; |
|
7234 |
- /** |
|
7235 |
- * @author fenris |
|
7236 |
- */ |
|
7237 |
- function deferral_delay(output, delay) { |
|
7238 |
- return (deferral_make((input, convey) => { |
|
7239 |
- setTimeout(() => convey(output), delay); |
|
7240 |
- })); |
|
7241 |
- } |
|
7242 |
- lib_call.deferral_delay = deferral_delay; |
|
7243 |
- /** |
|
7244 |
- * @author fenris |
|
7245 |
- * @desc connects two deferrals to form a new one; the output of the first is taken as input for the second |
|
7246 |
- * (similar to "Promise.then" when passing a function which returns a new promise) |
|
7247 |
- * @param {type_deferral<type_value1>} first a simple deferral |
|
7248 |
- * @param {(value1 : type_value1)=>type_deferral<type_value2>} second a function depending from a value returning a deferral |
|
7249 |
- */ |
|
7250 |
- function deferral_compose_serial(first, second) { |
|
7251 |
- return { |
|
7252 |
- "representation": ((input) => first.representation(input).then((between) => second.representation(between))) |
|
7253 |
- }; |
|
7254 |
- } |
|
7255 |
- lib_call.deferral_compose_serial = deferral_compose_serial; |
|
7256 |
- /** |
|
7257 |
- * @author fenris |
|
7258 |
- */ |
|
7259 |
- function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }) { |
|
7260 |
- return (deferral_make((input, convey) => { |
|
7261 |
- let object = { |
|
7262 |
- "left": lib_maybe.make_nothing(), |
|
7263 |
- "right": lib_maybe.make_nothing(), |
|
7264 |
- }; |
|
7265 |
- let finish = function () { |
|
7266 |
- if (lib_maybe.is_just(object.left) |
|
7267 |
- && |
|
7268 |
- lib_maybe.is_just(object.right)) { |
|
7269 |
- let result = { |
|
7270 |
- "left": lib_maybe.cull(object.left), |
|
7271 |
- "right": lib_maybe.cull(object.right), |
|
7272 |
- }; |
|
7273 |
- convey(result); |
|
7274 |
- } |
|
7275 |
- else { |
|
7276 |
- // do nothing |
|
7277 |
- } |
|
7278 |
- }; |
|
7279 |
- deferral_use(deferral_left, input, output_left => { |
|
7280 |
- object.left = lib_maybe.make_just(output_left); |
|
7281 |
- finish(); |
|
7282 |
- }); |
|
7283 |
- deferral_use(deferral_right, input, output_right => { |
|
7284 |
- object.right = lib_maybe.make_just(output_right); |
|
7285 |
- finish(); |
|
7286 |
- }); |
|
7287 |
- })); |
|
7288 |
- } |
|
7289 |
- lib_call.deferral_compose_parallel = deferral_compose_parallel; |
|
7290 |
- /** |
|
7291 |
- * @author fenris |
|
7292 |
- * @desc repeatedly applied serial composition |
|
7293 |
- */ |
|
7294 |
- function deferral_chain(members) { |
|
7295 |
- return (members.reduce( |
|
7296 |
- // (result, current) => deferral_compose_serial<type_value, type_value, type_value>(result, current), |
|
7297 |
- deferral_compose_serial, deferral_id())); |
|
7298 |
- } |
|
7299 |
- lib_call.deferral_chain = deferral_chain; |
|
7300 |
- /** |
|
7301 |
- * @author fenris |
|
7302 |
- */ |
|
7303 |
- /* |
|
7304 |
- export function deferral_bunch<type_input, type_output>( |
|
7305 |
- members : {[name : string] : type_deferral<type_input, type_output>} |
|
7306 |
- ) : type_deferral<type_input, {[name : string] : type_output}> { |
|
7307 |
- |
|
7308 |
- } |
|
7309 |
- */ |
|
7310 |
-})(lib_call || (lib_call = {})); |
|
7311 |
-/* |
|
7312 |
-This file is part of »bacterio-plankton:call«. |
|
7313 |
- |
|
7314 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7315 |
-<info@greenscale.de> |
|
7316 |
- |
|
7317 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
7318 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7319 |
-the Free Software Foundation, either version 3 of the License, or |
|
7320 |
-(at your option) any later version. |
|
7321 |
- |
|
7322 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
7323 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7324 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7325 |
-GNU Lesser General Public License for more details. |
|
7326 |
- |
|
7327 |
-You should have received a copy of the GNU Lesser General Public License |
|
7328 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
7329 |
- */ |
|
7330 |
-var lib_call; |
|
7331 |
-(function (lib_call) { |
|
7332 |
- /** |
|
7333 |
- * @author fenris |
|
7334 |
- */ |
|
7335 |
- class class_deferral { |
|
7336 |
- /** |
|
7337 |
- * @author fenris |
|
7338 |
- */ |
|
7339 |
- constructor(subject) { |
|
7340 |
- this.subject = subject; |
|
7341 |
- } |
|
7342 |
- /** |
|
7343 |
- * @author fenris |
|
7344 |
- */ |
|
7345 |
- static _cram(subject) { |
|
7346 |
- return (new class_deferral(subject)); |
|
7347 |
- } |
|
7348 |
- /** |
|
7349 |
- * @author fenris |
|
7350 |
- */ |
|
7351 |
- static _tear(instance) { |
|
7352 |
- return instance.subject; |
|
7353 |
- } |
|
7354 |
- /** |
|
7355 |
- * @author fenris |
|
7356 |
- */ |
|
7357 |
- static make(handler) { |
|
7358 |
- return (class_deferral._cram(lib_call.deferral_make(handler))); |
|
7359 |
- } |
|
7360 |
- /** |
|
7361 |
- * @author fenris |
|
7362 |
- */ |
|
7363 |
- use(input, procedure) { |
|
7364 |
- return (lib_call.deferral_use(class_deferral._tear(this), input, procedure)); |
|
7365 |
- } |
|
7366 |
- /** |
|
7367 |
- * @author fenris |
|
7368 |
- */ |
|
7369 |
- compose_serial(second) { |
|
7370 |
- return (class_deferral._cram(lib_call.deferral_compose_serial(class_deferral._tear(this), class_deferral._tear(second)))); |
|
7371 |
- } |
|
7372 |
- /** |
|
7373 |
- * @author fenris |
|
7374 |
- */ |
|
7375 |
- static chain(members) { |
|
7376 |
- return (class_deferral._cram(lib_call.deferral_chain(members.map(member => class_deferral._tear(member))))); |
|
7377 |
- } |
|
7378 |
- /** |
|
7379 |
- * @author fenris |
|
7380 |
- */ |
|
7381 |
- static wrap(function_) { |
|
7382 |
- return (class_deferral._cram(lib_call.deferral_wrap(function_))); |
|
7383 |
- } |
|
7384 |
- /** |
|
7385 |
- * @author fenris |
|
7386 |
- */ |
|
7387 |
- static const_(value) { |
|
7388 |
- return (class_deferral._cram(lib_call.deferral_const(value))); |
|
7389 |
- } |
|
7390 |
- /** |
|
7391 |
- * @author fenris |
|
7392 |
- */ |
|
7393 |
- static delay(output, delay) { |
|
7394 |
- return (class_deferral._cram(lib_call.deferral_delay(output, delay))); |
|
7395 |
- } |
|
7396 |
- } |
|
7397 |
- lib_call.class_deferral = class_deferral; |
|
7398 |
-})(lib_call || (lib_call = {})); |
|
7399 |
-/* |
|
7400 |
-This file is part of »bacterio-plankton:call«. |
|
7401 |
- |
|
7402 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7403 |
-<info@greenscale.de> |
|
7404 |
- |
|
7405 |
-»bacterio-plankton:call« is free software: you can redistribute it and/or modify |
|
7406 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7407 |
-the Free Software Foundation, either version 3 of the License, or |
|
7408 |
-(at your option) any later version. |
|
7409 |
- |
|
7410 |
-»bacterio-plankton:call« is distributed in the hope that it will be useful, |
|
7411 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7412 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7413 |
-GNU Lesser General Public License for more details. |
|
7414 |
- |
|
7415 |
-You should have received a copy of the GNU Lesser General Public License |
|
7416 |
-along with »bacterio-plankton:call«. If not, see <http://www.gnu.org/licenses/>. |
|
7417 |
- */ |
|
7418 |
-var lib_call; |
|
7419 |
-(function (lib_call) { |
|
7420 |
- /** |
|
7421 |
- * @author fenris |
|
7422 |
- */ |
|
7423 |
- function timeout(function_, delay) { |
|
7424 |
- return ( |
|
7425 |
- /*window.*/ setTimeout(function_, delay)); |
|
7426 |
- } |
|
7427 |
- lib_call.timeout = timeout; |
|
7428 |
- /** |
|
7429 |
- * @desc a definition for a value being "defined" |
|
7430 |
- * @author neuc |
|
7431 |
- */ |
|
7432 |
- function is_def(obj, null_is_valid = false) { |
|
7433 |
- return (!((typeof (obj) === "undefined") |
|
7434 |
- || |
|
7435 |
- (!null_is_valid && (obj === null)))); |
|
7436 |
- } |
|
7437 |
- lib_call.is_def = is_def; |
|
7438 |
- /** |
|
7439 |
- * @desc returns the value if set and, when a type is specified, if the type is correct, if not return default_value |
|
7440 |
- * @author neuc |
|
7441 |
- */ |
|
7442 |
- function def_val(value, default_value, type = null, null_is_valid = false) { |
|
7443 |
- if (is_def(value, null_is_valid) |
|
7444 |
- && |
|
7445 |
- (is_def(type) |
|
7446 |
- ? ((typeof value === type) |
|
7447 |
- || |
|
7448 |
- ((value === null) |
|
7449 |
- && |
|
7450 |
- null_is_valid)) |
|
7451 |
- : true)) { |
|
7452 |
- return value; |
|
7453 |
- } |
|
7454 |
- else { |
|
7455 |
- return default_value; |
|
7456 |
- } |
|
7457 |
- } |
|
7458 |
- lib_call.def_val = def_val; |
|
7459 |
- ; |
|
7460 |
- /** |
|
7461 |
- * @desc just the empty function; useful for some callbacks etc. |
|
7462 |
- * @author fenris |
|
7463 |
- */ |
|
7464 |
- function nothing() { |
|
7465 |
- } |
|
7466 |
- lib_call.nothing = nothing; |
|
7467 |
- /** |
|
7468 |
- * @desc outputs |
|
7469 |
- * @author fenris |
|
7470 |
- */ |
|
7471 |
- function output(...args) { |
|
7472 |
- lib_log.info.apply(lib_log, args); |
|
7473 |
- } |
|
7474 |
- lib_call.output = output; |
|
7475 |
- /** |
|
7476 |
- * @desc converts the "arguments"-map into an array |
|
7477 |
- * @param {Object} args |
|
7478 |
- * @author fenris |
|
7479 |
- */ |
|
7480 |
- function args2list(args) { |
|
7481 |
- return Object.keys(args).map(key => args[key]); |
|
7482 |
- } |
|
7483 |
- lib_call.args2list = args2list; |
|
7484 |
- /** |
|
7485 |
- * @desc provides the call for an attribute of a class as a regular function |
|
7486 |
- * @param {string} name the name of the attribute |
|
7487 |
- * @return {*} |
|
7488 |
- * @author fenris |
|
7489 |
- */ |
|
7490 |
- function attribute(name) { |
|
7491 |
- return ((object) => object[name]); |
|
7492 |
- } |
|
7493 |
- lib_call.attribute = attribute; |
|
7494 |
- /** |
|
7495 |
- * @desc provides a method of a class as a regular function |
|
7496 |
- * @param {string} name the name of the method |
|
7497 |
- * @return {function} |
|
7498 |
- * @author fenris |
|
7499 |
- */ |
|
7500 |
- function method(name) { |
|
7501 |
- return (function (object) { return object[name].apply(object, args2list(arguments).slice(1)); }); |
|
7502 |
- } |
|
7503 |
- lib_call.method = method; |
|
7504 |
- /** |
|
7505 |
- * @author fenris |
|
7506 |
- */ |
|
7507 |
- function distinguish(unival, handlers, fallback = null) { |
|
7508 |
- if (unival.kind in handlers) { |
|
7509 |
- let handler = handlers[unival.kind]; |
|
7510 |
- return handler(unival.data); |
|
7511 |
- } |
|
7512 |
- else { |
|
7513 |
- let message = ("unhandled kind '" + unival.kind + "'"); |
|
7514 |
- if (fallback !== null) { |
|
7515 |
- console.warn(message); |
|
7516 |
- return fallback(unival); |
|
7517 |
- } |
|
7518 |
- else { |
|
7519 |
- throw (new Error(message)); |
|
7520 |
- } |
|
7521 |
- } |
|
7522 |
- } |
|
7523 |
- lib_call.distinguish = distinguish; |
|
7524 |
-})(lib_call || (lib_call = {})); |
|
7525 |
-/* |
|
7526 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7527 |
- |
|
7528 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7529 |
-<info@greenscale.de> |
|
7530 |
- |
|
7531 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7532 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7533 |
-the Free Software Foundation, either version 3 of the License, or |
|
7534 |
-(at your option) any later version. |
|
7535 |
- |
|
7536 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7537 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7538 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7539 |
-GNU Lesser General Public License for more details. |
|
7540 |
- |
|
7541 |
-You should have received a copy of the GNU Lesser General Public License |
|
7542 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7543 |
- */ |
|
7544 |
-var lib_comm; |
|
7545 |
-(function (lib_comm) { |
|
7546 |
- /** |
|
7547 |
- * @author fenris |
|
7548 |
- */ |
|
7549 |
- lib_trait.define("comm-client", { |
|
7550 |
- "state": null, |
|
7551 |
- "message_in": null, |
|
7552 |
- "message_out": null |
|
7553 |
- }, { |
|
7554 |
- "setup": { |
|
7555 |
- "shape": { |
|
7556 |
- "name": "function", |
|
7557 |
- "parameters": { |
|
7558 |
- "shape_input": { |
|
7559 |
- "name": "variable", |
|
7560 |
- "parameters": { |
|
7561 |
- "name": "state" |
|
7562 |
- } |
|
7563 |
- }, |
|
7564 |
- "shape_output": { |
|
7565 |
- "name": "promise", |
|
7566 |
- "parameters": { |
|
7567 |
- "shape_result": { |
|
7568 |
- "name": "variable", |
|
7569 |
- "parameters": { |
|
7570 |
- "name": "state" |
|
7571 |
- } |
|
7572 |
- }, |
|
7573 |
- "shape_reason": { |
|
7574 |
- "name": "any" |
|
7575 |
- } |
|
7576 |
- } |
|
7577 |
- } |
|
7578 |
- } |
|
7579 |
- } |
|
7580 |
- }, |
|
7581 |
- "send": { |
|
7582 |
- "shape": { |
|
7583 |
- "name": "function", |
|
7584 |
- "parameters": { |
|
7585 |
- "shape_input": { |
|
7586 |
- "name": "variable", |
|
7587 |
- "parameters": { |
|
7588 |
- "name": "state" |
|
7589 |
- } |
|
7590 |
- }, |
|
7591 |
- "shape_output": { |
|
7592 |
- "name": "function", |
|
7593 |
- "parameters": { |
|
7594 |
- "shape_input": { |
|
7595 |
- "name": "variable", |
|
7596 |
- "parameters": { |
|
7597 |
- "name": "message_out" |
|
7598 |
- } |
|
7599 |
- }, |
|
7600 |
- "shape_output": { |
|
7601 |
- "name": "promise", |
|
7602 |
- "parameters": { |
|
7603 |
- "shape_result": { |
|
7604 |
- "name": "variable", |
|
7605 |
- "parameters": { |
|
7606 |
- "name": "message_in" |
|
7607 |
- } |
|
7608 |
- }, |
|
7609 |
- "shape_reason": { |
|
7610 |
- "name": "any" |
|
7611 |
- } |
|
7612 |
- } |
|
7613 |
- } |
|
7614 |
- } |
|
7615 |
- } |
|
7616 |
- } |
|
7617 |
- } |
|
7618 |
- } |
|
7619 |
- }); |
|
7620 |
-})(lib_comm || (lib_comm = {})); |
|
7621 |
-/* |
|
7622 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7623 |
- |
|
7624 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7625 |
-<info@greenscale.de> |
|
7626 |
- |
|
7627 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7628 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7629 |
-the Free Software Foundation, either version 3 of the License, or |
|
7630 |
-(at your option) any later version. |
|
7631 |
- |
|
7632 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7633 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7634 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7635 |
-GNU Lesser General Public License for more details. |
|
7636 |
- |
|
7637 |
-You should have received a copy of the GNU Lesser General Public License |
|
7638 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7639 |
- */ |
|
7640 |
-/* |
|
7641 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7642 |
- |
|
7643 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7644 |
-<info@greenscale.de> |
|
7645 |
- |
|
7646 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7647 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7648 |
-the Free Software Foundation, either version 3 of the License, or |
|
7649 |
-(at your option) any later version. |
|
7650 |
- |
|
7651 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7652 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7653 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7654 |
-GNU Lesser General Public License for more details. |
|
7655 |
- |
|
7656 |
-You should have received a copy of the GNU Lesser General Public License |
|
7657 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7658 |
- */ |
|
7659 |
-var lib_comm; |
|
7660 |
-(function (lib_comm) { |
|
7661 |
- /** |
|
7662 |
- * @author fenris |
|
7663 |
- */ |
|
7664 |
- lib_comm.default_parameters_client_http = { |
|
7665 |
- "protocol": "http", |
|
7666 |
- "host": null, |
|
7667 |
- "port": null, |
|
7668 |
- "path": null, |
|
7669 |
- "omit_protocol": false, |
|
7670 |
- "content_type": "plain/text; charset=utf-8", |
|
7671 |
- "with_credentials": false, |
|
7672 |
- }; |
|
7673 |
-})(lib_comm || (lib_comm = {})); |
|
7674 |
-/* |
|
7675 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7676 |
- |
|
7677 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7678 |
-<info@greenscale.de> |
|
7679 |
- |
|
7680 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7681 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7682 |
-the Free Software Foundation, either version 3 of the License, or |
|
7683 |
-(at your option) any later version. |
|
7684 |
- |
|
7685 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7686 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7687 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7688 |
-GNU Lesser General Public License for more details. |
|
7689 |
- |
|
7690 |
-You should have received a copy of the GNU Lesser General Public License |
|
7691 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7692 |
- */ |
|
7693 |
-var lib_comm; |
|
7694 |
-(function (lib_comm) { |
|
7695 |
- /** |
|
7696 |
- * @author fenris |
|
7697 |
- */ |
|
7698 |
- function client_http_construct(parameters = {}, method = "POST", headers = {}) { |
|
7699 |
- return { |
|
7700 |
- "parameters": lib_object.patched(lib_comm.default_parameters_client_http, parameters), |
|
7701 |
- "method": method.toLowerCase(), |
|
7702 |
- "headers": headers, |
|
7703 |
- }; |
|
7704 |
- } |
|
7705 |
- lib_comm.client_http_construct = client_http_construct; |
|
7706 |
- /** |
|
7707 |
- * @author fenris |
|
7708 |
- */ |
|
7709 |
- function client_http_setup(subject) { |
|
7710 |
- return (lib_call.promise_resolve(undefined)); |
|
7711 |
- } |
|
7712 |
- lib_comm.client_http_setup = client_http_setup; |
|
7713 |
- /** |
|
7714 |
- * @author fenris |
|
7715 |
- */ |
|
7716 |
- function client_http_send(subject, message) { |
|
7717 |
- return (lib_call.promise_make((resolve, reject) => { |
|
7718 |
- if ((subject.method === "get") && (message !== null)) { |
|
7719 |
- let message_ = "can not send data via GET"; |
|
7720 |
- reject(new Error(message_)); |
|
7721 |
- } |
|
7722 |
- else { |
|
7723 |
- let request = new XMLHttpRequest(); |
|
7724 |
- let url = lib_string.make_url({ |
|
7725 |
- "protocol": (subject.parameters.omit_protocol ? null : subject.parameters.protocol), |
|
7726 |
- "host": subject.parameters.host, |
|
7727 |
- "port": subject.parameters.port, |
|
7728 |
- "path": subject.parameters.path, |
|
7729 |
- }); |
|
7730 |
- request.open(subject.method.toUpperCase(), url, true); |
|
7731 |
- lib_object.to_array(subject.headers).forEach(({ "key": key, "value": value }) => { |
|
7732 |
- request.setRequestHeader(key, value); |
|
7733 |
- }); |
|
7734 |
- request.setRequestHeader("Content-Type", subject.parameters.content_type); |
|
7735 |
- if (subject.parameters.with_credentials) { |
|
7736 |
- request.withCredentials = true; |
|
7737 |
- } |
|
7738 |
- /* |
|
7739 |
- request.onerror = () => { |
|
7740 |
- debugger; |
|
7741 |
- reject(new Error("unhandled error")); |
|
7742 |
- }; |
|
7743 |
- */ |
|
7744 |
- request.onreadystatechange = () => { |
|
7745 |
- switch (request.readyState) { |
|
7746 |
- case XMLHttpRequest.DONE: { |
|
7747 |
- switch (request.status) { |
|
7748 |
- case 0: { |
|
7749 |
- reject(new Error("XMLHttpRequest failed")); |
|
7750 |
- break; |
|
7751 |
- } |
|
7752 |
- default: { |
|
7753 |
- let answer = { "code": request.status, "text": request.responseText }; |
|
7754 |
- resolve(answer); |
|
7755 |
- break; |
|
7756 |
- } |
|
7757 |
- } |
|
7758 |
- break; |
|
7759 |
- } |
|
7760 |
- default: { |
|
7761 |
- // console.warn(`unhandled readyState ${request.readyState}`); |
|
7762 |
- break; |
|
7763 |
- } |
|
7764 |
- } |
|
7765 |
- }; |
|
7766 |
- request.send(message); |
|
7767 |
- } |
|
7768 |
- })); |
|
7769 |
- } |
|
7770 |
- lib_comm.client_http_send = client_http_send; |
|
7771 |
- /** |
|
7772 |
- * @author Martin Springwald <springwald@greenscale.de> |
|
7773 |
- * @author Christian Neubauer <neubauer@greenscale.de> |
|
7774 |
- * @author Christian Fraß <frass@greenscale.de> |
|
7775 |
- */ |
|
7776 |
- function http_get_blob({ "url": url, "mime": type }) { |
|
7777 |
- let request = new XMLHttpRequest(); |
|
7778 |
- return new Promise((resolve, reject) => { |
|
7779 |
- request.open("GET", url, true); |
|
7780 |
- request.responseType = "arraybuffer"; |
|
7781 |
- request.onload = function () { |
|
7782 |
- if (request.status === 200) { |
|
7783 |
- resolve(new Blob([request.response], { "type": type })); |
|
7784 |
- } |
|
7785 |
- else { |
|
7786 |
- reject(new Error("error on blob-load")); |
|
7787 |
- } |
|
7788 |
- }; |
|
7789 |
- request.onerror = function () { |
|
7790 |
- reject(undefined); |
|
7791 |
- }; |
|
7792 |
- request.send(); |
|
7793 |
- }); |
|
7794 |
- } |
|
7795 |
- lib_comm.http_get_blob = http_get_blob; |
|
7796 |
-})(lib_comm || (lib_comm = {})); |
|
7797 |
-/* |
|
7798 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7799 |
- |
|
7800 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7801 |
-<info@greenscale.de> |
|
7802 |
- |
|
7803 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7804 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7805 |
-the Free Software Foundation, either version 3 of the License, or |
|
7806 |
-(at your option) any later version. |
|
7807 |
- |
|
7808 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7809 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7810 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7811 |
-GNU Lesser General Public License for more details. |
|
7812 |
- |
|
7813 |
-You should have received a copy of the GNU Lesser General Public License |
|
7814 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7815 |
- */ |
|
7816 |
-var lib_comm; |
|
7817 |
-(function (lib_comm) { |
|
7818 |
- /** |
|
7819 |
- * @author fenris |
|
7820 |
- */ |
|
7821 |
- lib_trait.attend("comm-client", "http", { |
|
7822 |
- "state": { |
|
7823 |
- "name": "any" |
|
7824 |
- }, |
|
7825 |
- "message_in": { |
|
7826 |
- "name": "string" |
|
7827 |
- }, |
|
7828 |
- "message_out": { |
|
7829 |
- "name": "any" // type_response_http |
|
7830 |
- } |
|
7831 |
- }, { |
|
7832 |
- "setup": () => (state) => { |
|
7833 |
- return lib_comm.client_http_setup(state).then(_ => lib_call.promise_resolve(state)); |
|
7834 |
- }, |
|
7835 |
- "send": () => (state) => (message) => { |
|
7836 |
- return lib_comm.client_http_send(state, message); |
|
7837 |
- } |
|
7838 |
- }); |
|
7839 |
-})(lib_comm || (lib_comm = {})); |
|
7840 |
-/* |
|
7841 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7842 |
- |
|
7843 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7844 |
-<info@greenscale.de> |
|
7845 |
- |
|
7846 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7847 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7848 |
-the Free Software Foundation, either version 3 of the License, or |
|
7849 |
-(at your option) any later version. |
|
7850 |
- |
|
7851 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7852 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7853 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7854 |
-GNU Lesser General Public License for more details. |
|
7855 |
- |
|
7856 |
-You should have received a copy of the GNU Lesser General Public License |
|
7857 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7858 |
- */ |
|
7859 |
-var lib_comm; |
|
7860 |
-(function (lib_comm) { |
|
7861 |
- /** |
|
7862 |
- * @author fenris |
|
7863 |
- */ |
|
7864 |
- class class_client_http { |
|
7865 |
- /** |
|
7866 |
- * @author fenris |
|
7867 |
- */ |
|
7868 |
- constructor(parameters = lib_comm.default_parameters_client_http, method = "POST", headers = {}) { |
|
7869 |
- this.subject = lib_comm.client_http_construct(parameters, method, headers); |
|
7870 |
- } |
|
7871 |
- /** |
|
7872 |
- * @author fenris |
|
7873 |
- * @implementation |
|
7874 |
- */ |
|
7875 |
- setup() { |
|
7876 |
- return lib_comm.client_http_setup(this.subject); |
|
7877 |
- } |
|
7878 |
- /** |
|
7879 |
- * @author fenris |
|
7880 |
- * @implementation |
|
7881 |
- */ |
|
7882 |
- send(message) { |
|
7883 |
- return lib_comm.client_http_send(this.subject, message); |
|
7884 |
- } |
|
7885 |
- } |
|
7886 |
- lib_comm.class_client_http = class_client_http; |
|
7887 |
-})(lib_comm || (lib_comm = {})); |
|
7888 |
-/* |
|
7889 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7890 |
- |
|
7891 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7892 |
-<info@greenscale.de> |
|
7893 |
- |
|
7894 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7895 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7896 |
-the Free Software Foundation, either version 3 of the License, or |
|
7897 |
-(at your option) any later version. |
|
7898 |
- |
|
7899 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7900 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7901 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7902 |
-GNU Lesser General Public License for more details. |
|
7903 |
- |
|
7904 |
-You should have received a copy of the GNU Lesser General Public License |
|
7905 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7906 |
- */ |
|
7907 |
-var lib_comm; |
|
7908 |
-(function (lib_comm) { |
|
7909 |
- /** |
|
7910 |
- * @author fenris |
|
7911 |
- */ |
|
7912 |
- class class_client_mhttp { |
|
7913 |
- /** |
|
7914 |
- * @author fenris |
|
7915 |
- */ |
|
7916 |
- constructor(parameters = lib_comm.default_parameters_client_http) { |
|
7917 |
- this.core = new lib_comm.class_client_http(parameters); |
|
7918 |
- } |
|
7919 |
- /** |
|
7920 |
- * @author fenris |
|
7921 |
- * @implementation |
|
7922 |
- */ |
|
7923 |
- setup() { |
|
7924 |
- return this.core.setup(); |
|
7925 |
- } |
|
7926 |
- /** |
|
7927 |
- * @author fenris |
|
7928 |
- * @implementation |
|
7929 |
- */ |
|
7930 |
- send(message) { |
|
7931 |
- return (this.core.send(message) |
|
7932 |
- .then((answer) => { |
|
7933 |
- switch (answer.code) { |
|
7934 |
- case 200: { |
|
7935 |
- return lib_call.promise_resolve(answer.text /*.toString()*/); |
|
7936 |
- break; |
|
7937 |
- } |
|
7938 |
- default: { |
|
7939 |
- return lib_call.promise_reject(new Error(`XMLHttpRequest failed; status was ${answer.code.toFixed(0)}`)); |
|
7940 |
- break; |
|
7941 |
- } |
|
7942 |
- } |
|
7943 |
- })); |
|
7944 |
- } |
|
7945 |
- } |
|
7946 |
- lib_comm.class_client_mhttp = class_client_mhttp; |
|
7947 |
-})(lib_comm || (lib_comm = {})); |
|
7948 |
-/* |
|
7949 |
-This file is part of »bacterio-plankton:comm-client«. |
|
7950 |
- |
|
7951 |
-Copyright 2016-2018 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' |
|
7952 |
-<info@greenscale.de> |
|
7953 |
- |
|
7954 |
-»bacterio-plankton:comm-client« is free software: you can redistribute it and/or modify |
|
7955 |
-it under the terms of the GNU Lesser General Public License as published by |
|
7956 |
-the Free Software Foundation, either version 3 of the License, or |
|
7957 |
-(at your option) any later version. |
|
7958 |
- |
|
7959 |
-»bacterio-plankton:comm-client« is distributed in the hope that it will be useful, |
|
7960 |
-but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7961 |
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7962 |
-GNU Lesser General Public License for more details. |
|
7963 |
- |
|
7964 |
-You should have received a copy of the GNU Lesser General Public License |
|
7965 |
-along with »bacterio-plankton:comm-client«. If not, see <http://www.gnu.org/licenses/>. |
|
7966 |
- */ |
|
7967 |
-var lib_comm; |
|
7968 |
-(function (lib_comm) { |
|
7969 |
- /** |
|
7970 |
- * @desc wrapper for string-based clients |
|
7971 |
- * @author fenris |
|
7972 |
- */ |
|
7973 |
- class class_client_complex { |
|
7974 |
- /** |
|
7975 |
- * @author fenris |
|
7976 |
- */ |
|
7977 |
- constructor(core, code = new lib_code.class_code_pair(new lib_code.class_code_json(), new lib_code.class_code_uri())) { |
|
7978 |
- this.core = core; |
|
7979 |
- this.code = code; |
|
7980 |
- } |
|
7981 |
- /** |
|
7982 |
- * @author fenris |
|
7983 |
- * @implementation |
|
7984 |
- */ |
|
7985 |
- setup() { |
|
7986 |
- return this.core.setup(); |
|
7987 |
- } |
|
7988 |
- /** |
|
7989 |
- * @author fenris |
|
7990 |
- * @implementation |
|
7991 |
- */ |
|
7992 |
- send(message) { |
|
7993 |
- const message_out_raw = this.code.encode(message); |
|
7994 |
- return (this.core.send(message_out_raw) |
|
7995 |
- .then((message_in_raw) => { |
|
7996 |
- const message_in = this.code.decode(message_in_raw); |
|
7997 |
- return lib_call.promise_resolve(message_in); |
|
7998 |
- })); |
|
7999 |
- } |
|
8000 |
- } |
|
8001 |
- lib_comm.class_client_complex = class_client_complex; |
|
8002 |
-})(lib_comm || (lib_comm = {})); |
|
8003 |
- |
|
8004 |
-async function api_query |
|
8005 |
-( |
|
8006 |
- action_name, |
|
8007 |
- input |
|
8008 |
-) |
|
8009 |
-{ |
|
8010 |
- const client = lib_comm.client_http_construct |
|
8011 |
- ( |
|
8012 |
- { |
|
8013 |
- "protocol": "http", |
|
8014 |
- "host": "localhost", |
|
8015 |
- "port": 7777, |
|
8016 |
- "path": "/foo/bar", |
|
8017 |
- } |
|
8018 |
- ); |
|
8019 |
- const message = JSON.stringify |
|
8020 |
- ( |
|
8021 |
- { |
|
8022 |
- "action": action_name, |
|
8023 |
- "input": input, |
|
8024 |
- } |
|
8025 |
- ); |
|
8026 |
- const answer = await lib_comm.client_http_send(client, message); |
|
8027 |
- if (! (answer.code === 200)) |
|
8028 |
- { |
|
8029 |
- return Promise.reject("server side error"); |
|
8030 |
- } |
|
8031 |
- else |
|
8032 |
- { |
|
8033 |
- const output = JSON.parse(answer.text); |
|
8034 |
- return Promise.resolve(output); |
|
8035 |
- } |
|
8036 |
-} |
|
8037 |
- |
|
8038 |
- |
|
8039 |
-/** |
|
8040 |
- */ |
|
8041 |
-function main |
|
8042 |
-( |
|
8043 |
-) |
|
8044 |
-{ |
|
8045 |
- document.querySelector("button").addEventListener |
|
8046 |
- ( |
|
8047 |
- "click", |
|
8048 |
- async function () |
|
8049 |
- { |
|
8050 |
- const language_from = document.querySelector("select[name=language_from]").value; |
|
8051 |
- const language_to = document.querySelector("select[name=language_to]").value; |
|
8052 |
- const token = document.querySelector("input[name=token]").value; |
|
8053 |
- const result = await api_query |
|
8054 |
- ( |
|
8055 |
- "translate", |
|
8056 |
- { |
|
8057 |
- "language_from": language_from, |
|
8058 |
- "language_to": language_to, |
|
8059 |
- "token": token, |
|
8060 |
- } |
|
8061 |
- ); |
|
8062 |
- const dom_ul = document.querySelector("#result"); |
|
8063 |
- dom_ul.textContent = ""; |
|
8064 |
- for (const entry of result) |
|
8065 |
- { |
|
8066 |
- let dom_li = document.createElement("li"); |
|
8067 |
- dom_li.textContent = (`[${entry.language_from}] ${entry.value_from} ~ [${entry.language_to}] ${entry.value_to}`); |
|
8068 |
- dom_ul.appendChild(dom_li); |
|
8069 |
- } |
|
8070 |
- } |
|
8071 |
- ); |
|
8072 |
-} |
|
8073 |
- |
|
8074 |
- |
|
8075 |
-document.addEventListener("DOMContentLoaded", function (event) {main();}); |
|
8076 |
- |
... | ... |
@@ -39,14 +39,54 @@ function main |
39 | 39 |
( |
40 | 40 |
) |
41 | 41 |
{ |
42 |
- document.querySelector("button").addEventListener |
|
42 |
+ // tabify |
|
43 |
+ { |
|
44 |
+ for (let dom_tab of document.querySelectorAll(".tab")) |
|
45 |
+ { |
|
46 |
+ for (let dom_tab_select of dom_tab.querySelectorAll(".tab-select li")) |
|
47 |
+ { |
|
48 |
+ dom_tab_select.addEventListener |
|
49 |
+ ( |
|
50 |
+ "click", |
|
51 |
+ (event) => |
|
52 |
+ { |
|
53 |
+ const tab_name = dom_tab_select.getAttribute("rel"); |
|
54 |
+ dom_tab.setAttribute("rel", tab_name); |
|
55 |
+ } |
|
56 |
+ ); |
|
57 |
+ } |
|
58 |
+ } |
|
59 |
+ } |
|
60 |
+ // show |
|
61 |
+ { |
|
62 |
+ document.querySelector(".tab-content[rel=\"show\"] button").addEventListener |
|
63 |
+ ( |
|
64 |
+ "click", |
|
65 |
+ async function () |
|
66 |
+ { |
|
67 |
+ const concept_id = document.querySelector(".tab-content[rel=\"show\"] inupt").value; |
|
68 |
+ const result = await api_query |
|
69 |
+ ( |
|
70 |
+ "show", |
|
71 |
+ { |
|
72 |
+ "concept_id": concept_id, |
|
73 |
+ } |
|
74 |
+ ); |
|
75 |
+ let dom_result = document.querySelector("#show_result") |
|
76 |
+ dom_result.textContent = JSON.stringify(result, undefined, " "); |
|
77 |
+ } |
|
78 |
+ ); |
|
79 |
+ } |
|
80 |
+ // translate |
|
81 |
+ { |
|
82 |
+ document.querySelector(".tab-content[rel=\"translate\"] button").addEventListener |
|
43 | 83 |
( |
44 | 84 |
"click", |
45 | 85 |
async function () |
46 | 86 |
{ |
47 |
- const language_from = document.querySelector("select[name=language_from]").value; |
|
48 |
- const language_to = document.querySelector("select[name=language_to]").value; |
|
49 |
- const token = document.querySelector("input[name=token]").value; |
|
87 |
+ const language_from = document.querySelector(".tab-content[rel=\"translate\"] select[name=language_from]").value; |
|
88 |
+ const language_to = document.querySelector(".tab-content[rel=\"translate\"] select[name=language_to]").value; |
|
89 |
+ const token = document.querySelector(".tab-content[rel=\"translate\"] input[name=token]").value; |
|
50 | 90 |
const result = await api_query |
51 | 91 |
( |
52 | 92 |
"translate", |
... | ... |
@@ -56,7 +96,7 @@ function main |
56 | 96 |
"token": token, |
57 | 97 |
} |
58 | 98 |
); |
59 |
- const dom_ul = document.querySelector("#result"); |
|
99 |
+ const dom_ul = document.querySelector("#translate_result"); |
|
60 | 100 |
dom_ul.textContent = ""; |
61 | 101 |
for (const entry of result) |
62 | 102 |
{ |
... | ... |
@@ -67,6 +107,7 @@ function main |
67 | 107 |
} |
68 | 108 |
); |
69 | 109 |
} |
110 |
+} |
|
70 | 111 |
|
71 | 112 |
|
72 | 113 |
document.addEventListener("DOMContentLoaded", function (event) {main();}); |
... | ... |
@@ -6,6 +6,20 @@ |
6 | 6 |
<script type="text/javascript" src="logic.js"></script> |
7 | 7 |
</head> |
8 | 8 |
<body> |
9 |
+ <div class="tab" rel="show"> |
|
10 |
+ <div class="tab-select"> |
|
11 |
+ <ul> |
|
12 |
+ <li rel="show">show</li> |
|
13 |
+ <li rel="translate">translate</li> |
|
14 |
+ </ul> |
|
15 |
+ </div> |
|
16 |
+ <div class="tab-content" rel="show"> |
|
17 |
+ <input type="number"/> |
|
18 |
+ <button>query</button> |
|
19 |
+ <pre id="show_result"> |
|
20 |
+ </pre> |
|
21 |
+ </div> |
|
22 |
+ <div class="tab-content" rel="translate"> |
|
9 | 23 |
<select name="language_from"> |
10 | 24 |
<option value="_">*</option> |
11 | 25 |
<option value="afr">afr</option> |
... | ... |
@@ -36,8 +50,10 @@ |
36 | 50 |
</select> |
37 | 51 |
<input type="text" name="token"/> |
38 | 52 |
<button>query</button> |
39 |
- <ul id="result"> |
|
53 |
+ <ul id="translate_result"> |
|
40 | 54 |
</ul> |
55 |
+ </div> |
|
56 |
+ </div> |
|
41 | 57 |
</body> |
42 | 58 |
</html> |
43 | 59 |
|
... | ... |
@@ -0,0 +1,32 @@ |
1 |
+$hue: 150; |
|
2 |
+ |
|
3 |
+html |
|
4 |
+{ |
|
5 |
+ background-color: hsl($hue, 0%, 0%); |
|
6 |
+ color: hsl($hue, 100%, 0%); |
|
7 |
+} |
|
8 |
+ |
|
9 |
+body |
|
10 |
+{ |
|
11 |
+ background-color: hsl($hue, 0%, 6.125%); |
|
12 |
+ color: hsl($hue, 0%, 93.875%); |
|
13 |
+} |
|
14 |
+ |
|
15 |
+ |
|
16 |
+.tab-select > ul > li |
|
17 |
+{ |
|
18 |
+ display: inline-block; |
|
19 |
+ margin: 8px; |
|
20 |
+ cursor: pointer; |
|
21 |
+} |
|
22 |
+ |
|
23 |
+.tab[rel="show"] .tab-select li[rel="show"] {border-bottom: 2px solid black;} |
|
24 |
+.tab[rel="show"] .tab-select li[rel="translate"] {border-bottom: none;} |
|
25 |
+.tab[rel="translate"] .tab-select li[rel="show"] {border-bottom: none;} |
|
26 |
+.tab[rel="translate"] .tab-select li[rel="translate"] {border-bottom: 2px solid black;} |
|
27 |
+ |
|
28 |
+.tab[rel="show"] .tab-content[rel="show"] {display: initial;} |
|
29 |
+.tab[rel="show"] .tab-content[rel="translate"] {display: none;} |
|
30 |
+.tab[rel="translate"] .tab-content[rel="show"] {display: none;} |
|
31 |
+.tab[rel="translate"] .tab-content[rel="translate"] {display: initial;} |
|
32 |
+ |
... | ... |
@@ -1,4 +1,5 @@ |
1 |
-# directories |
|
1 |
+## directories |
|
2 |
+ |
|
2 | 3 |
dir_lib := lib |
3 | 4 |
dir_source := source |
4 | 5 |
dir_temp := temp |
... | ... |
@@ -9,8 +12,11 @@ cmd_log := echo "--" |
9 | 12 |
cmd_copy := cp --recursive --update --verbose |
10 | 13 |
cmd_concatenate := cat |
11 | 14 |
cmd_dir_make := mkdir --parents |
15 |
+cmd_sassc := sassc |
|
16 |
+ |
|
12 | 17 |
|
13 | 18 |
## rules |
19 |
+ |
|
14 | 20 |
all: ${dir_build}/index.html ${dir_build}/logic.js ${dir_build}/style.css |
15 | 21 |
.PHONY: all |
16 | 22 |
|
... | ... |
@@ -39,7 +45,7 @@ ${dir_build}/logic.js: ${dir_temp}/plankton.js ${dir_temp}/logic-unlinked.js |
39 | 45 |
@ ${cmd_dir_make} ${dir_build} |
40 | 46 |
@ ${cmd_concatenate} $^ > $@ |
41 | 47 |
|
42 |
-${dir_build}/style.css: ${dir_source}/style.css |
|
48 |
+${dir_build}/style.css: ${dir_source}/style.sass |
|
43 | 49 |
@ ${cmd_log} "style …" |
44 |
- @ ${cmd_concatenate} $^ > $@ |
|
50 |
+ @ ${cmd_concatenate} $^ | ${cmd_sassc} --stdin > $@ |
|
45 | 51 |
|
46 | 52 |