was.js – Diff between revs 45 and 47
?pathlinks?
Rev 45 | Rev 47 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | /*! was.js - v1.0.5 - 2019-12-01
|
1 | /*! was.js - v1.0.5 - 2019-12-01 |
|
2 | * http://grimore.org
|
2 | * http://grimore.org |
|
3 | * Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */ |
3 | * Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */ |
|
4 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
4 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
5 | /*************************************************************************/ |
5 | /*************************************************************************/ |
|
6 | function wasProduct(a, b) { |
6 | function wasProduct(a, b) { |
|
7 | var m = Math.max(a.length, b.length); |
7 | var m = Math.max(a.length, b.length); |
|
8 | var o = {}; |
8 | var o = {}; |
|
Line 119... | Line 119... | |||
119 | stride: wasStride, |
119 | stride: wasStride, |
|
120 | chunk: wasChunk, |
120 | chunk: wasChunk, |
|
121 | equals: wasEquals |
121 | equals: wasEquals |
|
122 | }; |
122 | }; |
|
123 | } |
123 | } |
|
124 | |
124 | |
|
125 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
125 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
126 | /*************************************************************************/ |
126 | /*************************************************************************/ |
|
127 | function wasCSVToArray(csv) { |
127 | function wasCSVToArray(csv) { |
|
128 | var l = []; |
128 | var l = []; |
|
129 | var s = []; |
129 | var s = []; |
|
Line 175... | Line 175... | |||
175 | } |
175 | } |
|
176 | csv[i] = cell; |
176 | csv[i] = cell; |
|
177 | } |
177 | } |
|
178 | return csv.join(); |
178 | return csv.join(); |
|
179 | } |
179 | } |
|
180 | |
180 | |
|
181 | /* Node.JS package export. */ |
181 | /* Node.JS package export. */ |
|
182 | /*************************************************************************/ |
182 | /*************************************************************************/ |
|
183 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
183 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
|
184 | /* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject, wasKeyValueGet, wasKeyValueSet */ |
184 | /* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject, wasKeyValueGet, wasKeyValueSet */ |
|
185 | module.exports.formats = { |
185 | module.exports.formats = { |
|
Line 192... | Line 192... | |||
192 | KeyValueGet: wasKeyValueGet, |
192 | KeyValueGet: wasKeyValueGet, |
|
193 | KeyValueSet: wasKeyValueSet |
193 | KeyValueSet: wasKeyValueSet |
|
194 | } |
194 | } |
|
195 | }; |
195 | }; |
|
196 | } |
196 | } |
|
197 | |
197 | |
|
198 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
198 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
199 | /*************************************************************************/ |
199 | /*************************************************************************/ |
|
200 | function wasKeyValueToObject(a) { |
200 | function wasKeyValueToObject(a) { |
|
201 | var o = {}; |
201 | var o = {}; |
|
202 | a.reduce(function(a, c, i) { |
202 | a.reduce(function(a, c, i) { |
|
Line 230... | Line 230... | |||
230 | function wasKeyValueGet(k, data) { |
230 | function wasKeyValueGet(k, data) { |
|
231 | return data.split('&').reduce((a, c) => { |
231 | return data.split('&').reduce((a, c) => { |
|
232 | var s = c.split('='); |
232 | var s = c.split('='); |
|
233 | return s[0] === k ? s[1] : a; |
233 | return s[0] === k ? s[1] : a; |
|
234 | }, ''); |
234 | }, ''); |
|
235 | }
|
235 | } |
|
236 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
236 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
237 | /*************************************************************************/ |
237 | /*************************************************************************/ |
|
238 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
238 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
|
239 | /*************************************************************************/ |
239 | /*************************************************************************/ |
|
240 | function wasSwitch() { |
240 | function wasSwitch(q, d, ...c) { |
|
241 | if(arguments.length % 2 !== 0) { |
241 | if(c.length % 2 !== 0) { |
|
242 | throw "Pairs of predicates expected for cases"; |
242 | throw "Pairs of predicates expected for cases"; |
|
243 | } |
243 | } |
|
244 | |
244 | |
|
245 | (Array.isArray(arguments[0]) ? arguments[0] : [ arguments[0] ]).forEach(function(s) { |
245 | (Array.isArray(q) ? q : [ q ]).forEach((s) => { |
|
246 | var m = false; |
246 | var m = false; |
|
247 | for(var i = 2; i < arguments.length; i += 2) { |
247 | for(var i = 0; i < c.length; i += 2) { |
|
248 | if(!arguments[i](s)) { |
248 | if(!c[i](s)) { |
|
249 | continue; |
249 | continue; |
|
250 | } |
250 | } |
|
251 | if(!arguments[i + 1](s)) { |
251 | if(!c[i + 1](s)) { |
|
252 | continue; |
252 | continue; |
|
253 | } |
253 | } |
|
254 | m = true; |
254 | m = true; |
|
255 | } |
255 | } |
|
256 | |
256 | |
|
257 | if(!m) { |
257 | if(!m) { |
|
258 | arguments[1](s); |
258 | d(s); |
|
259 | } |
259 | } |
|
260 | }); |
260 | }); |
|
261 | } |
261 | } |
|
262 | if (!Array.prototype.switch) { |
262 | if (!Array.prototype.switch) { |
|
263 | Array.prototype.switch = function() { |
263 | Array.prototype.switch = function() { |
|
Line 277... | Line 277... | |||
277 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
277 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
|
278 | module.exports.lambda = { |
278 | module.exports.lambda = { |
|
279 | switch: wasSwitch |
279 | switch: wasSwitch |
|
280 | }; |
280 | }; |
|
281 | } |
281 | } |
|
282 | |
282 | |
|
283 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
283 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
284 | /*************************************************************************/ |
284 | /*************************************************************************/ |
|
285 | function wasMapValueToRange(value, xMin, xMax, yMin, yMax) { |
285 | function wasMapValueToRange(value, xMin, xMax, yMin, yMax) { |
|
286 | return yMin + ( |
286 | return yMin + ( |
|
287 | ( yMax - yMin ) * ( value - xMin ) / ( xMax - xMin ) |
287 | ( yMax - yMin ) * ( value - xMin ) / ( xMax - xMin ) |
|
Line 294... | Line 294... | |||
294 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
294 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
|
295 | module.exports.mathematics = { |
295 | module.exports.mathematics = { |
|
296 | MapValueToRange: wasMapValueToRange |
296 | MapValueToRange: wasMapValueToRange |
|
297 | }; |
297 | }; |
|
298 | } |
298 | } |
|
299 |
|
299 | |
|
300 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
300 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
301 | /*************************************************************************/ |
301 | /*************************************************************************/ |
|
302 | function wasHexToRGB(hex) { |
302 | function wasHexToRGB(hex) { |
|
303 | var shortRegEx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
303 | var shortRegEx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
|
304 | hex = hex.replace( |
304 | hex = hex.replace( |