Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@vates/decorate-with
Advanced tools
Creates a decorator from a function wrapper
Installation of the npm package:
npm install --save @vates/decorate-with
decorateWith(fn, ...args)
Creates a new (legacy) method decorator from a function decorator, for instance, allows using Lodash's functions as decorators:
import { decorateWith } from '@vates/decorate-with'
class Foo {
@decorateWith(lodash.debounce, 150)
bar() {
// body
}
}
decorateClass(class, map)
Decorates a number of accessors and methods directly, without using the decorator syntax:
import { decorateClass } from '@vates/decorate-with'
class Foo {
get bar() {
// body
}
set bar(value) {
// body
}
baz() {
// body
}
}
decorateClass(Foo, {
// getter and/or setter
bar: {
// without arguments
get: lodash.memoize,
// with arguments
set: [lodash.debounce, 150],
},
// method (with or without arguments)
baz: lodash.curry,
})
The decorated class is returned, so you can export it directly.
To apply multiple transforms to an accessor/method, you can either call decorateClass
multiple times or use @vates/compose
:
decorateClass(Foo, {
baz: compose([
[lodash.debounce, 150]
lodash.curry,
])
})
decorateObject(object, map)
Decorates an object the same way decorateClass()
decorates a class:
import { decorateObject } from '@vates/decorate-with'
const object = {
get bar() {
// body
},
set bar(value) {
// body
},
baz() {
// body
},
}
decorateObject(object, {
// getter and/or setter
bar: {
// without arguments
get: lodash.memoize,
// with arguments
set: [lodash.debounce, 150],
},
// method (with or without arguments)
baz: lodash.curry,
})
perInstance(fn, ...args)
Helper to decorate the method by instance instead of for the whole class.
This is often necessary for caching or deduplicating calls.
import { perInstance } from '@vates/decorateWith'
class Foo {
@decorateWith(perInstance, lodash.memoize)
bar() {
// body
}
}
Because it's a normal function, it can also be used with decorateClass
, with compose
or even by itself.
decorateMethodsWith(class, map)
Deprecated alias for
decorateClass(class, map)
.
Contributions are very welcomed, either on the documentation or on the code.
You may:
FAQs
Creates a decorator from a function wrapper
The npm package @vates/decorate-with receives a total of 19 weekly downloads. As such, @vates/decorate-with popularity was classified as not popular.
We found that @vates/decorate-with demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.