![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
lodash-decorators
Advanced tools
ES7 Decorators for lodash functions.
npm install --save lodash-decorators
For more in depth documentation please visit Lodash
Many of the lodash decorators can contain arguments.
debounce
throttle
memoize
after
before
ary
curry
curryRight
restParam
partial
partialRight
wrap
compose
flow
flowRight
backflow
delay
defer
import { after, debounce, memoize, curry } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@after(3)
@debounce(100)
getFullName() {
return `${this.firstName} ${this.lastName}`
}
@curry(2)
@memoize()
doSomeHeavyProcessing(arg1, arg2) {
}
}
Some decorators don't take any arguments at all.
once
spread
rearg
negate
bind
import { once } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@once
getFullName() {
return `${this.firstName} ${this.lastName}`
}
}
Some decorators work slightly differently than you would expect them to work than lodash.
partial
partialRight
wrap
These decorators take a String
argument as their first parameter
instead of a Function
. The argument is the name of a function on the
object you wish to partially apply arguments to.
import { partial } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getName(type) {
return type === 'firstName' ? this.firstName : this.lastName
}
@partial('getName', 'firstName')
getFirstName() {}
@partial('getName', null)
getLastName() {}
}
const person = new Person('Joe', 'Smith');
person.getFirstName(); // 'Joe'
person.getLastName(); // 'Smith'
Wraps work the same way as partials by taking a String
argument
of the function you wish to wrap.
import { wrap } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getName() {
return `${this.firstName} ${this.lastName}`;
}
@wrap('getName')
getUpperCaseName(fn) {
return fn().toUpperCase();
}
}
const person = new Person('Joe', 'Smith');
person.getUpperCaseName(); // JOE SMITH
You can use methods like compose
and flow
similiar to
partials. It takes any number of String
arguments that resolve
to Function
s on the object.
import { compose } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getName() {
return `${this.firstName} ${this.lastName}`;
}
upperCaseName(name) {
return name.toUpperCase();
}
@compose('upperCaseName', 'getName')
logName(name) {
console.log(name);
}
}
const person = new Person('Joe', 'Smith');
person.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
When apply a decorator to a getter, a special annotation is required to distinguish between a getter property and an instance decorator.
getter
import { getter, debounce } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@getter
@debounce(100)
get name() {
return `${this.firstName} ${this.lastName}`;
}
}
Bind takes arguments based on lodash's bind and binds the Function
to
the current instance object.
import { bind } from 'lodash-decorators'
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@bind()
getName() {
return `${this.firstName} ${this.lastName}`;
}
// It can also function as a partial
@bind('Joe')
getUpperCaseName(name) {
return name.toUpperCase();
}
}
const person = new Person('Joe', 'Smith');
person.getName.call(null); // Joe Smith
person.getUpperCaseName(); // JOE
You can also bind entire classes.
import { bind } from 'lodash-decorators'
@bind()
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getName() {
return `${this.firstName} ${this.lastName}`;
}
}
const person = new Person('Joe', 'Smith');
person.getName.call(null); // Joe Smith
Author: Steven Sojka MIT Licensed
FAQs
A collection of decorators using lodash at it's core.
The npm package lodash-decorators receives a total of 87,325 weekly downloads. As such, lodash-decorators popularity was classified as popular.
We found that lodash-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.