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

option-chain

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

option-chain - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

27

index.js
'use strict';
var objectAssign = require('object-assign');
module.exports = (options, fn, target) => {
const chainables = options.chainableMethods || {};
const spread = options.spread;
const defaults = Object.assign({}, options.defaults);
module.exports = function (options, fn, target) {
var chainables = options.chainableMethods || {};
var spread = options.spread;
var defaults = objectAssign({}, options.defaults);
function extend(target, getter, ctx) {
Object.keys(chainables).forEach(function (key) {
for (const key of Object.keys(chainables)) {
Object.defineProperty(target, key, {
enumerable: true,
configurable: true,
get: function () {
get() {
return wrap(getter, chainables[key], ctx || this);
}
});
});
}
}

@@ -23,10 +21,12 @@

function wrappedOpts() {
return objectAssign(createOpts(), extensionOpts);
return Object.assign(createOpts(), extensionOpts);
}
function wrappedFn() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
let args = new Array(arguments.length);
for (let i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
if (spread) {

@@ -37,2 +37,3 @@ args.unshift(wrappedOpts());

}
return fn.apply(ctx || this, args);

@@ -47,3 +48,3 @@ }

function copyDefaults() {
return objectAssign({}, defaults);
return Object.assign({}, defaults);
}

@@ -50,0 +51,0 @@

{
"name": "option-chain",
"version": "0.1.1",
"version": "1.0.0",
"description": "Use fluent property chains in lieu of options objects",
"license": "MIT",
"repository": "jamestalmage/option-chain",
"repository": "avajs/option-chain",
"author": {

@@ -13,6 +13,6 @@ "name": "James Talmage",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && nyc --cache --reporter=lcov --reporter=text ava"
"test": "xo && nyc ava"
},

@@ -31,10 +31,13 @@ "files": [

"devDependencies": {
"ava": "^0.10.0",
"ava": "^0.19.1",
"coveralls": "^2.11.6",
"nyc": "^5.3.0",
"xo": "^0.12.1"
"nyc": "^10.3.2",
"xo": "^0.18.2"
},
"dependencies": {
"object-assign": "^4.0.1"
"nyc": {
"reporter": [
"lcov",
"text"
]
}
}

@@ -1,4 +0,4 @@

# option-chain [![Build Status](https://travis-ci.org/jamestalmage/option-chain.svg?branch=master)](https://travis-ci.org/jamestalmage/option-chain) [![Coverage Status](https://coveralls.io/repos/jamestalmage/option-chain/badge.svg?branch=master&service=github)](https://coveralls.io/github/jamestalmage/option-chain?branch=master)
# option-chain [![Build Status](https://travis-ci.org/avajs/option-chain.svg?branch=master)](https://travis-ci.org/avajs/option-chain) [![Coverage Status](https://coveralls.io/repos/github/avajs/option-chain/badge.svg?branch=master)](https://coveralls.io/github/avajs/option-chain?branch=master)
> Use fluent property chains in lieu of options objects.
> Use fluent property chains in lieu of options objects

@@ -19,17 +19,18 @@

const optionDefinition = {
defaults: {
bar: false
},
chainableMethods: {
foo: {foo: true},
notFoo: {foo: false},
bar: {bar: true}
}
defaults: {
bar: false
},
chainableMethods: {
foo: {foo: true},
notFoo: {foo: false},
bar: {bar: true}
}
};
function printOptionsAndArgs(options, args) {
console.log(options);
if (args.length) {
console.log(args);
}
console.log(options);
if (args.length) {
console.log(args);
}
}

@@ -60,4 +61,4 @@

Type: `Object`
*Required*
*Required*<br>
Type: `Object`

@@ -70,6 +71,6 @@ A map of chainable property names to the options set by adding property to the chain.

const chainableMethods = {
foo: {foo: true},
notFoo: {foo: false},
bar: {bar: true},
both: {foo: true, bar: true}
foo: {foo: true},
notFoo: {foo: false},
bar: {bar: true},
both: {foo: true, bar: true}
}

@@ -83,3 +84,3 @@ ```

- `fn.both` sets both `foo` and `bar` to `true`.
- The last property in the chain takes precedence, so `fn.foo.notFoo` would result in `foo` being `false`.
- The last property in the chain takes precedence, so `fn.foo.notFoo` would result in `foo` being `false`.

@@ -89,3 +90,3 @@

Type: `Object`
Type: `Object`<br>
Default: `{}`

@@ -97,3 +98,3 @@

Type: `boolean`
Type: `boolean`<br>
Default: `false`

@@ -105,9 +106,9 @@

function withoutSpread(opts, args) {
let foo = args[0];
let bar = args[1];
// ...
let foo = args[0];
let bar = args[1];
// ...
}
function withSpread(opts, foo, bar) {
// ...
// ...
}

@@ -118,3 +119,3 @@ ```

Type: `function`
Type: `Function`

@@ -127,12 +128,13 @@ This callback is called with the accumulated options as the first argument. Depending on the value of `options.spread`, arguments passed to the wrapper will either be an array as the second argument or spread out as the 2nd, 3rd, 4th... arguments.

*Hint:* If you want to extend a `target` and add a method that simply uses the defaults, add a chainable method definition with an empty spec:
*Hint:* If you want to extend a `target` and add a method that simply uses the defaults, add a chainable method definition with an empty spec:
```js
const chainableMethods = {
defaultMethodName: {}
defaultMethodName: {}
}
```
## License
MIT © [James Talmage](http://github.com/jamestalmage)
MIT © [James Talmage](https://github.com/jamestalmage)
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