Comparing version 1.0.0 to 3.0.0
26
index.js
'use strict'; | ||
module.exports = (initialForKey) => { | ||
const o = {}; | ||
module.exports = (definition) => { | ||
const keys = definition ? Object.keys(definition) : []; | ||
for (const key of Object.keys(initialForKey)) { | ||
const initial = initialForKey[key]; | ||
const map = new WeakMap(); | ||
o[key] = (subkey) => { | ||
if (!map.get(subkey)) map.set(subkey, initial()); | ||
return map.get(subkey); | ||
}; | ||
} | ||
const initialize = () => keys.reduce((o, key) => { | ||
const a = definition[key]; | ||
o[key] = typeof a === 'function' ? a() : a; | ||
return o; | ||
}, {}); | ||
const map = new WeakMap(); | ||
return o; | ||
return (o) => { | ||
const state = map.get(o); | ||
if (state) return state; | ||
const created = initialize(); | ||
map.set(o, created); | ||
return created; | ||
}; | ||
}; |
{ | ||
"name": "bursary", | ||
"version": "1.0.0", | ||
"version": "3.0.0", | ||
"description": "Store private data.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
699
17