was.js – Blame information for rev 55
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
55 | office | 1 | /*! was.js - v1.0.8 - 2020-12-09 |
2 | * http://grimore.org |
||
3 | * Copyright (c) 2020 [object Object]; Licensed GPL-3.0 */ |
||
4 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
5 | /*************************************************************************/ |
||
6 | function wasArrayToObject(a) { |
||
7 | var o = {}; |
||
8 | a.reduce(function(a, c, i) { |
||
9 | i = Math.floor(i / 2); |
||
10 | if (!a[i]) { |
||
11 | a[i] = []; |
||
12 | } |
||
13 | a[i].push(c); |
||
14 | return a; |
||
15 | }, []).forEach(function(c, i, a) { |
||
16 | o[c[0]] = c[1]; |
||
17 | }, o); |
||
18 | return o; |
||
19 | } |
||
20 | if (!Array.prototype.toObject) { |
||
21 | Array.prototype.toObject = function() { |
||
22 | return wasArrayToObject(this); |
||
23 | }; |
||
24 | } |
||
25 | // jQuery |
||
26 | if(typeof jQuery === 'function') { |
||
27 | $.extend({ |
||
28 | toObject: wasArrayToObject |
||
29 | }); |
||
30 | } |
||
31 | |||
32 | |||
33 | /*************************************************************************/ |
||
34 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
35 | /*************************************************************************/ |
||
36 | function wasProduct(a, b) { |
||
37 | var m = Math.max(a.length, b.length); |
||
38 | var o = {}; |
||
39 | for(var i = 0; i < m; ++i) {> |
||
40 | < m; ++i) { o[a[i]] = b[i];> |
||
41 | < m; ++i) { }> |
||
42 | < m; ++i) { return o;> |
||
43 | < m; ++i) {}> |
||
44 | < m; ++i) {if (!Array.prototype.product) {> |
||
45 | < m; ++i) { Array.prototype.product = function(b) {> |
||
46 | < m; ++i) { return wasProduct(this, b);> |
||
47 | < m; ++i) { };> |
||
48 | < m; ++i) {}> |
||
49 | < m; ++i) {// jQuery> |
||
50 | < m; ++i) {if(typeof jQuery === 'function') {> |
||
51 | < m; ++i) { $.extend({> |
||
52 | < m; ++i) { product: wasProduct> |
||
53 | < m; ++i) { });> |
||
54 | < m; ++i) {}> |
||
55 | |||
56 | < m; ++i) {/*************************************************************************/> |
||
57 | < m; ++i) {/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
58 | < m; ++i) {/*************************************************************************/> |
||
59 | < m; ++i) {function wasStride(a, s) {> |
||
60 | < m; ++i) { return a.filter(function(e, i) {> |
||
61 | < m; ++i) { return i % s === 0;> |
||
62 | < m; ++i) { });> |
||
63 | < m; ++i) {}> |
||
64 | < m; ++i) {if (!Array.prototype.stride) {> |
||
65 | < m; ++i) { Array.prototype.stride = function(s) {> |
||
66 | < m; ++i) { return wasStride(this, s);> |
||
67 | < m; ++i) { };> |
||
68 | < m; ++i) {}> |
||
69 | < m; ++i) {// jQuery> |
||
70 | < m; ++i) {if(typeof jQuery === 'function') {> |
||
71 | < m; ++i) { $.extend({> |
||
72 | < m; ++i) { stride: wasStride> |
||
73 | < m; ++i) { });> |
||
74 | < m; ++i) {}> |
||
75 | |||
76 | < m; ++i) {// Vanilla JavaScript> |
||
77 | < m; ++i) {function wasChunk(a, n) {> |
||
78 | < m; ++i) { return Array.from(new Array(Math.ceil(a.length/n)), (_,i)=>a.slice(i*n,i*n+n));> |
||
79 | < m; ++i) {}> |
||
80 | < m; ++i) {if (!Array.prototype.chunk) {> |
||
81 | < m; ++i) { Array.prototype.chunk = function(a, n) {> |
||
82 | < m; ++i) { return wasChunk(this, n);> |
||
83 | < m; ++i) { };> |
||
84 | < m; ++i) {}> |
||
85 | < m; ++i) {// jQuery> |
||
86 | < m; ++i) {if(typeof jQuery === 'function') {> |
||
87 | < m; ++i) { $.extend({> |
||
88 | < m; ++i) { chunk: wasChunk> |
||
89 | < m; ++i) { });> |
||
90 | < m; ++i) {}> |
||
91 | |||
92 | < m; ++i) {/*************************************************************************/> |
||
93 | < m; ++i) {/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
94 | < m; ++i) {/*************************************************************************/> |
||
95 | < m; ++i) {/*stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript*/> |
||
96 | < m; ++i) {/*************************************************************************/> |
||
97 | < m; ++i) {// Vanilla JavaScript> |
||
98 | < m; ++i) {function wasEquals(a, b) {> |
||
99 | < m; ++i) { // if the other array is a falsy value, return> |
||
100 | < m; ++i) { if (!b) {> |
||
101 | < m; ++i) { return false;> |
||
102 | < m; ++i) { }> |
||
103 | |||
104 | < m; ++i) { // compare lengths - can save a lot of time > |
||
105 | < m; ++i) { if (a.length !== b.length) {> |
||
106 | < m; ++i) { return false;> |
||
107 | < m; ++i) { }> |
||
108 | |||
109 | < m; ++i) { for (var i = 0, l = a.length; i < l; i++) {> |
||
110 | < m; ++i) { // Check if we have nested arrays> |
||
111 | < m; ++i) { if (a[i] instanceof Array && b[i] instanceof Array) {> |
||
112 | < m; ++i) { // recurse into the nested arrays> |
||
113 | < m; ++i) { if (!a[i].equals(b[i])) {> |
||
114 | < m; ++i) { return false;> |
||
115 | < m; ++i) { }> |
||
116 | < m; ++i) { } else if (a[i] !== b[i]) {> |
||
117 | < m; ++i) { // Warning - two different object instances will never be equal: {x:20} != {x:20}> |
||
118 | < m; ++i) { return false;> |
||
119 | < m; ++i) { }> |
||
120 | < m; ++i) { }> |
||
121 | < m; ++i) { return true;> |
||
122 | < m; ++i) {}> |
||
123 | < m; ++i) {if (!Array.prototype.equals) {> |
||
124 | < m; ++i) { // attach the .equals method to Array's prototype to call it on any array> |
||
125 | < m; ++i) { Array.prototype.equals = function(a, b) {> |
||
126 | < m; ++i) { return wasEquals(this, b);> |
||
127 | < m; ++i) { };> |
||
128 | < m; ++i) {}> |
||
129 | < m; ++i) {// jQuery> |
||
130 | < m; ++i) {if(typeof jQuery === 'function') {> |
||
131 | < m; ++i) { $.extend({> |
||
132 | < m; ++i) { equals: wasEquals> |
||
133 | < m; ++i) { });> |
||
134 | < m; ++i) {}> |
||
135 | |||
136 | < m; ++i) {/*************************************************************************/> |
||
137 | < m; ++i) {/* Node.JS package export. */> |
||
138 | < m; ++i) {/*************************************************************************/> |
||
139 | < m; ++i) {if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {> |
||
140 | < m; ++i) { module.exports.collections = {> |
||
141 | < m; ++i) { product: wasProduct,> |
||
142 | < m; ++i) { stride: wasStride,> |
||
143 | < m; ++i) { chunk: wasChunk,> |
||
144 | < m; ++i) { equals: wasEquals,> |
||
145 | < m; ++i) { toObject: wasArrayToObject> |
||
146 | < m; ++i) { };> |
||
147 | < m; ++i) {}> |
||
148 | |||
149 | < m; ++i) {/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
150 | < m; ++i) {/*************************************************************************/> |
||
151 | < m; ++i) {function wasCSVToArray(csv) {> |
||
152 | < m; ++i) { var l = [];> |
||
153 | < m; ++i) { var s = [];> |
||
154 | < m; ++i) { var m = "";> |
||
155 | |||
156 | < m; ++i) { do {> |
||
157 | < m; ++i) { var a = csv.charAt(0);> |
||
158 | < m; ++i) { csv = csv.slice(1, csv.length);> |
||
159 | < m; ++i) { if(a === ",") {> |
||
160 | < m; ++i) { if(s[s.length-1] !== '"') {> |
||
161 | < m; ++i) { l.push(m);> |
||
162 | < m; ++i) { m = "";> |
||
163 | < m; ++i) { continue;> |
||
164 | < m; ++i) { }> |
||
165 | < m; ++i) { m += a;> |
||
166 | < m; ++i) { continue;> |
||
167 | < m; ++i) { }> |
||
168 | < m; ++i) { if(a === '"' && csv.charAt(0) === a) {> |
||
169 | < m; ++i) { m += a;> |
||
170 | < m; ++i) { csv = csv.slice(1, csv.length);> |
||
171 | < m; ++i) { continue;> |
||
172 | < m; ++i) { }> |
||
173 | < m; ++i) { if(a === '"') {> |
||
174 | < m; ++i) { if(s[s.length-1] !== a) {> |
||
175 | < m; ++i) { s.push(a);> |
||
176 | < m; ++i) { continue;> |
||
177 | < m; ++i) { }> |
||
178 | < m; ++i) { s.pop();> |
||
179 | < m; ++i) { continue;> |
||
180 | < m; ++i) { }> |
||
181 | < m; ++i) { m += a;> |
||
182 | < m; ++i) { } while(csv !== "");> |
||
183 | |||
184 | < m; ++i) { l.push(m);> |
||
185 | |||
186 | < m; ++i) { return l;> |
||
187 | < m; ++i) {}> |
||
188 | |||
189 | < m; ++i) {/*************************************************************************/> |
||
190 | < m; ++i) {/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
191 | < m; ++i) {/*************************************************************************/> |
||
192 | < m; ++i) {function wasArrayToCSV(a) {> |
||
193 | < m; ++i) { var csv = [];> |
||
194 | < m; ++i) { for(var i=0; i<a.length; ++i) {> |
||
195 | < m; ++i) { var cell = a[i].toString().replace('"', '""');> |
||
196 | < m; ++i) { if(/"\s,\r\n/.test(cell)) {> |
||
197 | < m; ++i) { csv[i] = '"' + cell + '"';> |
||
198 | < m; ++i) { continue;> |
||
199 | < m; ++i) { }> |
||
200 | < m; ++i) { csv[i] = cell;> |
||
201 | < m; ++i) { }> |
||
202 | < m; ++i) { return csv.join();> |
||
203 | < m; ++i) {}> |
||
204 | |||
205 | < m; ++i) {/* Node.JS package export. */> |
||
206 | < m; ++i) {/*************************************************************************/> |
||
207 | < m; ++i) {if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {> |
||
208 | < m; ++i) { /* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject, wasKeyValueGet, wasKeyValueSet */> |
||
209 | < m; ++i) { module.exports.formats = {> |
||
210 | < m; ++i) { csv: {> |
||
211 | < m; ++i) { CSVToArray: wasCSVToArray,> |
||
212 | < m; ++i) { ArrayToCSV: wasArrayToCSV> |
||
213 | < m; ++i) { },> |
||
214 | < m; ++i) { kvp: {> |
||
215 | < m; ++i) { KeyValueToObject: wasKeyValueToObject,> |
||
216 | < m; ++i) { KeyValueGet: wasKeyValueGet,> |
||
217 | < m; ++i) { KeyValueSet: wasKeyValueSet> |
||
218 | < m; ++i) { }> |
||
219 | < m; ++i) { };> |
||
220 | < m; ++i) {}> |
||
221 | |||
222 | < m; ++i) {/* Copyright (C) 2020 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
223 | < m; ++i) {/*************************************************************************/> |
||
224 | < m; ++i) {function wasKeyValueToObject(data) {> |
||
225 | < m; ++i) { var result = {};> |
||
226 | < m; ++i) { data.split('&').forEach((kvp) => {> |
||
227 | < m; ++i) { var kv = kvp.split('=')> |
||
228 | < m; ++i) { .filter((kv) => > |
||
229 | < m; ++i) { kv[0] !== 'undefined' && kv[1] !== 'undefined'); > |
||
230 | < m; ++i) { result[kv[0]] = kv[1];> |
||
231 | |||
232 | < m; ++i) { });> |
||
233 | < m; ++i) { return result;> |
||
234 | < m; ++i) {}> |
||
235 | |||
236 | < m; ++i) {/*************************************************************************/> |
||
237 | < m; ++i) {/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
238 | < m; ++i) {/*************************************************************************/> |
||
239 | < m; ++i) {function wasKeyValueSet(k, v, data) {> |
||
240 | < m; ++i) { return data.split('&')> |
||
241 | < m; ++i) { .map(c => c.split('=')[0] === k ? `${k}=${v}` : c)> |
||
242 | < m; ++i) { .concat(`${k}=${v}`)> |
||
243 | < m; ++i) { .filter((e,i,s) => s.indexOf(e) === i)> |
||
244 | < m; ++i) { .join('&');> |
||
245 | < m; ++i) {}> |
||
246 | |||
247 | |||
248 | < m; ++i) {/*************************************************************************/> |
||
249 | < m; ++i) {/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
250 | < m; ++i) {/*************************************************************************/> |
||
251 | < m; ++i) {function wasKeyValueGet(k, data) {> |
||
252 | < m; ++i) { return data.split('&').reduce((a, c) => {> |
||
253 | < m; ++i) { var s = c.split('=');> |
||
254 | < m; ++i) { return s[0] === k ? s[1] : a;> |
||
255 | < m; ++i) { }, '');> |
||
256 | < m; ++i) {}> |
||
257 | < m; ++i) {/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
258 | < m; ++i) {/*************************************************************************/> |
||
259 | < m; ++i) {/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */> |
||
260 | < m; ++i) {/*************************************************************************/> |
||
261 | < m; ++i) {function wasSwitch(q, d, ...c) {> |
||
262 | < m; ++i) { if(c.length % 2 !== 0) {> |
||
263 | < m; ++i) { throw "Pairs of predicates expected for cases";> |
||
264 | < m; ++i) { }> |
||
265 | |||
266 | < m; ++i) { (Array.isArray(q) ? q : [ q ]).forEach((s) => {> |
||
267 | < m; ++i) { var m = false;> |
||
268 | < m; ++i) { for(var i = 0; i < c.length; i += 2) {> |
||
269 | < m; ++i) { if(!c[i](s)) {> |
||
270 | < m; ++i) { continue;> |
||
271 | < m; ++i) { }> |
||
272 | < m; ++i) { if(!c[i + 1](s)) {> |
||
273 | < m; ++i) { continue;> |
||
274 | < m; ++i) { }> |
||
275 | < m; ++i) { m = true;> |
||
276 | < m; ++i) { }> |
||
277 | |||
278 | < m; ++i) { if(!m) {> |
||
279 | < m; ++i) { d(s);> |
||
280 | < m; ++i) { }> |
||
281 | < m; ++i) { });> |
||
282 | < m; ++i) {}> |
||
283 | < m; ++i) {if (!Array.prototype.switch) {> |
||
284 | < m; ++i) { Array.prototype.switch = function() {> |
||
285 | < m; ++i) { wasSwitch(this, arguments[0], arguments.slice(1));> |
||
286 | < m; ++i) { };> |
||
287 | < m; ++i) {}> |
||
288 | < m; ++i) {// jQuery> |
||
289 | < m; ++i) {if(typeof jQuery === 'function') {> |
||
290 | < m; ++i) { $.extend({> |
||
291 | < m; ++i) { switch: wasSwitch> |
||
292 | < m; ++i) { });> |
||
293 | < m; ++i) {}> |
||
294 | |||
295 | < m; ++i) {/*************************************************************************/> |
||
296 | < m; ++i) {/* Node.JS package export. */> |
||
297 | < m; ++i) {/*************************************************************************/> |
||
298 | < m; ++i) {if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {> |
||
299 | < m; ++i) { module.exports.lambda = {> |
||
300 | < m; ++i) { switch: wasSwitch> |
||
301 | < m; ++i) { };> |
||
302 | < m; ++i) {}> |
||
303 | |||
304 | < m; ++i) {/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
305 | < m; ++i) {/*************************************************************************/> |
||
306 | < m; ++i) {function wasMapValueToRange(value, xMin, xMax, yMin, yMax) {> |
||
307 | < m; ++i) { return yMin + (> |
||
308 | < m; ++i) { ( yMax - yMin ) * ( value - xMin ) / ( xMax - xMin )> |
||
309 | < m; ++i) { );> |
||
310 | < m; ++i) {}> |
||
311 | |||
312 | < m; ++i) {/*************************************************************************/> |
||
313 | < m; ++i) {/* Node.JS package export. */> |
||
314 | < m; ++i) {/*************************************************************************/> |
||
315 | < m; ++i) {if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {> |
||
316 | < m; ++i) { module.exports.mathematics = {> |
||
317 | < m; ++i) { MapValueToRange: wasMapValueToRange> |
||
318 | < m; ++i) { };> |
||
319 | < m; ++i) {}> |
||
320 | |||
321 | < m; ++i) {/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
322 | < m; ++i) {/*************************************************************************/> |
||
323 | < m; ++i) {function wasHexToRGB(hex) {> |
||
324 | < m; ++i) { var shortRegEx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;> |
||
325 | < m; ++i) { hex = hex.replace(> |
||
326 | < m; ++i) { shortRegEx,> |
||
327 | < m; ++i) { function(m, r, g, b) {> |
||
328 | < m; ++i) { return r + r + g + g + b + b;> |
||
329 | < m; ++i) { }> |
||
330 | < m; ++i) { );> |
||
331 | |||
332 | < m; ++i) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);> |
||
333 | < m; ++i) { return result ? {> |
||
334 | < m; ++i) { r: parseInt(result[1], 16),> |
||
335 | < m; ++i) { g: parseInt(result[2], 16),> |
||
336 | < m; ++i) { b: parseInt(result[3], 16)> |
||
337 | < m; ++i) { } : null;> |
||
338 | < m; ++i) {}> |
||
339 | |||
340 | < m; ++i) {/*************************************************************************/> |
||
341 | < m; ++i) {/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */> |
||
342 | < m; ++i) {/*************************************************************************/> |
||
343 | < m; ++i) {function wasRGBToHex(r, g, b) {> |
||
344 | < m; ++i) { return "#" + (> |
||
345 | < m; ++i) { (1 << 24) +><>> |
||
346 | < m; ++i) {<< 24) +< 24) + (r << 16) +><>><>> |
||
347 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) + (g << 8) +><>><>><>> |
||
348 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) + b><>><>><>> |
||
349 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) + ).toString(16).slice(1);><>><>><>> |
||
350 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) +}><>><>><>> |
||
351 | |||
352 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) +/*************************************************************************/><>><>><>> |
||
353 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) +/* Node.JS package export. */><>><>><>> |
||
354 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) +/*************************************************************************/><>><>><>> |
||
355 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) +if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {><>><>><>> |
||
356 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) + module.exports.physics = {><>><>><>> |
||
357 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) + HexToRGB: wasHexToRGB,><>><>><>> |
||
358 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) + RGBToHex: wasRGBToHex><>><>><>> |
||
359 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) + };><>><>><>> |
||
360 | < m; ++i) {<< 24) +< 24) +<< 16) +< 16) +<< 8) +< 8) +}><>><>><>> |