data-fns
Version:
This library provides utility functions for working with array data that are useful in many contexts, including creative coding. It offers generic functions that perform common operations such as offsetting an array, generating an array based on a callbac
3 lines (2 loc) • 2.64 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var r=function(r,t,e){return t[e(r,t.length)]},t=function(r,t){var e=r%t;return Math.abs(e>=0?e:t+e)},e=[0,1,1,1,1,0,0,0],n=function(r,t){return r-t},o=function(r,t,e){if(void 0===e&&(e=0),r<0||t<0)throw new Error("Inputs must be positive integers");for(var o=[],a=t>r?r:t,i=0;i<a;i++){var u=Math.floor(i*r/a);o.push((u+e)%r)}return o.sort(n)};function a(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}exports.binaryToIndices=function(r){for(var t=[],e=0;e<r.length;e++)1===r[e]&&t.push(e);return t},exports.cellularAutomata=function(r,n,o){void 0===n&&(n=e),void 0===o&&(o=t);for(var a=new Array(r.length),i=r.length,u=0;u<i;u++){var s=r[o(u-1,i)],c=r[u],f=r[o(u+1,i)];a[u]=n[4*s+2*c+f]}return a},exports.cyclic=t,exports.euclideanSequencer=o,exports.euclideanSilences=function(r,t,e){void 0===e&&(e=0);for(var n=o(r,t,e),a=[],i=0;i<r;i++)n.includes(i)||a.push(i);return a},exports.generateSequence=function(r,t,e){if(r<0)throw new Error("Iterations must be a positive number");if(0===r)return[];for(var n=[t],o=t,a=1;a<r;a++)o=e(o),n.push(o);return n},exports.getItem=r,exports.indicesToBinary=function(r,t){for(var e,n=Array(t).fill(0),o=function(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,t){if(r){if("string"==typeof r)return a(r,void 0);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(r,void 0):void 0}}(r))){e&&(r=e);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(r);!(e=o()).done;){var i=e.value;i>=0&&i<t&&(n[i]=1)}return n},exports.mapAt=function(r,t,e){if(t>r.length||t<0)throw new Error("Index out of range");var n=r[t];if(e(n)===n)return r;var o=r.slice();return o[t]=e(r[t]),o},exports.modulo=function(r,t){return Math.abs(r)%Math.abs(t)*(Math.sign(r)*Math.sign(t))},exports.palindrome=function(r,t){var e=t;if(1===e)return 0;var n=r%(2*e-2),o=n>=0?n:2*e-2+n;return o<e?Math.abs(o):2*e-o-2},exports.patternChunks=function(e,n){for(var o=[],a=[].concat(e),i=0;a.length>0;)o.push(a.splice(0,r(i,n,t))),i++;return o},exports.times=function(r,t){for(var e=[],n=0;n<r;n++)e.push(t(n));return e};
//# sourceMappingURL=data-fns.cjs.production.min.js.map