Cascading, controlled-visibility options object management.
Installations
npm install figgy-pudding
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
13.10.1
NPM Version
6.13.7
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
2,376,108,983
Last Day
750,584
Last Week
3,296,859
Last Month
15,689,717
Last Year
246,801,749
GitHub Statistics
1 Stars
60 Commits
3 Forks
3 Watching
53 Branches
110 Contributors
Bundle Size
2.59 kB
Minified
1.13 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.5.2
Package Id
figgy-pudding@3.5.2
Size
6.26 kB
NPM Version
6.13.7
Node Version
13.10.1
Publised On
24 Mar 2020
Total Downloads
Cumulative downloads
Total Downloads
2,376,108,983
Last day
-4.8%
750,584
Compared to previous day
Last week
-19.4%
3,296,859
Compared to previous week
Last month
1.9%
15,689,717
Compared to previous month
Last year
-35%
246,801,749
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
Note: pending imminent deprecation
This module will be deprecated once npm v7 is released. Please do not rely on it more than absolutely necessary (ie, only if you are depending on it for use with npm v6 internal dependencies).
figgy-pudding
figgy-pudding
is a small JavaScript
library for managing and composing cascading options objects -- hiding what
needs to be hidden from each layer, without having to do a lot of manual munging
and passing of options.
The God Object is Dead!
Now Bring Us Some Figgy Pudding!
Install
$ npm install figgy-pudding
Table of Contents
Example
1// print-package.js 2const fetch = require('./fetch.js') 3const puddin = require('figgy-pudding') 4 5const PrintOpts = puddin({ 6 json: { default: false } 7}) 8 9async function printPkg (name, opts) { 10 // Expected pattern is to call this in every interface function. If `opts` is 11 // not passed in, it will automatically create an (empty) object for it. 12 opts = PrintOpts(opts) 13 const uri = `https://registry.npmjs.com/${name}` 14 const res = await fetch(uri, opts.concat({ 15 // Add or override any passed-in configs and pass them down. 16 log: customLogger 17 })) 18 // The following would throw an error, because it's not in PrintOpts: 19 // console.log(opts.log) 20 if (opts.json) { 21 return res.json() 22 } else { 23 return res.text() 24 } 25} 26 27console.log(await printPkg('figgy', { 28 // Pass in *all* configs at the toplevel, as a regular object. 29 json: true, 30 cache: './tmp-cache' 31}))
1// fetch.js 2const puddin = require('figgy-pudding') 3 4const FetchOpts = puddin({ 5 log: { default: require('npmlog') }, 6 cache: {} 7}) 8 9module.exports = async function (..., opts) { 10 opts = FetchOpts(opts) 11}
Features
- hide options from layer that didn't ask for it
- shared multi-layer options
- make sure
opts
argument is available - transparent key access like normal keys, through a Proxy. No need for
.get()
! - default values
- key aliases
- arbitrary key filter functions
- key/value iteration
- serialization
- 100% test coverage using
tap --100
API
> figgyPudding({ key: { default: val } | String }, [opts]) -> PuddingFactory
Defines an Options constructor that can be used to collect only the needed options.
An optional default
property for specs can be used to specify default values
if nothing was passed in.
If the value for a spec is a string, it will be treated as an alias to that other key.
Example
1const MyAppOpts = figgyPudding({ 2 lg: 'log', 3 log: { 4 default: () => require('npmlog') 5 }, 6 cache: {} 7})
> PuddingFactory(...providers) -> FiggyPudding{}
Instantiates an options object defined by figgyPudding()
, which uses
providers
, in order, to find requested properties.
Each provider can be either a plain object, a Map
-like object (that is, one
with a .get()
method) or another figgyPudding Opts
object.
When nesting Opts
objects, their properties will not become available to the
new object, but any further nested Opts
that reference that property will be
able to read from their grandparent, as long as they define that key. Default
values for nested Opts
parents will be used, if found.
Example
1const ReqOpts = figgyPudding({ 2 follow: {} 3}) 4 5const opts = ReqOpts({ 6 follow: true, 7 log: require('npmlog') 8}) 9 10opts.follow // => true 11opts.log // => Error: ReqOpts does not define `log` 12 13const MoreOpts = figgyPudding({ 14 log: {} 15}) 16MoreOpts(opts).log // => npmlog object (passed in from original plain obj) 17MoreOpts(opts).follow // => Error: MoreOpts does not define `follow`
> opts.get(key) -> Value
Gets a value from the options object.
Example
1const opts = MyOpts(config) 2opts.get('foo') // value of `foo` 3opts.foo // Proxy-based access through `.get()`
> opts.concat(...moreProviders) -> FiggyPudding{}
Creates a new opts object of the same type as opts
with additional providers.
Providers further to the right shadow providers to the left, with properties in
the original opts
being shadows by the new providers.
Example
1const opts = MyOpts({x: 1}) 2opts.get('x') // 1 3opts.concat({x: 2}).get('x') // 2 4opts.get('x') // 1 (original opts object left intact)
> opts.toJSON() -> Value
Converts opts
to a plain, JSON-stringifiable JavaScript value. Used internally
by JavaScript to get JSON.stringify()
working.
Only keys that are readable by the current pudding type will be serialized.
Example
1const opts = MyOpts({x: 1})
2opts.toJSON() // {x: 1}
3JSON.stringify(opts) // '{"x":1}'
> opts.forEach((value, key, opts) => {}, thisArg) -> undefined
Iterates over the values of opts
, limited to the keys readable by the current
pudding type. thisArg
will be used to set the this
argument when calling the
fn
.
Example
1const opts = MyOpts({x: 1, y: 2}) 2opts.forEach((value, key) => console.log(key, '=', value))
> opts.entries() -> Iterator<[[key, value], ...]>
Returns an iterator that iterates over the keys and values in opts
, limited to
the keys readable by the current pudding type. Each iteration returns an array
of [key, value]
.
Example
1const opts = MyOpts({x: 1, y: 2}) 2[...opts({x: 1, y: 2}).entries()] // [['x', 1], ['y', 2]]
> opts[Symbol.iterator]() -> Iterator<[[key, value], ...]>
Returns an iterator that iterates over the keys and values in opts
, limited to
the keys readable by the current pudding type. Each iteration returns an array
of [key, value]
. Makes puddings work natively with JS iteration mechanisms.
Example
1const opts = MyOpts({x: 1, y: 2}) 2[...opts({x: 1, y: 2})] // [['x', 1], ['y', 2]] 3for (let [key, value] of opts({x: 1, y: 2})) { 4 console.log(key, '=', value) 5}
> opts.keys() -> Iterator<[key, ...]>
Returns an iterator that iterates over the keys in opts
, limited to the keys
readable by the current pudding type.
Example
1const opts = MyOpts({x: 1, y: 2}) 2[...opts({x: 1, y: 2}).keys()] // ['x', 'y']
> opts.values() -> Iterator<[value, ...]>
Returns an iterator that iterates over the values in opts
, limited to the keys
readable by the current pudding type.
Example
'
1const opts = MyOpts({x: 1, y: 2}) 2[...opts({x: 1, y: 2}).values()] // [1, 2]
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'latest'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
54 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-7xcx-6wjh-7xp2
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More