Gathering detailed insights and metrics for lodash-decorators-esm
Gathering detailed insights and metrics for lodash-decorators-esm
Gathering detailed insights and metrics for lodash-decorators-esm
Gathering detailed insights and metrics for lodash-decorators-esm
npm install lodash-decorators-esm
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
32,262
Last Day
55
Last Week
227
Last Month
1,254
Last Year
11,993
1 Stars
214 Commits
16 Branches
1 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
Decorators using lodash functions. View the API docs for more in depth documentation.
npm install --save lodash-es lodash-decorators-es
This library requires Map
and WeakMap
to be available globally. If Map
or WeakMap
is not supported in your environment then use a polyfill.
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';
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
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}
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.
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}
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.
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
You can use methods like compose
and flow
similiar to
partials. The arguments are resolved the same way partials
are resolved.
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
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
You can mixin methods into a class by using the Mixin
decorator.
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
You can wrap a method in a lodash attempt method.
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 takes arguments based on lodash's bind and binds the Function
to
the current instance object.
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
.
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
Version 4 is a rewrite of the library and has many breaking changes.
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
.
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. 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.
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.
If a prototype decorator comes after an instance decorator it will be ignored since there is no way to apply it in the chain.
Attempt
now takes an argument to line up with lodash API.Bind
used on a class no longer delegates to BindAll
. Use BindAll
instead.Curry
, Partial
, Flow
, FlowRight
are now instance decorators.import { Debounce } from 'lodash-decorators-esm/debounce'
;No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
no SAST tool detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
58 existing vulnerabilities detected
Details
Score
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