New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 0.2.2 to 0.2.3

133

Applicator.js

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

var _typeMap;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _defineProperty(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }

@@ -32,65 +28,71 @@

var types = {
SINGLE: 'single',
PRE: 'pre',
POST: 'post',
PROTO: 'proto',
WRAP: 'wrap',
COMPOSE: 'compose',
PARTIALED: 'partialed',
PARTIAL: 'partial',
REPLACE: 'replace',
INSTANCE: 'instance'
};
var applicators = {
// Methods where the function is the last argument or the first
// and all other arguments come before or after.
post: function post(fn, target, value) {
for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
args[_key - 3] = arguments[_key];
}
var typeMap = (_typeMap = {}, _defineProperty(_typeMap, types.POST, function (fn, target, value) {
for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
args[_key - 3] = arguments[_key];
}
return fn.apply(undefined, args.concat([value]));
},
pre: function pre(fn, target, value) {
for (var _len2 = arguments.length, args = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
args[_key2 - 3] = arguments[_key2];
}
return fn.apply(undefined, args.concat([value]));
}), _defineProperty(_typeMap, types.PRE, function (fn, target, value) {
for (var _len2 = arguments.length, args = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
args[_key2 - 3] = arguments[_key2];
}
return fn.apply(undefined, [value].concat(args));
},
return fn.apply(undefined, [value].concat(args));
}), _defineProperty(_typeMap, types.PARTIAL, function (fn, target, value) {
for (var _len3 = arguments.length, args = Array(_len3 > 3 ? _len3 - 3 : 0), _key3 = 3; _key3 < _len3; _key3++) {
args[_key3 - 3] = arguments[_key3];
}
// Partials are slightly different. They partial an existing function
// on the object referenced by string name.
partial: function partial(fn, target, value) {
for (var _len3 = arguments.length, args = Array(_len3 > 3 ? _len3 - 3 : 0), _key3 = 3; _key3 < _len3; _key3++) {
args[_key3 - 3] = arguments[_key3];
}
return fn.apply(undefined, [Applicator.resolveFunction(args[0], target)].concat(_toConsumableArray(args.slice(1))));
}), _defineProperty(_typeMap, types.WRAP, function (fn, target, value) {
return fn(Applicator.resolveFunction(arguments[3], target), value);
}), _defineProperty(_typeMap, types.REPLACE, function (fn, target, value) {
for (var _len4 = arguments.length, args = Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) {
args[_key4 - 3] = arguments[_key4];
}
return fn.apply(undefined, [Applicator.resolveFunction(args[0], target)].concat(_toConsumableArray(args.slice(1))));
},
return fn.apply(undefined, args);
}), _defineProperty(_typeMap, types.COMPOSE, function (fn, target, value) {
for (var _len5 = arguments.length, args = Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
args[_key5 - 3] = arguments[_key5];
}
// Wrap is a different case since the original function value
// needs to be given to the wrap method.
wrap: function wrap(fn, target, value) {
return fn(Applicator.resolveFunction(arguments[3], target), value);
},
replace: function replace(fn, target, value) {
for (var _len4 = arguments.length, args = Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) {
args[_key4 - 3] = arguments[_key4];
}
return fn.apply(undefined, [value].concat(_toConsumableArray(args.map(function (method) {
return Applicator.resolveFunction(method, target);
}))));
}), _defineProperty(_typeMap, types.PARTIALED, function (fn, target, value) {
for (var _len6 = arguments.length, args = Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
args[_key6 - 3] = arguments[_key6];
}
return fn.apply(undefined, args);
},
return _lodashFunctionPartial2['default'].apply(undefined, [fn, value].concat(args));
}), _defineProperty(_typeMap, types.SINGLE, function (fn, target, value) {
for (var _len7 = arguments.length, args = Array(_len7 > 3 ? _len7 - 3 : 0), _key7 = 3; _key7 < _len7; _key7++) {
args[_key7 - 3] = arguments[_key7];
// Calls the function with key functions and the value
compose: function compose(fn, target, value) {
for (var _len5 = arguments.length, args = Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
args[_key5 - 3] = arguments[_key5];
}
return fn.apply(undefined, [value].concat(_toConsumableArray(args.map(function (method) {
return Applicator.resolveFunction(method, target);
}))));
},
partialed: function partialed(fn, target, value) {
for (var _len6 = arguments.length, args = Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
args[_key6 - 3] = arguments[_key6];
}
return _lodashFunctionPartial2['default'].apply(undefined, [fn, value].concat(args));
},
single: function single(fn, target, value) {
for (var _len7 = arguments.length, args = Array(_len7 > 3 ? _len7 - 3 : 0), _key7 = 3; _key7 < _len7; _key7++) {
args[_key7 - 3] = arguments[_key7];
}
return applicators.pre.apply(applicators, [fn, target, value].concat(args));
}
};
return typeMap[types.PRE].apply(typeMap, [fn, target, value].concat(args));
}), _typeMap);
var Applicator = {
invoke: function invoke(type, method, target, value) {
invoke: function invoke(applicator, method, target, value) {
for (var _len8 = arguments.length, args = Array(_len8 > 4 ? _len8 - 4 : 0), _key8 = 4; _key8 < _len8; _key8++) {

@@ -100,3 +102,3 @@ args[_key8 - 4] = arguments[_key8];

return typeMap[type].apply(typeMap, [method, target, value].concat(args));
return applicator.apply(undefined, [method, target, value].concat(args));
},

@@ -121,16 +123,5 @@

(0, _lodashObjectAssign2['default'])(Applicator, types);
(0, _lodashObjectAssign2['default'])(Applicator, { applicators: applicators });
exports['default'] = Applicator;
module.exports = exports['default'];
// Methods where the function is the last argument or the first
// and all other arguments come before or after.
// Partials are slightly different. They partial an existing function
// on the object referenced by string name.
// Wrap is a different case since the original function value
// needs to be given to the wrap method.
// Calls the function with key functions and the value
module.exports = exports['default'];

@@ -31,6 +31,8 @@ 'use strict';

var applicators = _Applicator2['default'].applicators;
function createDecorator(method) {
var type = arguments[1] === undefined ? _Applicator2['default'].PRE : arguments[1];
var applicator = arguments[1] === undefined ? applicators.pre : arguments[1];
return type === _Applicator2['default'].SINGLE ? wrapper() : wrapper;
return applicator === applicators.single ? wrapper() : wrapper;

@@ -47,6 +49,6 @@ function wrapper() {

if (get) {
descriptor.get = _Applicator2['default'].invoke.apply(_Applicator2['default'], [type, method, target, get].concat(args));
descriptor.get = _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, target, get].concat(args));
_Applicator2['default'].copyMetaData(get, descriptor.get);
} else if (value) {
descriptor.value = _Applicator2['default'].invoke.apply(_Applicator2['default'], [type, method, target, value].concat(args));
descriptor.value = _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, target, value].concat(args));
_Applicator2['default'].copyMetaData(value, descriptor.value);

@@ -61,7 +63,7 @@ }

function createInstanceDecorator(method) {
var type = arguments[1] === undefined ? _Applicator2['default'].PRE : arguments[1];
var applicator = arguments[1] === undefined ? applicators.pre : arguments[1];
var objectMap = new _utilsCompositeKeyWeakMap2['default']();
return type === _Applicator2['default'].SINGLE ? wrapper() : wrapper;
return applicator === applicators.single ? wrapper() : wrapper;

@@ -93,3 +95,3 @@ function wrapper() {

if (!objectMap.has([this, toWrap])) {
objectMap.set([this, toWrap], _Applicator2['default'].invoke.apply(_Applicator2['default'], [type, method, this, toWrap].concat(args)));
objectMap.set([this, toWrap], _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, this, toWrap].concat(args)));
}

@@ -96,0 +98,0 @@

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

var _INSTANCE, _PROTO, _methods;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _defineProperty(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }
var _lodashStringCapitalize = require('lodash/string/capitalize');

@@ -42,16 +38,18 @@

var _Applicator2 = _interopRequireDefault(_Applicator);
var methods = {
instance: {
single: ['once'],
pre: ['debounce', 'throttle', 'memoize'],
post: ['after', 'before']
},
proto: {
single: ['spread', 'rearg', 'negate'],
pre: ['ary', 'curry', 'curryRight', 'restParam'],
partial: ['partial', 'partialRight'],
wrap: ['wrap'],
compose: ['compose', 'flow', 'flowRight', 'backflow'],
partialed: ['delay', 'defer']
}
};
var SINGLE = _Applicator2['default'].SINGLE;
var PRE = _Applicator2['default'].PRE;
var POST = _Applicator2['default'].POST;
var PROTO = _Applicator2['default'].PROTO;
var WRAP = _Applicator2['default'].WRAP;
var COMPOSE = _Applicator2['default'].COMPOSE;
var PARTIALED = _Applicator2['default'].PARTIALED;
var PARTIAL = _Applicator2['default'].PARTIAL;
var INSTANCE = _Applicator2['default'].INSTANCE;
var methods = (_methods = {}, _defineProperty(_methods, INSTANCE, (_INSTANCE = {}, _defineProperty(_INSTANCE, SINGLE, ['once']), _defineProperty(_INSTANCE, PRE, ['debounce', 'throttle', 'memoize']), _defineProperty(_INSTANCE, POST, ['after', 'before']), _INSTANCE)), _defineProperty(_methods, PROTO, (_PROTO = {}, _defineProperty(_PROTO, SINGLE, ['spread', 'rearg', 'negate']), _defineProperty(_PROTO, PRE, ['ary', 'curry', 'curryRight', 'restParam']), _defineProperty(_PROTO, PARTIAL, ['partial', 'partialRight']), _defineProperty(_PROTO, WRAP, ['wrap']), _defineProperty(_PROTO, COMPOSE, ['compose', 'flow', 'flowRight', 'backflow']), _defineProperty(_PROTO, PARTIALED, ['delay', 'defer']), _PROTO)), _methods);
var result = {};

@@ -62,3 +60,3 @@

result = list.reduce(function (res, fnName) {
res[fnName] = createType === INSTANCE ? (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'][fnName], type) : (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'][fnName], type);
res[fnName] = createType === 'instance' ? (0, _decoratorFactory.createInstanceDecorator)(_lodashFunction2['default'][fnName], _Applicator.applicators[type]) : (0, _decoratorFactory.createDecorator)(_lodashFunction2['default'][fnName], _Applicator.applicators[type]);

@@ -65,0 +63,0 @@ return res;

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

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

@@ -8,0 +8,0 @@ "node": ">=0.12.0"

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _decoratorFactory = require('./decoratorFactory');

@@ -14,4 +12,2 @@

var _Applicator2 = _interopRequireDefault(_Applicator);
exports['default'] = (0, _decoratorFactory.createDecorator)(function tapDecorator(fn) {

@@ -26,3 +22,3 @@ return function () {

};
}, _Applicator2['default'].SINGLE);
}, _Applicator.applicators.single);
module.exports = exports['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