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

lodash-decorators

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash-decorators - npm Package Compare versions

Comparing version 1.1.0 to 2.0.1

.npmignore

89

Applicator.js

@@ -6,2 +6,4 @@ 'use strict';

});
exports.invoke = invoke;
exports.resolveFunction = resolveFunction;

@@ -58,3 +60,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

return fn.apply(undefined, [Applicator.resolveFunction(args[0], this, target)].concat(_toConsumableArray(args.slice(1)))).apply(this, invokeArgs);
return fn.apply(undefined, [resolveFunction(args[0], this, target)].concat(_toConsumableArray(args.slice(1)))).apply(this, invokeArgs);
};

@@ -71,3 +73,3 @@ },

return fn(Applicator.resolveFunction(fnName, this, target), value).apply(this, invokeArgs);
return fn(resolveFunction(fnName, this, target), value).apply(this, invokeArgs);
};

@@ -98,3 +100,3 @@ },

return fn.apply(undefined, [value].concat(_toConsumableArray(args.map(function (method) {
return Applicator.resolveFunction(method, _this, target);
return resolveFunction(method, _this, target);
})))).apply(this, invokeArgs);

@@ -120,2 +122,3 @@ };

exports.applicators = applicators;
/**

@@ -125,48 +128,44 @@ * Applys a specific method signature onto a set of arguments. This is due to the various different APIs

*/
var Applicator = {
/**
* Invokes an applicator method.
*
* @param {Function} applicator The applicator function.
* @param {Function} method The function the applicator if being applied to.
* @param {Object} target The target object given to the decorator.
* @param {Function} value The value the decorator is being applied to.
* @param {...*} [args] Any additional arguments passed to the applicator.
* @returns {Function} A function with __method__ applied to __value__
* with the __applicator__s signature.
*/
invoke: function invoke(applicator, method, target, value) {
for (var _len11 = arguments.length, args = Array(_len11 > 4 ? _len11 - 4 : 0), _key11 = 4; _key11 < _len11; _key11++) {
args[_key11 - 4] = arguments[_key11];
}
return applicator.apply(undefined, [method, target, value].concat(args));
},
/**
* Invokes an applicator method.
*
* @param {Function} applicator The applicator function.
* @param {Function} method The function the applicator if being applied to.
* @param {Object} target The target object given to the decorator.
* @param {Function} value The value the decorator is being applied to.
* @param {...*} [args] Any additional arguments passed to the applicator.
* @returns {Function} A function with __method__ applied to __value__
* with the __applicator__s signature.
*/
/**
* Resolves a function on the current target object. It first will
* try and resolve on the context object, then the target object,
* then an error will be thrown if the method can not be resolved.
*
* @param {Function|String} method The method or method name.
* @param {Object} [context] The context object to resolve from.
* @param {Object} [target] The target object to resolve from.
* @returns {Function} The resolved function.
*/
resolveFunction: function resolveFunction(method, context, target) {
if ((0, _lodashLangIsFunction2['default'])(method)) {
return method;
} else if ((0, _lodashLangIsFunction2['default'])(context[method])) {
return context[method];
} else if ((0, _lodashLangIsFunction2['default'])(target[method])) {
return target[method];
}
function invoke(applicator, method, target, value) {
for (var _len11 = arguments.length, args = Array(_len11 > 4 ? _len11 - 4 : 0), _key11 = 4; _key11 < _len11; _key11++) {
args[_key11 - 4] = arguments[_key11];
}
throw new ReferenceError((0, _utilsLog2['default'])('Can not resolve method ' + method + ' on any target Objects'));
return applicator.apply(undefined, [method, target, value].concat(args));
}
/**
* Resolves a function on the current target object. It first will
* try and resolve on the context object, then the target object,
* then an error will be thrown if the method can not be resolved.
*
* @param {Function|String} method The method or method name.
* @param {Object} [context] The context object to resolve from.
* @param {Object} [target] The target object to resolve from.
* @returns {Function} The resolved function.
*/
function resolveFunction(method, context, target) {
if ((0, _lodashLangIsFunction2['default'])(method)) {
return method;
} else if ((0, _lodashLangIsFunction2['default'])(context[method])) {
return context[method];
} else if ((0, _lodashLangIsFunction2['default'])(target[method])) {
return target[method];
}
};
(0, _lodashObjectAssign2['default'])(Applicator, { applicators: applicators });
exports['default'] = Applicator;
module.exports = exports['default'];
throw new ReferenceError((0, _utilsLog2['default'])('Can not resolve method ' + method + ' on any target Objects'));
}

@@ -9,6 +9,2 @@ 'use strict';

var _utilsNormalizeExport = require('../utils/normalizeExport');
var _utilsNormalizeExport2 = _interopRequireDefault(_utilsNormalizeExport);
var _bind = require('./bind');

@@ -22,6 +18,5 @@

exports['default'] = (0, _utilsNormalizeExport2['default'])({
bind: _bind2['default'],
bindAll: _bindAll2['default']
});
module.exports = exports['default'];
exports.bind = _bind2['default'];
exports.bindAll = _bindAll2['default'];
exports.BindAll = _bindAll2['default'];
exports.Bind = _bind2['default'];

@@ -8,2 +8,4 @@ 'use strict';

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

@@ -35,2 +37,6 @@

var _lodashStringCapitalize = require('lodash/string/capitalize');
var _lodashStringCapitalize2 = _interopRequireDefault(_lodashStringCapitalize);
var _bindBindMap = require('./bind/bindMap');

@@ -50,3 +56,3 @@

var _Applicator2 = _interopRequireDefault(_Applicator);
var Applicator = _interopRequireWildcard(_Applicator);

@@ -57,8 +63,4 @@ var _utilsLog = require('./utils/log');

var _utilsNormalizeExport = require('./utils/normalizeExport');
var applicators = Applicator.applicators;
var _utilsNormalizeExport2 = _interopRequireDefault(_utilsNormalizeExport);
var applicators = _Applicator2['default'].applicators;
var instanceMethodMap = new _utilsCompositeKeyWeakMap2['default']();

@@ -148,3 +150,3 @@

descriptor[targetName] = _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, target, targetMethod].concat(args));
descriptor[targetName] = Applicator.invoke.apply(Applicator, [applicator, method, target, targetMethod].concat(args));
(0, _utilsCopyMetaData2['default'])(descriptor[targetName], targetMethod);

@@ -233,3 +235,3 @@ }

if (!instanceMap.has(keys)) {
instanceMap.set(keys, _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, this, targetMethod].concat(args)));
instanceMap.set(keys, Applicator.invoke.apply(Applicator, [applicator, method, this, targetMethod].concat(args)));
}

@@ -259,3 +261,3 @@

if (!instanceMap.has(keys)) {
instanceMap.set(keys, _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, this, targetMethod].concat(args)));
instanceMap.set(keys, Applicator.invoke.apply(Applicator, [applicator, method, this, targetMethod].concat(args)));
}

@@ -303,3 +305,8 @@

return (0, _lodashObjectAssign2['default'])(decorator, (0, _utilsNormalizeExport2['default'])(accessors));
(0, _lodashObjectForOwn2['default'])(accessors, function (value, key) {
decorator[key] = value;
decorator[(0, _lodashStringCapitalize2['default'])(key)] = value;
});
return decorator;
}

@@ -9,6 +9,2 @@ 'use strict';

var _utilsNormalizeExport = require('../utils/normalizeExport');
var _utilsNormalizeExport2 = _interopRequireDefault(_utilsNormalizeExport);
var _configurable = require('./configurable');

@@ -34,12 +30,22 @@

exports['default'] = (0, _utilsNormalizeExport2['default'])({
configurable: _configurable2['default'],
enumerable: _enumerable2['default'],
returnsArg: _returnsArg2['default'],
writable: _writable2['default'],
deprecated: _deprecated2['default'],
readonly: (0, _writable2['default'])(false),
nonenumerable: (0, _enumerable2['default'])(false),
nonconfigurable: (0, _configurable2['default'])(false)
});
module.exports = exports['default'];
exports.configurable = _configurable2['default'];
exports.enumerable = _enumerable2['default'];
exports.returnsArg = _returnsArg2['default'];
exports.writable = _writable2['default'];
exports.deprecated = _deprecated2['default'];
var readonly = (0, _writable2['default'])(false);
exports.readonly = readonly;
var nonenumerable = (0, _enumerable2['default'])(false);
exports.nonenumerable = nonenumerable;
var nonconfigurable = (0, _configurable2['default'])(false);
exports.nonconfigurable = nonconfigurable;
// Uppercase aliases
exports.Configurable = _configurable2['default'];
exports.Enumerable = _enumerable2['default'];
exports.ReturnsArg = _returnsArg2['default'];
exports.Writable = _writable2['default'];
exports.Deprecated = _deprecated2['default'];
exports.Readonly = readonly;
exports.Nonenumerable = nonenumerable;
exports.Nonconfigurable = nonconfigurable;

@@ -9,10 +9,2 @@ 'use strict';

var _lodashObjectForOwn = require('lodash/object/forOwn');
var _lodashObjectForOwn2 = _interopRequireDefault(_lodashObjectForOwn);
var _lodashObjectAssign = require('lodash/object/assign');
var _lodashObjectAssign2 = _interopRequireDefault(_lodashObjectAssign);
var _lodashFunction = require('lodash/function');

@@ -46,44 +38,86 @@

var _utilsNormalizeExport = require('./utils/normalizeExport');
exports.bind = _bindBind2['default'];
exports.tap = _tap2['default'];
exports.bindAll = _bindBindAll2['default'];
exports.mixin = _mixin2['default'];
exports.attempt = _attempt2['default'];
var _utilsNormalizeExport2 = _interopRequireDefault(_utilsNormalizeExport);
// Instance decorators
var once = (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'].once, _Applicator.applicators.single);
exports.once = once;
var debounce = (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'].debounce, _Applicator.applicators.pre);
exports.debounce = debounce;
var throttle = (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'].throttle, _Applicator.applicators.pre);
exports.throttle = throttle;
var memoize = (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'].memoize, _Applicator.applicators.pre);
exports.memoize = memoize;
var after = (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'].after, _Applicator.applicators.post);
exports.after = after;
var before = (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'].before, _Applicator.applicators.post);
var methods = {
instance: {
single: ['once'],
pre: ['debounce', 'throttle', 'memoize'],
post: ['after', 'before']
},
proto: {
single: ['spread', 'rearg', 'negate'],
pre: ['modArgs', 'ary', 'curry', 'curryRight', 'restParam'],
partial: ['partial', 'partialRight'],
wrap: ['wrap'],
compose: ['compose', 'flow', 'flowRight', 'backflow'],
partialed: ['delay', 'defer']
}
};
exports.before = before;
// Prototype decorators
var spread = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].spread, _Applicator.applicators.single);
exports.spread = spread;
var rearg = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].rearg, _Applicator.applicators.single);
exports.rearg = rearg;
var negate = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].negate, _Applicator.applicators.single);
exports.negate = negate;
var modArgs = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].modArgs, _Applicator.applicators.pre);
exports.modArgs = modArgs;
var ary = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].ary, _Applicator.applicators.pre);
exports.ary = ary;
var curry = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].curry, _Applicator.applicators.pre);
exports.curry = curry;
var curryRight = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].curryRight, _Applicator.applicators.pre);
exports.curryRight = curryRight;
var restParam = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].restParam, _Applicator.applicators.pre);
exports.restParam = restParam;
var partial = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].partial, _Applicator.applicators.partial);
exports.partial = partial;
var partialRight = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].partialRight, _Applicator.applicators.partial);
exports.partialRight = partialRight;
var wrap = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].wrap, _Applicator.applicators.wrap);
exports.wrap = wrap;
var compose = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].compose, _Applicator.applicators.compose);
exports.compose = compose;
var flow = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].flow, _Applicator.applicators.compose);
exports.flow = flow;
var flowRight = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].flowRight, _Applicator.applicators.compose);
exports.flowRight = flowRight;
var backflow = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].backflow, _Applicator.applicators.compose);
exports.backflow = backflow;
var delay = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].delay, _Applicator.applicators.partialed);
exports.delay = delay;
var defer = (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'].defer, _Applicator.applicators.partialed);
var result = {};
(0, _lodashObjectForOwn2['default'])(methods, function (hash, createType) {
(0, _lodashObjectForOwn2['default'])(hash, function (list, type) {
result = list.reduce(function (res, fnName) {
res[fnName] = createType === 'instance' ? (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'][fnName], _Applicator.applicators[type]) : (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'][fnName], _Applicator.applicators[type]);
return res;
}, result);
});
});
// All other decorators
(0, _lodashObjectAssign2['default'])(result, {
bind: _bindBind2['default'],
tap: _tap2['default'],
bindAll: _bindBindAll2['default'],
mixin: _mixin2['default'],
attempt: _attempt2['default']
});
exports['default'] = (0, _utilsNormalizeExport2['default'])(result);
module.exports = exports['default'];
exports.defer = defer;
// Uppercase aliases
exports.Once = once;
exports.Debounce = debounce;
exports.Throttle = throttle;
exports.Memoize = memoize;
exports.After = after;
exports.Before = before;
exports.Spread = spread;
exports.Rearg = rearg;
exports.Negate = negate;
exports.ModArgs = modArgs;
exports.Ary = ary;
exports.Curry = curry;
exports.CurryRight = curryRight;
exports.RestParam = restParam;
exports.Partial = partial;
exports.PartialRight = partialRight;
exports.Wrap = wrap;
exports.Compose = compose;
exports.Flow = flow;
exports.FlowRight = flowRight;
exports.Backflow = backflow;
exports.Delay = delay;
exports.Defer = defer;
exports.Bind = _bindBind2['default'];
exports.Tap = _tap2['default'];
exports.BindAll = _bindBindAll2['default'];
exports.Mixin = _mixin2['default'];
exports.Attempt = _attempt2['default'];

@@ -5,3 +5,3 @@ {

"description": "A collection of decorators using lodash at it's core.",
"version": "1.1.0",
"version": "2.0.1",
"engines": {

@@ -36,3 +36,3 @@ "node": ">=0.12.0"

"chalk": "~1.0.0",
"del": "~1.1.1",
"del": "^2.2.0",
"gulp": "~3.8.11",

@@ -39,0 +39,0 @@ "gulp-babel": "~5.0.0",

@@ -42,2 +42,6 @@ # lodash-decorators

## Disclaimer
The decorator proposal is still in quite a bit of flux. There will most likely be breaking changes as the spec changes. These
will be reflected in major releases (2.0.0).
## Install

@@ -44,0 +48,0 @@

@@ -9,6 +9,2 @@ 'use strict';

var _utilsNormalizeExport = require('../utils/normalizeExport');
var _utilsNormalizeExport2 = _interopRequireDefault(_utilsNormalizeExport);
var _validate = require('./validate');

@@ -22,6 +18,7 @@

exports['default'] = (0, _utilsNormalizeExport2['default'])({
validate: _validate2['default'],
validateReturn: _validateReturn2['default']
});
module.exports = exports['default'];
exports.validate = _validate2['default'];
exports.validateReturn = _validateReturn2['default'];
// Uppercase aliases
exports.Validate = _validate2['default'];
exports.ValidateReturn = _validateReturn2['default'];
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