/trunk/dist/was.js |
@@ -0,0 +1,125 @@ |
/*! was - v1.0.0 - 2017-05-28 |
* http://grimore.org |
* Copyright (c) 2017 Wizardry and Steamworks <office@grimore.org>; Licensed GPL-3.0 */ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
if (!Array.prototype.product) { |
Array.prototype.product = function(b) { |
var a = this; |
return $.map( |
new Array(Math.max(this.length, a.length)), |
function(e, i) { |
var o = {}; |
o[a[i]] = b[i]; |
return o; |
}); |
}; |
} |
$.extend({ |
product: function(a, b) { |
return $.map( |
new Array(Math.max(this.length, a.length)), |
function(e, i) { |
var o = {}; |
o[a[i]] = b[i]; |
return o; |
}); |
} |
}); |
|
/*************************************************************************/ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
if (!Array.prototype.stride) { |
Array.prototype.stride = function(s) { |
return this.filter(function(e, i) { |
return i % s === 0; |
}); |
}; |
} |
$.extend({ |
stride: function(a, s) { |
return a.filter(function(e, i) { |
return i % s === 0; |
}); |
} |
}); |
|
/*************************************************************************/ |
/* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
/*************************************************************************/ |
if (!Array.prototype.chunk) { |
Array.prototype.chunk = function(n) { |
if (!this.length) { |
return []; |
} |
return [this.slice(0, n)] |
.concat(this.slice(n).chunk(n)); |
}; |
} |
$.extend({ |
chunk: function(a, n) { |
if (!a.length) { |
return []; |
} |
return [a.slice(0, n)] |
.concat(a.slice(n).chunk(n)); |
} |
}); |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
function wasCSVToArray(csv) { |
var l = []; |
var s = []; |
var m = ""; |
|
do { |
var a = csv.charAt(0); |
csv = csv.slice(1, csv.length); |
if(a === ",") { |
if(s[s.length-1] !== '"') { |
l.push(m); |
m = ""; |
continue; |
} |
m += a; |
continue; |
} |
if(a === '"' && csv.charAt(0) === a) { |
m += a; |
csv = csv.slice(1, csv.length); |
continue; |
} |
if(a === '"') { |
if(s[s.length-1] !== a) { |
s.push(a); |
continue; |
} |
s.pop(); |
continue; |
} |
m += a; |
} while(csv !== ""); |
|
l.push(m); |
|
return l; |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
function wasArrayToCSV(a) { |
var csv = []; |
for(var i=0; i<a.length; ++i) { |
var cell = a[i].toString().replace('"', '""'); |
if(/"\s,\r\n/.test(cell)) { |
csv[i] = '"' + cell + '"'; |
continue; |
} |
csv[i] = cell; |
} |
return csv.join(); |
} |
/trunk/dist/was.min.js |
@@ -0,0 +1,4 @@ |
/*! was - v1.0.0 - 2017-05-28 |
* http://grimore.org |
* Copyright (c) 2017 Wizardry and Steamworks <office@grimore.org>; Licensed GPL-3.0 */ |
function wasCSVToArray(a){var b=[],c=[],d="";do{var e=a.charAt(0);if(a=a.slice(1,a.length),","!==e)if('"'!==e||a.charAt(0)!==e)if('"'!==e)d+=e;else{if(c[c.length-1]!==e){c.push(e);continue}c.pop()}else d+=e,a=a.slice(1,a.length);else{if('"'!==c[c.length-1]){b.push(d),d="";continue}d+=e}}while(""!==a);return b.push(d),b}function wasArrayToCSV(a){for(var b=[],c=0;c<a.length;++c){var d=a[c].toString().replace('"','""');/"\s,\r\n/.test(d)?b[c]='"'+d+'"':b[c]=d}return b.join()}Array.prototype.product||(Array.prototype.product=function(a){var b=this;return $.map(new Array(Math.max(this.length,b.length)),function(c,d){var e={};return e[b[d]]=a[d],e})}),$.extend({product:function(a,b){return $.map(new Array(Math.max(this.length,a.length)),function(c,d){var e={};return e[a[d]]=b[d],e})}}),Array.prototype.stride||(Array.prototype.stride=function(a){return this.filter(function(b,c){return c%a==0})}),$.extend({stride:function(a,b){return a.filter(function(a,c){return c%b==0})}}),Array.prototype.chunk||(Array.prototype.chunk=function(a){return this.length?[this.slice(0,a)].concat(this.slice(a).chunk(a)):[]}),$.extend({chunk:function(a,b){return a.length?[a.slice(0,b)].concat(a.slice(b).chunk(b)):[]}}); |