was.js

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 44  →  ?path2? @ 45
/trunk/dist/was.js
@@ -1,6 +1,6 @@
/*! was.js - v1.0.4 - 2019-08-03
* http://grimore.org
* Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */
/*! was.js - v1.0.5 - 2019-12-01
* http://grimore.org
* Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasProduct(a, b) {
@@ -121,7 +121,7 @@
equals: wasEquals
};
}
 
 
/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasCSVToArray(csv) {
@@ -177,11 +177,11 @@
}
return csv.join();
}
 
 
/* Node.JS package export. */
/*************************************************************************/
if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
/* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject */
/* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject, wasKeyValueGet, wasKeyValueSet */
module.exports.formats = {
csv: {
CSVToArray: wasCSVToArray,
@@ -188,11 +188,13 @@
ArrayToCSV: wasArrayToCSV
},
kvp: {
KeyValueToObject: wasKeyValueToObject
KeyValueToObject: wasKeyValueToObject,
KeyValueGet: wasKeyValueGet,
KeyValueSet: wasKeyValueSet
}
};
}
 
 
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasKeyValueToObject(a) {
@@ -210,8 +212,29 @@
return o;
}
 
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasKeyValueSet(k, v, data) {
return data.split('&')
.map(c => c.split('=')[0] === k ? `${k}=${v}` : c)
.concat(`${k}=${v}`)
.filter((e,i,s) => s.indexOf(e) === i)
.join('&');
}
 
 
/*************************************************************************/
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasKeyValueGet(k, data) {
return data.split('&').reduce((a, c) => {
var s = c.split('=');
return s[0] === k ? s[1] : a;
}, '');
}
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
/* fuss/lambda_calculus/functional_programming/aggregators @ grimore.org */
/*************************************************************************/
function wasSwitch() {
@@ -256,7 +279,7 @@
switch: wasSwitch
};
}
 
 
/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasMapValueToRange(value, xMin, xMax, yMin, yMax) {
@@ -273,7 +296,7 @@
MapValueToRange: wasMapValueToRange
};
}
 
 
/* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */
/*************************************************************************/
function wasHexToRGB(hex) {
/trunk/dist/was.min.js
@@ -1,5 +1,5 @@
/*! was.js - v1.0.4 - 2019-08-03
/*! was.js - v1.0.5 - 2019-12-01
* http://grimore.org
* Copyright (c) 2019 [object Object]; Licensed GPL-3.0 */
 
function wasProduct(e,t){for(var r=Math.max(e.length,t.length),o={},n=0;n<r;++n)o[e[n]]=t[n];return o}function wasStride(e,t){return e.filter(function(e,r){return r%t==0})}function wasChunk(e,t){return e.length?[e.slice(0,t)].concat(e.slice(t).wasChunk(t)):[]}function wasEquals(e,t){if(!t)return!1;if(e.length!==t.length)return!1;for(var r=0,o=e.length;r<o;r++)if(e[r]instanceof Array&&t[r]instanceof Array){if(!e[r].equals(t[r]))return!1}else if(e[r]!==t[r])return!1;return!0}function wasCSVToArray(e){var t=[],r=[],o="";do{var n=e.charAt(0);if(e=e.slice(1,e.length),","!==n)if('"'!==n||e.charAt(0)!==n)if('"'!==n)o+=n;else{if(r[r.length-1]!==n){r.push(n);continue}r.pop()}else o+=n,e=e.slice(1,e.length);else{if('"'!==r[r.length-1]){t.push(o),o="";continue}o+=n}}while(""!==e);return t.push(o),t}function wasArrayToCSV(e){for(var t=[],r=0;r<e.length;++r){var o=e[r].toString().replace('"','""');/"\s,\r\n/.test(o)?t[r]='"'+o+'"':t[r]=o}return t.join()}function wasKeyValueToObject(e){var t={};return e.reduce(function(e,t,r){return e[r=Math.floor(r/2)]||(e[r]=[]),e[r].push(t),e},[]).forEach(function(e,r,o){t[e[0]]=e[1]},t),t}function wasSwitch(){if(arguments.length%2!=0)throw"Pairs of predicates expected for cases";(Array.isArray(arguments[0])?arguments[0]:[arguments[0]]).forEach(function(e){for(var t=!1,r=2;r<arguments.length;r+=2)arguments[r](e)&&arguments[r+1](e)&&(t=!0);t||arguments[1](e)})}function wasMapValueToRange(e,t,r,o,n){return o+(n-o)*(e-t)/(r-t)}function wasHexToRGB(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,r,o){return t+t+r+r+o+o});var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null}function wasRGBToHex(e,t,r){return"#"+((1<<24)+(e<<16)+(t<<8)+r).toString(16).slice(1)}Array.prototype.product||(Array.prototype.product=function(e){return wasProduct(this,e)}),"function"==typeof jQuery&&$.extend({product:wasProduct}),Array.prototype.stride||(Array.prototype.stride=function(e){return wasStride(this,e)}),"function"==typeof jQuery&&$.extend({stride:wasStride}),Array.prototype.chunk||(Array.prototype.chunk=function(e,t){return wasChunk(this,t)}),"function"==typeof jQuery&&$.extend({chunk:wasChunk}),Array.prototype.equals||(Array.prototype.equals=function(e,t){return wasEquals(this,t)}),"function"==typeof jQuery&&$.extend({equals:wasEquals}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.collections={product:wasProduct,stride:wasStride,chunk:wasChunk,equals:wasEquals}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.formats={csv:{CSVToArray:wasCSVToArray,ArrayToCSV:wasArrayToCSV},kvp:{KeyValueToObject:wasKeyValueToObject}}),Array.prototype.switch||(Array.prototype.switch=function(){wasSwitch(this,arguments[0],arguments.slice(1))}),"function"==typeof jQuery&&$.extend({switch:wasSwitch}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.lambda={switch:wasSwitch}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.mathematics={MapValueToRange:wasMapValueToRange}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.physics={HexToRGB:wasHexToRGB,RGBToHex:wasRGBToHex});
function wasProduct(e,t){for(var r=Math.max(e.length,t.length),n={},o=0;o<r;++o)n[e[o]]=t[o];return n}function wasStride(e,t){return e.filter(function(e,r){return r%t==0})}function wasChunk(e,t){return e.length?[e.slice(0,t)].concat(e.slice(t).wasChunk(t)):[]}function wasEquals(e,t){if(!t)return!1;if(e.length!==t.length)return!1;for(var r=0,n=e.length;r<n;r++)if(e[r]instanceof Array&&t[r]instanceof Array){if(!e[r].equals(t[r]))return!1}else if(e[r]!==t[r])return!1;return!0}function wasCSVToArray(e){var t=[],r=[],n="";do{var o=e.charAt(0);if(e=e.slice(1,e.length),","!==o)if('"'!==o||e.charAt(0)!==o)if('"'!==o)n+=o;else{if(r[r.length-1]!==o){r.push(o);continue}r.pop()}else n+=o,e=e.slice(1,e.length);else{if('"'!==r[r.length-1]){t.push(n),n="";continue}n+=o}}while(""!==e);return t.push(n),t}function wasArrayToCSV(e){for(var t=[],r=0;r<e.length;++r){var n=e[r].toString().replace('"','""');/"\s,\r\n/.test(n)?t[r]='"'+n+'"':t[r]=n}return t.join()}function wasKeyValueToObject(e){var t={};return e.reduce(function(e,t,r){return e[r=Math.floor(r/2)]||(e[r]=[]),e[r].push(t),e},[]).forEach(function(e,r,n){t[e[0]]=e[1]},t),t}function wasKeyValueSet(e,t,r){return r.split("&").map(r=>r.split("=")[0]===e?`${e}=${t}`:r).concat(`${e}=${t}`).filter((e,t,r)=>r.indexOf(e)===t).join("&")}function wasKeyValueGet(e,t){return t.split("&").reduce((t,r)=>{var n=r.split("=");return n[0]===e?n[1]:t},"")}function wasSwitch(){if(arguments.length%2!=0)throw"Pairs of predicates expected for cases";(Array.isArray(arguments[0])?arguments[0]:[arguments[0]]).forEach(function(e){for(var t=!1,r=2;r<arguments.length;r+=2)arguments[r](e)&&arguments[r+1](e)&&(t=!0);t||arguments[1](e)})}function wasMapValueToRange(e,t,r,n,o){return n+(o-n)*(e-t)/(r-t)}function wasHexToRGB(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,r,n){return t+t+r+r+n+n});var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null}function wasRGBToHex(e,t,r){return"#"+((1<<24)+(e<<16)+(t<<8)+r).toString(16).slice(1)}Array.prototype.product||(Array.prototype.product=function(e){return wasProduct(this,e)}),"function"==typeof jQuery&&$.extend({product:wasProduct}),Array.prototype.stride||(Array.prototype.stride=function(e){return wasStride(this,e)}),"function"==typeof jQuery&&$.extend({stride:wasStride}),Array.prototype.chunk||(Array.prototype.chunk=function(e,t){return wasChunk(this,t)}),"function"==typeof jQuery&&$.extend({chunk:wasChunk}),Array.prototype.equals||(Array.prototype.equals=function(e,t){return wasEquals(this,t)}),"function"==typeof jQuery&&$.extend({equals:wasEquals}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.collections={product:wasProduct,stride:wasStride,chunk:wasChunk,equals:wasEquals}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.formats={csv:{CSVToArray:wasCSVToArray,ArrayToCSV:wasArrayToCSV},kvp:{KeyValueToObject:wasKeyValueToObject,KeyValueGet:wasKeyValueGet,KeyValueSet:wasKeyValueSet}}),Array.prototype.switch||(Array.prototype.switch=function(){wasSwitch(this,arguments[0],arguments.slice(1))}),"function"==typeof jQuery&&$.extend({switch:wasSwitch}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.lambda={switch:wasSwitch}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.mathematics={MapValueToRange:wasMapValueToRange}),"undefined"!=typeof module&&void 0!==module.exports&&(module.exports.physics={HexToRGB:wasHexToRGB,RGBToHex:wasRGBToHex});
/trunk/lib/formats/formats.js
@@ -2,7 +2,7 @@
/* Node.JS package export. */
/*************************************************************************/
if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
/* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject */
/* global wasCSVToArray, wasArrayToCSV, wasKeyValueToObject, wasKeyValueGet, wasKeyValueSet */
module.exports.formats = {
csv: {
CSVToArray: wasCSVToArray,
@@ -9,8 +9,8 @@
ArrayToCSV: wasArrayToCSV
},
kvp: {
KeyValueToObject: wasKeyValueToObject
KeyValueGet: wasKeyValueGet
KeyValueToObject: wasKeyValueToObject,
KeyValueGet: wasKeyValueGet,
KeyValueSet: wasKeyValueSet
}
};
/trunk/lib/formats/kvp/kvp.js
@@ -24,7 +24,7 @@
.map(c => c.split('=')[0] === k ? `${k}=${v}` : c)
.concat(`${k}=${v}`)
.filter((e,i,s) => s.indexOf(e) === i)
.join('&')
.join('&');
}
 
 
@@ -33,7 +33,7 @@
/*************************************************************************/
function wasKeyValueGet(k, data) {
return data.split('&').reduce((a, c) => {
var s = c.split('=')
return s[0] === k ? s[1] : a
}, '')
var s = c.split('=');
return s[0] === k ? s[1] : a;
}, '');
}
/trunk/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "was.js",
"version": "1.0.3",
"version": "1.0.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -1519,7 +1519,6 @@
"version": "0.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"kind-of": "^3.0.2",
"longest": "^1.0.1",
@@ -2290,8 +2289,7 @@
"longest": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"loose-envify": {
"version": "1.2.0",