(function(exports) {
"use strict";
/* default namespace used for functions is `window.icky.namespaces.functions` */
const DEFAULT_NAMESPACE = "functions";
/* each function named via `gnf()` is assigned a unique incremented name */
let id = 0;
/* initialise icky */
let icky = {
namespaces: {
[DEFAULT_NAMESPACE]: {}
}
};
/* globallyNameFunction gives the function a name and keeps a reference to it on window.icky */
const globallyNameFunction = (namespace, fn) => {
var name = `fn_${id++}`;
if (icky.namespaces[namespace]) {
icky.namespaces[namespace][name] = fn;
return `icky.namespaces.${namespace}.${name}`;
} else {
let errMsg = `icky.js error: namespace '${namespace}' does not exist`;
console.error(errMsg);
throw new Error(errMsg);
}
};