diff --git a/node_modules/figgy-pudding/CHANGELOG.md b/node_modules/figgy-pudding/CHANGELOG.md index e8989c840390a..b3bf92d1509e8 100644 --- a/node_modules/figgy-pudding/CHANGELOG.md +++ b/node_modules/figgy-pudding/CHANGELOG.md @@ -2,6 +2,56 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [3.4.1](https://github.com/zkat/figgy-pudding/compare/v3.4.0...v3.4.1) (2018-08-16) + + +### Bug Fixes + +* **forEach:** get forEach to behave like a normal forEach ([c064755](https://github.com/zkat/figgy-pudding/commit/c064755)) +* **has:** get `in` keyword working right ([fafc5a8](https://github.com/zkat/figgy-pudding/commit/fafc5a8)) +* **iteration:** fix and test iteration of opts.other keys ([7a76217](https://github.com/zkat/figgy-pudding/commit/7a76217)) +* **iteration:** use proper args for forEach/toJSON ([974e879](https://github.com/zkat/figgy-pudding/commit/974e879)) +* **proxy:** make sure proxy corner-cases work ok ([8c66e45](https://github.com/zkat/figgy-pudding/commit/8c66e45)) +* **set:** fix and test the exceptions to writing ([206793b](https://github.com/zkat/figgy-pudding/commit/206793b)) + + + + +# [3.4.0](https://github.com/zkat/figgy-pudding/compare/v3.3.0...v3.4.0) (2018-08-16) + + +### Features + +* **iterator:** allow iteration over "other" keys ([3c53323](https://github.com/zkat/figgy-pudding/commit/3c53323)) + + + + +# [3.3.0](https://github.com/zkat/figgy-pudding/compare/v3.2.1...v3.3.0) (2018-08-16) + + +### Bug Fixes + +* **props:** allow symbols to pass through ([97b3464](https://github.com/zkat/figgy-pudding/commit/97b3464)) + + +### Features + +* **pudding:** iteration and serialization support ([0aaa50d](https://github.com/zkat/figgy-pudding/commit/0aaa50d)) + + + + +## [3.2.1](https://github.com/zkat/figgy-pudding/compare/v3.2.0...v3.2.1) (2018-08-15) + + +### Bug Fixes + +* **aliases:** make reverse aliases work correctly ([76a255e](https://github.com/zkat/figgy-pudding/commit/76a255e)) + + + # [3.2.0](https://github.com/zkat/figgy-pudding/compare/v3.1.0...v3.2.0) (2018-07-26) diff --git a/node_modules/figgy-pudding/index.js b/node_modules/figgy-pudding/index.js index 0afd41f8040df..7991e69fc832f 100644 --- a/node_modules/figgy-pudding/index.js +++ b/node_modules/figgy-pudding/index.js @@ -3,8 +3,22 @@ class FiggyPudding { constructor (specs, opts, providers) { this.__specs = specs || {} - this.__opts = opts || (() => false) - this.__providers = reverse((providers || []).filter( + Object.keys(this.__specs).forEach(alias => { + if (typeof this.__specs[alias] === 'string') { + const key = this.__specs[alias] + const realSpec = this.__specs[key] + if (realSpec) { + const aliasArr = realSpec.aliases || [] + aliasArr.push(alias, key) + realSpec.aliases = [...(new Set(aliasArr))] + this.__specs[alias] = realSpec + } else { + throw new Error(`Alias refers to invalid key: ${key} -> ${alias}`) + } + } + }) + this.__opts = opts || {} + this.__providers = reverse((providers).filter( x => x != null && typeof x === 'object' )) this.__isFiggyPudding = true @@ -12,6 +26,52 @@ class FiggyPudding { get (key) { return pudGet(this, key, true) } + get [Symbol.toStringTag] () { return 'FiggyPudding' } + forEach (fn, thisArg = this) { + for (let [key, value] of this.entries()) { + fn.call(thisArg, value, key, this) + } + } + toJSON () { + const obj = {} + this.forEach((val, key) => { + obj[key] = val + }) + return obj + } + * entries (_matcher) { + for (let key of Object.keys(this.__specs)) { + yield [key, this.get(key)] + } + const matcher = _matcher || this.__opts.other + if (matcher) { + const seen = new Set() + 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) && !seen.has(key)) { + seen.add(key) + yield [key, val] + } + } + } + } + } + * [Symbol.iterator] () { + for (let [key, value] of this.entries()) { + yield [key, value] + } + } + * keys () { + for (let [key] of this.entries()) { + yield key + } + } + * values () { + for (let [, value] of this.entries()) { + yield value + } + } concat (...moreConfig) { return new Proxy(new FiggyPudding( this.__specs, @@ -20,25 +80,38 @@ class FiggyPudding { ), proxyHandler) } } +try { + const util = require('util') + FiggyPudding.prototype[util.inspect.custom] = function (depth, opts) { + return ( + this[Symbol.toStringTag] + ' ' + ) + util.inspect(this.toJSON(), opts) + } +} 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 (typeof spec === 'string') { - key = spec - 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 for (let p of pud.__providers) { - if (p.__isFiggyPudding) { - ret = pudGet(p, key, false) - } else if (typeof p.get === 'function') { - ret = p.get(key) - } else { - ret = p[key] + ret = tryGet(key, p) + if (ret === undefined && spec.aliases && spec.aliases.length) { + for (let alias of spec.aliases) { + if (alias === key) { continue } + ret = tryGet(alias, p) + if (ret !== undefined) { + break + } + } } if (ret !== undefined) { break @@ -56,28 +129,47 @@ function pudGet (pud, key, validate) { } } +function tryGet (key, p) { + let ret + if (p.__isFiggyPudding) { + ret = pudGet(p, key, false) + } else if (typeof p.get === 'function') { + ret = p.get(key) + } else { + ret = p[key] + } + return ret +} + const proxyHandler = { has (obj, prop) { - return pudGet(obj, prop, false) !== undefined + return prop in obj.__specs && pudGet(obj, prop, false) !== undefined + }, + ownKeys (obj) { + return Object.keys(obj.__specs) }, get (obj, prop) { if ( - prop === 'concat' || - prop === 'get' || - prop.slice(0, 2) === '__' + typeof prop === 'symbol' || + prop.slice(0, 2) === '__' || + prop in FiggyPudding.prototype ) { return obj[prop] } return obj.get(prop) }, set (obj, prop, value) { - if (prop.slice(0, 2) === '__') { + if ( + typeof prop === 'symbol' || + prop.slice(0, 2) === '__' + ) { obj[prop] = value + return true } else { throw new Error('figgyPudding options cannot be modified. Use .concat() instead.') } }, - delete () { + deleteProperty () { throw new Error('figgyPudding options cannot be deleted. Use .concat() and shadow them instead.') } } diff --git a/node_modules/figgy-pudding/package.json b/node_modules/figgy-pudding/package.json index 2d8368663a8e2..81e03eff7d7ac 100644 --- a/node_modules/figgy-pudding/package.json +++ b/node_modules/figgy-pudding/package.json @@ -1,19 +1,19 @@ { - "_from": "figgy-pudding@3.2.0", - "_id": "figgy-pudding@3.2.0", + "_from": "figgy-pudding@latest", + "_id": "figgy-pudding@3.4.1", "_inBundle": false, - "_integrity": "sha512-S2gSvqcqkI4sk+dI3ykKllfEg88dL5cXM0QPT4z9UbOkNygqec8/99d0VB3ikZ7u1/QC5l4e1YJPWvoUFuRVkg==", + "_integrity": "sha512-j1SAT641cerGuOvoSBoaE9LbSzh1N/E5ufk9oMpOKuyK8MyW3sGg4rh+4qhLmVTEAzipO5XTHYT4gjb6JYLE8g==", "_location": "/figgy-pudding", "_phantomChildren": {}, "_requested": { - "type": "version", + "type": "tag", "registry": true, - "raw": "figgy-pudding@3.2.0", + "raw": "figgy-pudding@latest", "name": "figgy-pudding", "escapedName": "figgy-pudding", - "rawSpec": "3.2.0", + "rawSpec": "latest", "saveSpec": null, - "fetchSpec": "3.2.0" + "fetchSpec": "latest" }, "_requiredBy": [ "#USER", @@ -22,9 +22,9 @@ "/libnpmhook", "/libnpmhook/npm-registry-fetch" ], - "_resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.2.0.tgz", - "_shasum": "464626b73d7b0fc045a99753d191b0785957ff73", - "_spec": "figgy-pudding@3.2.0", + "_resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.4.1.tgz", + "_shasum": "af66da1991fa2f94ff7f33b545a38ea4b3869696", + "_spec": "figgy-pudding@latest", "_where": "/Users/zkat/Documents/code/work/npm", "author": { "name": "Kat Marchán", @@ -66,9 +66,9 @@ "prerelease": "npm t", "pretest": "standard", "release": "standard-version -s", - "test": "tap -J --coverage test/*.js", + "test": "tap -J --100 --coverage test/*.js", "update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'", "update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'" }, - "version": "3.2.0" + "version": "3.4.1" } diff --git a/package-lock.json b/package-lock.json index 24b78ee9ecf70..da11c0f1e0cca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1535,9 +1535,9 @@ } }, "figgy-pudding": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.2.0.tgz", - "integrity": "sha512-S2gSvqcqkI4sk+dI3ykKllfEg88dL5cXM0QPT4z9UbOkNygqec8/99d0VB3ikZ7u1/QC5l4e1YJPWvoUFuRVkg==" + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.4.1.tgz", + "integrity": "sha512-j1SAT641cerGuOvoSBoaE9LbSzh1N/E5ufk9oMpOKuyK8MyW3sGg4rh+4qhLmVTEAzipO5XTHYT4gjb6JYLE8g==" }, "figures": { "version": "2.0.0", diff --git a/package.json b/package.json index c144ff23b8bc9..a13ba6f33ec56 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "detect-newline": "^2.1.0", "dezalgo": "~1.0.3", "editor": "~1.0.0", - "figgy-pudding": "^3.2.0", + "figgy-pudding": "^3.4.1", "find-npm-prefix": "^1.0.2", "fs-vacuum": "~1.2.10", "fs-write-stream-atomic": "~1.0.10",