JSPM

@untydev/options

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q24378F
  • License MIT

Handle default options in functions.

Package Exports

  • @untydev/options
  • @untydev/options/lib/options.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@untydev/options) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@untydev/options

Installation

Requires Node.js in version >=17.9.1.

npm i @untydev/options

Usage

import makeOptions from '@untydev/options'

const defaultOptions = {
  firstOption: true,
  secondOption: 'a'
}

function doSomething (options) {
  options = makeOptions(options, defaultOptions)
  
  console.log(options)
}

doSomething()
// options = { firstOption: true, secondOption: 'a' }

doSomething({ firstOption: false })
// options = { firstOption: false, secondOption: 'a' }

doSomething({ secondOption: 'b' })
// options = { firstOption: true, secondOption: 'b' })

API

makeOptions([inputOptions: Object], [defaultOptions: Object]): Object

Merges inputOptions with defaultOptions and returns a new object. None of the input arguments is modified. The merging is done with @untydev/merge function.