2021-01-02 03:34:37 +00:00
|
|
|
function Anchor(fasten = {}, mixins = []) {
|
|
|
|
const NAMESPACE = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
|
2021-01-01 23:21:54 +00:00
|
|
|
|
2021-01-02 03:34:37 +00:00
|
|
|
const GLOBAL = window || global || {};
|
2021-01-01 23:21:54 +00:00
|
|
|
|
2021-01-02 03:34:37 +00:00
|
|
|
const register = function register(key, value) {
|
|
|
|
if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
|
|
|
|
return GLOBAL[NAMESPACE][key] = value;
|
2021-01-01 23:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-01-02 03:34:37 +00:00
|
|
|
}.bind(GLOBAL[NAMESPACE]);
|
2021-01-01 23:21:54 +00:00
|
|
|
|
2021-01-02 03:34:37 +00:00
|
|
|
function build(fasten, merges, register) {
|
|
|
|
if (GLOBAL[NAMESPACE]) {
|
2021-01-01 23:21:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-02 03:34:37 +00:00
|
|
|
GLOBAL[NAMESPACE] = fasten;
|
|
|
|
GLOBAL[NAMESPACE]['register'] = register;
|
2021-01-01 23:21:54 +00:00
|
|
|
|
2021-01-02 03:34:37 +00:00
|
|
|
merges.forEach((merge) => Object.assign(GLOBAL[NAMESPACE], merge));
|
2021-01-01 23:21:54 +00:00
|
|
|
|
2021-01-02 03:34:37 +00:00
|
|
|
return GLOBAL[NAMESPACE];
|
2021-01-01 23:21:54 +00:00
|
|
|
}
|
2021-01-02 03:34:37 +00:00
|
|
|
return build(fasten, mixins, register);
|
2021-01-01 23:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Anchor;
|