Skip to content

Commit

Permalink
feat(iterator): allow iteration over "other" keys
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 16, 2018
1 parent 3a3e029 commit 3c53323
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions index.js
Expand Up @@ -37,24 +37,35 @@ class FiggyPudding {
})
return obj
}
* entries () {
* entries (_matcher) {
for (let key of Object.keys(this.__specs)) {
yield [key, this.get(key)]
}
const matcher = this.__opts.other || _matcher
if (matcher) {
for (let p of this.__providers) {
const iter = p.entries ? p.entries(matcher) : Object.entries(p)
for (let [key, val] of iter) {
if (matcher(key)) {
yield [key, val]
}
}
}
}
}
* [Symbol.iterator] () {
for (let key of Object.keys(this.__specs)) {
yield [key, this.get(key)]
}
}
* keys () {
for (let key of Object.keys(this.__specs)) {
for (let [key] of this.entries()) {
yield key
}
}
* values () {
for (let key of Object.keys(this.__specs)) {
yield this.get(key)
for (let [, value] of this.entries()) {
yield value
}
}
concat (...moreConfig) {
Expand All @@ -74,10 +85,16 @@ try {
}
} catch (e) {}

function BadKeyError (key) {
throw Object.assign(new Error(
`invalid config key requested: ${key}`
), {code: 'EBADKEY'})
}

function pudGet (pud, key, validate) {
let spec = pud.__specs[key]
if (validate && !spec && (!pud.__opts.other || !pud.__opts.other(key))) {
throw new Error(`invalid config key requested: ${key}`)
BadKeyError(key)
} else {
if (!spec) { spec = {} }
let ret
Expand Down

0 comments on commit 3c53323

Please sign in to comment.