Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defaults-extender

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defaults-extender

A different approach for extending Options against Defaults.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Defaults-Extender

Build Status npm version npm downloads dependencies

Fast, tiny and useful utility to extend options against defaults.

Installation

$ npm install defaults-extender

Description

Easily extend object A with object B with a few fancy features. for example:

let's say you are building a command-line interface (CLI) and you have have something like this:

$ mycli --option.enabled true

but what you really want to do is.. if the user only sends --option true set the property enabled to true. if you are to tackle with the command parser itself you end up with a "if else" hell in your file... or you start to create names like --optionEnabled true...

what if you could so something like this:

const extend = require('defaults-extender')
//or const { extend } = require('defaults-extender')

const defaults = {
    options: {
        enabled: false,
        format: 'jpg',
        size: 1024
    }
}

let options = { options : true };

let result = extend(defaults, options);

// result in 

result = {
    options: {
        enabled: true,
        format: 'jpg',
        size: 1024
    }
}

so, all what you need to do is specify your defaults, and adhere to it, it will be how your final output will look like. for example this will not work:

const defaults = {
    options: false
}

let options = {
    options: {
        enabled: true
    }
}

let result = extend(defaults, options);

console.log(result.options.enabled) // undefined

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install && npm test

Build From Source

To build from github, first clone this repo locally then run npm run build:

$ npm run build

License

MIT

Keywords

FAQs

Package last updated on 05 Apr 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc