A collection of decorators using lodash at it's core.
Installations
npm install lodash-decorators
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.12.0
Node Version
8.3.0
NPM Version
5.10.0
Score
99.1
Supply Chain
99.6
Quality
76.1
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
27,916,691
Last Day
11,365
Last Week
51,555
Last Month
236,357
Last Year
3,746,437
GitHub Statistics
729 Stars
213 Commits
34 Forks
13 Watching
26 Branches
7 Contributors
Bundle Size
31.21 kB
Minified
6.39 kB
Minified + Gzipped
Package Meta Information
Latest Version
6.0.1
Package Id
lodash-decorators@6.0.1
Size
44.21 kB
NPM Version
5.10.0
Node Version
8.3.0
Publised On
22 Dec 2018
Total Downloads
Cumulative downloads
Total Downloads
27,916,691
Last day
-18.2%
11,365
Compared to previous day
Last week
-28.6%
51,555
Compared to previous week
Last month
7.7%
236,357
Compared to previous month
Last year
-16%
3,746,437
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
lodash-decorators
Decorators using lodash functions. View the API docs for more in depth documentation.
- Install
- Usage
Install
npm install --save lodash lodash-decorators
Polyfills
This library requires Map
and WeakMap
to be available globally. If Map
or WeakMap
is not supported in your environment then use a polyfill.
Usage
For more in depth documentation please visit Lodash
Decorators are exported as both start case and lower case.
import { Debounce } from 'lodash-decorators';
is the same as
import { debounce } from 'lodash-decorators';
They can also be imported directly.
import Debounce from 'lodash-decorators/debounce';
Decorators
These decorators are included in the package. These are also exported as lowercase for those who prefer lowercase decorators.
After
AfterAll
Ary
Attempt
Before
BeforeAll
Bind
BindAll
Curry
CurryAll
CurryRight
CurryRightAll
Debounce
DebounceAll
Defer
Delay
Flip
Flow
FlowRight
Memoize
MemoizeAll
Mixin
Negate
Once
OnceAll
OverArgs
Partial
PartialRight
Rearg
Rest
Spread
Tap
Throttle
ThrottleAll
ThrottleGetter
ThrottleSetter
Unary
Wrap
Example
1import { Debounce, Memoize } from 'lodash-decorators'; 2 3class Person { 4 constructor(firstName, lastName) { 5 this.firstName = firstName; 6 this.lastName = lastName; 7 } 8 9 @Debounce(100) 10 save(date) { 11 return this.httpService.post(data); 12 } 13 14 @Memoize(item => item.id) 15 doSomeHeavyProcessing(arg1, arg2) {} 16}
Optional Params and Casing
If a decorator does not require params or has optional params then the decorator does not require invocation. Decorators are also exported in lower case as well as start case.
Example
1// These are both valid decorator usages. 2class Person { 3 @Memoize() 4 doSomething() {} 5 6 @Memoize 7 doSomething2() {} 8 9 @memoize() 10 doSomething3() {} 11 12 @memoize 13 doSomething4() {} 14}
Partials
Some decorators work slightly differently than you would expect them to work than lodash.
Partial
PartialRight
Wrap
These can take a Function
as their first argument or a String
.
If the argument is a String
then a Function
is resolved from
the current object.
Example
1import { Partial, Wrap } from 'lodash-decorators' 2 3class Person { 4 constructor(firstName, lastName) { 5 this.firstName = firstName; 6 this.lastName = lastName; 7 } 8 9 getName(type) { 10 return type === 'firstName' ? this.firstName : this.lastName 11 } 12 13 @Partial('getName', 'firstName') 14 getFirstName() {} 15 16 @Partial('getName', null) 17 getLastName() {} 18 19 @Wrap('getName') 20 getUpperCaseName(fn) { 21 return fn().toUpperCase(); 22 } 23} 24 25const person = new Person('Joe', 'Smith'); 26 27person.getFirstName(); // 'Joe' 28person.getLastName(); // 'Smith' 29person.getUpperCaseName(); // JOE SMITH
Composition
You can use methods like compose
and flow
similiar to
partials. The arguments are resolved the same way partials
are resolved.
Example
1import { Flow } from 'lodash-decorators' 2import { kebabCase } from 'lodash'; 3 4class Person { 5 @Flow('getName', kebabCase) 6 logName; 7 8 constructor(firstName, lastName) { 9 this.firstName = firstName; 10 this.lastName = lastName; 11 } 12 13 getName() { 14 return `${this.firstName} ${this.lastName}`; 15 } 16} 17 18const person = new Person('Joe', 'Smith'); 19 20person.logName(); // joe-smith
Instance Decorators
Normally decorators are applied to the prototype method of the class you are working with, but with some of these decorators that is not the desired behavour. These decorators are applied at the instance level.
Debounce
Throttle
Memoize
After
Before
Curry
CurryRight
Once
Flow
FlowRight
Rearg
Negate
Flip
Bind
Partial
PartialRight
Mixin
You can mixin methods into a class by using the Mixin
decorator.
Example
1import { Mixin } from 'lodash-decorators'; 2 3const MyOtherApi = { 4 someCoolMethod() { 5 // Do something cool 6 } 7}; 8 9@Mixin(MyOtherApi) 10class Person {} 11 12Person.prototype.someCoolMethod === MyOtherApi.someCoolMethod; // => true
Attempt
You can wrap a method in a lodash attempt method.
Example
1import { Attempt } from 'lodash-decorators'; 2 3class Person { 4 @Attempt() 5 throwAnError() { 6 throw new Error(); 7 } 8 9 @Attempt() 10 doNotThrowAnError() { 11 return '0_o'; 12 } 13} 14 15const person = new Person(); 16 17let result = person.throwAnError(); 18 19result instanceof Error; // => true 20 21result = person.doNotThrowAnError(); 22 23result === '0_o'; // => true
Bind
Bind takes arguments based on lodash's bind and binds the Function
to
the current instance object.
Example
1import { Bind } from 'lodash-decorators' 2 3class Person { 4 constructor(firstName, lastName) { 5 this.firstName = firstName; 6 this.lastName = lastName; 7 } 8 9 @Bind() 10 getName() { 11 return `${this.firstName} ${this.lastName}`; 12 } 13 14 // It can also function as a partial 15 @Bind('Joe') 16 getUpperCaseName(name) { 17 return name.toUpperCase(); 18 } 19} 20 21const person = new Person('Joe', 'Smith'); 22 23person.getName.call(null); // Joe Smith 24person.getUpperCaseName(); // JOE
You can also bind entire classes with bindAll
or bind
.
Example
1import { BindAll } from 'lodash-decorators' 2 3@BindAll() 4class Person { 5 constructor(firstName, lastName) { 6 this.firstName = firstName; 7 this.lastName = lastName; 8 } 9 10 getName() { 11 return `${this.firstName} ${this.lastName}`; 12 } 13} 14 15const person = new Person('Joe', 'Smith'); 16 17person.getName.call(null); // Joe Smith
v4 Breaking Changes
Version 4 is a rewrite of the library and has many breaking changes.
Not all decorators can be applied to or forced on getters/setters.
Only certain decorators make sense to be applied to getters/setters. Before you could specify the target of the decorator like debounce.set(15)
. This behavior is
removed and decorators that make sense to apply to getters/setters are configured to be applied to methods and either the getter or the setter. For example:
1class MyClass { 2 // This only gets applied to the setter as it doesn't make sense to apply it to the getter. 3 @Debounce(1000) 4 get value() { 5 return this._value; 6 } 7 8 set value(val) { 9 this._value = val; 10 } 11 12 @Debounce(15) 13 fn() {} 14}
This keeps the API cleaner and doesn't require the developer to know how the decorator applies to the descriptor. Some decorators have explicit version that apply to either getters of setters, such as ThrottleGetter
and ThrottleSetter
.
No longer force instance decorator onto prototype
There is no longer a Proto
decorator attached to instance decorators. Most instance decorators now have a counterpart that applies to the prototype instead of the instance. Debounce.Proto()
is now DebounceAll()
.
All decorators now take arguments
All decorators now take arguments. So instead of @Once
you would do @Once()
. This keeps the API consistent and doesn't require the developer to remember which decorators take arguments.
Removal of extensions and validation package
All extensions like enumerable
have been removed in favor of core-decorators. There may be some slight over lap like debounce
and throttle
. Fair warning, instance decorators may not play nice with other implementations of instance decorators.
We want to keep lodash decorators focused specifically on lodash specific functions.
Prototype decorator order no longer throws an error
If a prototype decorator comes after an instance decorator it will be ignored since there is no way to apply it in the chain.
Other breaking changes
Attempt
now takes an argument to line up with lodash API.Bind
used on a class no longer delegates toBindAll
. UseBindAll
instead.Curry
,Partial
,Flow
,FlowRight
are now instance decorators.
v4 Improvements
- Ships with TypeScript typings.
- Predictable performance.
- Improvements to Bind decorator.
- Improved API for decorator factory.
- More and better unit tests.
- Better performance with instance decorators.
- Single imports with
import { Debounce } from 'lodash-decorators/debounce'
; - Composition decorators can be used on properties. These will generate the composed function.
No vulnerabilities found.
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no binaries found in the repo
Reason
Found 2/18 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Reason
43 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-p28h-cc7q-c4fg
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-jc84-3g44-wf2q
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-xf5p-87ch-gxw2
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
1.9
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to lodash-decorators
core-decorators
Library of JavaScript stage-0 decorators (aka ES2016/ES7 decorators but that's not accurate!) inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more! Works great with React/Angular/more!
@types/lodash-decorators
Stub TypeScript definitions entry for lodash-decorators, which provides its own types definitions
lodash-decorators-esm
A collection of decorators using lodash at it's core.
@phanmn/lodash-decorators
A collection of decorators using lodash at it's core.