Installations
npm install lodash-decorators-esm
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.12.0
Node Version
12.18.2
NPM Version
6.14.5
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
32,262
Last Day
55
Last Week
227
Last Month
1,254
Last Year
11,993
GitHub Statistics
1 Stars
214 Commits
16 Branches
1 Contributors
Bundle Size
12.09 kB
Minified
3.10 kB
Minified + Gzipped
Package Meta Information
Latest Version
6.1.1
Package Id
lodash-decorators-esm@6.1.1
Unpacked Size
206.17 kB
Size
43.49 kB
File Count
201
NPM Version
6.14.5
Node Version
12.18.2
Total Downloads
Cumulative downloads
Total Downloads
32,262
Last day
-38.2%
55
Compared to previous day
Last week
-33.6%
227
Compared to previous week
Last month
22.9%
1,254
Compared to previous month
Last year
4%
11,993
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
lodash-decorators
Decorators using lodash functions. View the API docs for more in depth documentation.
- Install
- Usage
Install
npm install --save lodash-es lodash-decorators-es
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-esm';
is the same as
import { debounce } from 'lodash-decorators-esm';
They can also be imported directly.
import Debounce from 'lodash-decorators-esm/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-esm'; 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-esm' 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-esm' 2import { kebabCase } from 'lodash-es'; 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-esm'; 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-esm'; 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 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-esm' 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-esm/debounce'
; - Composition decorators can be used on properties. These will generate the composed function.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is archived
Details
- Warn: Repository is archived.
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
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
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
58 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-3xgq-45jj-v275
- 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-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- 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-6x33-pw7p-hmpq
- 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-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- 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-4xcv-9jjx-gfj3
- 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-7xcx-6wjh-7xp2
- 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
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2025-02-03
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 More