Socket
Socket
Sign inDemoInstall

figgy-pudding

Package Overview
Dependencies
0
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    figgy-pudding

Delicious, festive, cascading config/opts definitions


Version published
Weekly downloads
3.8M
decreased by-28.12%
Maintainers
2
Install size
12.3 kB
Created
Weekly downloads
 

Changelog

Source

3.2.1 (2018-08-15)

Bug Fixes

  • aliases: make reverse aliases work correctly (76a255e)

<a name="3.2.0"></a>

Readme

Source

figgy-pudding npm version license Travis AppVeyor Coverage Status

Death to the God Object! Now Bring Us Some Figgy Pudding!

figgy-pudding is a simple 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.

Install

$ npm install figgy-pudding

Table of Contents

Example

const puddin = require('figgyPudding')

const RequestOpts = puddin({
  follow: {
    default: true
  },
  streaming: {
    default: false
  },
  log: {
    default: require('npmlog')
  }
})

const MyAppOpts = puddin({
  log: {
    default: require('npmlog')
  },
  cache: {
    default: './cache'
  }
})

function start (opts) {
  opts = MyAppOpts(opts)
  initCache(opts.get('cache'))
  opts.get('streaming') // => undefined
  reqStuff('https://npm.im/figgy-pudding', opts)
}

function reqStuff (uri, opts) {
  opts = RequestOpts(opts)
  require('request').get(uri, opts) // can't see `cache`
}

Features

  • Hide options from layer that didn't ask for it
  • Shared multi-layer options

API

> figgyPudding({ key: { default: val } | String }, [opts])

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
const MyAppOpts = figgyPudding({
  lg: 'log',
  log: {
    default: () => require('npmlog')
  },
  cache: {}
})
> Opts(...providers)

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
const ReqOpts = figgyPudding({
  follow: {}
})

const opts = ReqOpts({
  follow: true,
  log: require('npmlog')
})

opts.get('follow') // => true
opts.get('log') // => Error: ReqOpts does not define `log`

const MoreOpts = figgyPudding({
  log: {}
})
MoreOpts(opts).get('log') // => npmlog object (passed in from original plain obj)
MoreOpts(opts).get('follow') // => Error: MoreOpts does not define `follow`
> opts.get(key)

Gets a value from the options object.

Example
const opts = MyOpts(config)
opts.get('foo') // value of `foo`
> opts.concat(...moreProviders)

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
const opts = MyOpts({x: 1})
opts.get('x') // 1
opts.concat({x: 2}).get('x') // 2
opts.get('x') // 1 (original opts object left intact)

Keywords

FAQs

Last updated on 15 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc