Registry / devops / decorate

decorate

JSON →
library1.0.0jsnpmunverified

decorate is a lightweight library (v1.0.0) that allows using decorators in JavaScript without needing transpilers like Babel or TypeScript. It provides a `decorate()` function that applies decorators to classes, methods, or properties. It is useful for environments where native decorator syntax is unsupported or to avoid build tooling. The package is stable but has low release cadence. It offers both ESM and CJS exports and works in Node.js and browsers. Differentiator: it enables decorator patterns without transpilation overhead.

npm install decorate
INSTALL
IMPORT
SIG · DECORATE
D
decorate
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (decorate)
import decorate from 'decorate'
const decorate = require('decorate')
ESM default import. The package provides a default export. In CommonJS, use require('decorate').default.

Shows how to import and use decorate to apply class and method decorators without transpiler.

import decorate from 'decorate'; class MyClass { greet() { return 'Hello'; } } // Class decorator function function classDecorator(cls) { cls.prototype.version = '1.0'; } decorate(MyClass, classDecorator); console.log(new MyClass().version); // '1.0' // Method decorator (non-enumerable) function nonenumerable(target, key, descriptor) { descriptor.enumerable = false; return descriptor; } class MyClass2 { secret() { return 'hidden'; } } decorate(MyClass2, 'secret', nonenumerable); console.log(Object.keys(MyClass2.prototype)); // []
Debug
Known issues
gotchadecorate() mutates the class/prototype in place; it does not return a new class.
fix
The class is modified directly; treat it as mutation.
affects: >=0.0.0
gotchadecorate() applies decorators immediately when called, not at decoration time, so order matters.
fix
Apply decorators in the order they should execute.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: decorate is not a function
Using CommonJS require incorrectly; default export is under .default.
fix
Use import decorate from 'decorate' or const decorate = require('decorate').default;
Cannot use decorator on undefined
Decorator is not a function or is applied incorrectly.
fix
Ensure decorator argument is a function (class) or string (method name) followed by decorator function.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
decorate — npm install decorate · libregistry