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 0.0.1 to 0.0.2

src/getter.js

2

package.json
{
"name": "lodash-decorators",
"author": "Steven Sojka",
"version": "0.0.1",
"version": "0.0.2",
"engines": {

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

'use strict';
import { isFunction } from 'lodash';
import settings from './settings';

@@ -24,2 +25,4 @@ const TYPE_MAP = {

TYPE_MAP.single = TYPE_MAP.pre;
/**

@@ -34,3 +37,5 @@ * Creates a generic decorator for a method on an object.

function createDecorator(root, method, type = 'pre') {
return function wrapper(...args) {
return type === 'single' ? wrapper() : wrapper;
function wrapper(...args) {
return function decorator(target, name, descriptor) {

@@ -52,24 +57,33 @@ const { value, get } = descriptor;

function createInstanceDecorator(root, method, type = 'pre') {
return function wrapper(...args) {
return type === 'single' ? wrapper() : wrapper;
function wrapper(...args) {
return function decorator(target, name, descriptor) {
const { value, get } = descriptor;
const action = TYPE_MAP[type];
const getterAnnotation = `${settings.annotationPrefix}isGetter`;
return {
get: function getter() {
const newDescriptor = { configurable: true, writable: true };
getter[getterAnnotation] = get[getterAnnotation];
if (isFunction(get)) {
newDescriptor.get = action(root[method], this, get, ...args);
Object.defineProperty(this, name, newDescriptor);
return { get: getter };
return newDescriptor.get();
}
function getter() {
const isGetter = Boolean(getter[getterAnnotation]);
const newDescriptor = { configurable: true };
newDescriptor.value = action(root[method], this, value, ...args);
if (isFunction(get)) {
const toWrap = isGetter ? get : get.call(this);
newDescriptor.get = action(root[method], this, toWrap, ...args);
Object.defineProperty(this, name, newDescriptor);
return newDescriptor.value;
return isGetter ? newDescriptor.get() : newDescriptor.get;
}
};
newDescriptor.value = action(root[method], this, value, ...args);
Object.defineProperty(this, name, newDescriptor);
return newDescriptor.value;
}
};

@@ -76,0 +90,0 @@ };

'use strict';
import _ from 'lodash';
import getter from './getter';
import { createDecorator, createInstanceDecorator } from './decoratorFactory';
import settings from './settings';
const methods = {
instance: {
single: [
'once'
],
pre: [
'debounce',
'throttle',
'memoize',
'once'
'memoize'
],

@@ -20,7 +24,9 @@ post: [

proto: {
single: [
'rearg',
'negate'
],
pre: [
'curry',
'curryRight',
'negate',
'rearg'
'curryRight'
],

@@ -35,3 +41,4 @@ partial: [

compose: [
'compose'
'compose',
'flow'
]

@@ -55,2 +62,10 @@ }

export default result;
// All other decorators
_.assign(result, { getter });
// Provide aliases @memoize => @Memoize
// This is for users who prefer capitalized decorators and
// can prevent naming collissions.
_.forOwn(result, (value, key) => result[_.capitalize(key)] = value);
export default _.assign(result, { settings });
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