Socket
Socket
Sign inDemoInstall

resolve-options

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

91

index.js
'use strict';
var koalas = require('koalas');
var normalize = require('value-or-function');

@@ -17,11 +16,47 @@

var lastKey;
function resolve(key) {
if (typeof key !== 'string') {
// Keep constants separately
var constants = {};
function resolveConstant(key) {
if (constants.hasOwnProperty(key)) {
return constants[key];
}
var definition = config[key];
// Ignore options that are not defined
if (!definition) {
return;
}
var appliedArgs = slice.call(arguments, 1);
var option = options[key];
if (option != null) {
if (typeof option === 'function') {
return;
}
option = normalize.call(resolver, definition.type, option);
if (option != null) {
constants[key] = option;
return option;
}
}
var fallback = definition.default;
if (option == null && typeof fallback !== 'function') {
constants[key] = fallback;
return fallback;
}
}
// Keep requested keys to detect (and disallow) recursive resolution
var stack = [];
function resolve(key) {
var option = resolveConstant(key);
if (option != null) {
return option;
}
var definition = config[key];

@@ -33,30 +68,46 @@ // Ignore options that are not defined

if (key === lastKey) {
if (stack.indexOf(key) >= 0) {
throw new Error('Recursive resolution denied.');
}
lastKey = key;
var option = options[key];
// Bind the option so it can resolve other options if necessary
if (typeof option === 'function') {
option = option.bind(resolver);
}
option = options[key];
var fallback = definition.default;
var appliedArgs = slice.call(arguments, 1);
var args = [definition.type, option].concat(appliedArgs);
var result = normalize.apply(null, args);
var fallback = definition.default;
// Bind & apply the default so it can resolve other options if necessary
if (typeof fallback === 'function') {
fallback = fallback.apply(resolver, appliedArgs);
function toResolve() {
stack.push(key);
var option = normalize.apply(resolver, args);
if (option == null) {
option = fallback;
if (typeof option === 'function') {
option = option.apply(resolver, appliedArgs);
}
}
return option;
}
lastKey = null;
function onResolve() {
stack.pop();
}
return koalas(result, fallback);
return tryResolve(toResolve, onResolve);
}
return resolver;
}
function tryResolve(toResolve, onResolve) {
try {
return toResolve();
} finally {
onResolve();
}
}
module.exports = createResolver;
{
"name": "resolve-options",
"version": "1.0.0",
"version": "1.1.0",
"description": "Resolve an options object based on configuration.",

@@ -27,4 +27,3 @@ "author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)",

"dependencies": {
"koalas": "^1.0.2",
"value-or-function": "^2.0.0"
"value-or-function": "^3.0.0"
},

@@ -31,0 +30,0 @@ "devDependencies": {

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