was.js – Diff between revs 41 and 45
?pathlinks?
Rev 41 | Rev 45 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | /*! was.js - v1.0.4 - 2019-08-03 |
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 */ |
184 | /* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject, wasKeyValueGet, wasKeyValueSet */ |
|
185 | module.exports.formats = { |
185 | module.exports.formats = { |
|
186 | csv: { |
186 | csv: { |
|
187 | CSVToArray: wasCSVToArray, |
187 | CSVToArray: wasCSVToArray, |
|
188 | ArrayToCSV: wasArrayToCSV |
188 | ArrayToCSV: wasArrayToCSV |
|
189 | }, |
189 | }, |
|
190 | kvp: { |
190 | kvp: { |
|
191 | KeyValueToObject: wasKeyValueToObject |
191 | KeyValueToObject: wasKeyValueToObject, |
|
- | 192 | KeyValueGet: wasKeyValueGet, |
||
- | 193 | KeyValueSet: wasKeyValueSet |
||
192 | } |
194 | } |
|
193 | }; |
195 | }; |
|
194 | } |
196 | } |
|
195 | |
197 | |
|
196 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
198 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
197 | /*************************************************************************/ |
199 | /*************************************************************************/ |
|
198 | function wasKeyValueToObject(a) { |
200 | function wasKeyValueToObject(a) { |
|
199 | var o = {}; |
201 | var o = {}; |
|
200 | a.reduce(function(a, c, i) { |
202 | a.reduce(function(a, c, i) { |
|
Line 208... | Line 210... | |||
208 | o[c[0]] = c[1]; |
210 | o[c[0]] = c[1]; |
|
209 | }, o); |
211 | }, o); |
|
210 | return o; |
212 | return o; |
|
211 | } |
213 | } |
|
Line -... | Line 214... | |||
- | 214 | |
||
- | 215 | /*************************************************************************/ |
||
- | 216 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
- | 217 | /*************************************************************************/ |
||
- | 218 | function wasKeyValueSet(k, v, data) { |
||
- | 219 | return data.split('&') |
||
- | 220 | .map(c => c.split('=')[0] === k ? `${k}=${v}` : c) |
||
- | 221 | .concat(`${k}=${v}`) |
||
- | 222 | .filter((e,i,s) => s.indexOf(e) === i) |
||
- | 223 | .join('&'); |
||
- | 224 | } |
||
- | 225 | |
||
- | 226 | |
||
- | 227 | /*************************************************************************/ |
||
- | 228 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
- | 229 | /*************************************************************************/ |
||
- | 230 | function wasKeyValueGet(k, data) { |
||
- | 231 | return data.split('&').reduce((a, c) => { |
||
- | 232 | var s = c.split('='); |
||
- | 233 | return s[0] === k ? s[1] : a; |
||
- | 234 | }, ''); |
||
212 | |
235 | }
|
|
213 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
236 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
214 | /*************************************************************************/ |
237 | /*************************************************************************/ |
|
215 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
238 | /* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */ |
|
216 | /*************************************************************************/ |
239 | /*************************************************************************/ |
|
Line 254... | Line 277... | |||
254 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
277 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
|
255 | module.exports.lambda = { |
278 | module.exports.lambda = { |
|
256 | switch: wasSwitch |
279 | switch: wasSwitch |
|
257 | }; |
280 | }; |
|
258 | } |
281 | } |
|
259 | |
282 | |
|
260 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
283 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
261 | /*************************************************************************/ |
284 | /*************************************************************************/ |
|
262 | function wasMapValueToRange(value, xMin, xMax, yMin, yMax) { |
285 | function wasMapValueToRange(value, xMin, xMax, yMin, yMax) { |
|
263 | return yMin + ( |
286 | return yMin + ( |
|
264 | ( yMax - yMin ) * ( value - xMin ) / ( xMax - xMin ) |
287 | ( yMax - yMin ) * ( value - xMin ) / ( xMax - xMin ) |
|
Line 271... | Line 294... | |||
271 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
294 | if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') { |
|
272 | module.exports.mathematics = { |
295 | module.exports.mathematics = { |
|
273 | MapValueToRange: wasMapValueToRange |
296 | MapValueToRange: wasMapValueToRange |
|
274 | }; |
297 | }; |
|
275 | } |
298 | } |
|
276 | |
299 |
|
|
277 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
300 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
278 | /*************************************************************************/ |
301 | /*************************************************************************/ |
|
279 | function wasHexToRGB(hex) { |
302 | function wasHexToRGB(hex) { |
|
280 | 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; |
|
281 | hex = hex.replace( |
304 | hex = hex.replace( |