Useful ES2016/ES7 decorators.
These are stage-0 decorators because while the decorators spec has changed and is now stage-2, no transpiler has yet to implement these changes and until they do, this library won't either. Although the TypeScript documentation uses the phrase "Decorators are a stage 2 proposal for JavaScript" this is misleading because TypeScript still only implements the stage-0 version of the spec, which is very incompatible with stage-2 (as of this writing).
*compiled code is intentionally not checked into this repo
A version compiled to ES5 in CJS format is published to npm as dcoo
# npm install dcoo --save // not yet published
npm install https://github.com/rjoydip/dcoo.git
This can be consumed by any transpiler that supports stage-0 of the decorators spec, like babel.js version 5. Babel 6 does not yet support decorators natively, but you can include babel-plugin-transform-decorators-legacy.
dcoo does not officially support TypeScript. There are known incompatibilities with the way it transpiles the output. PRs certainly welcome to fix that!
Calls console.log()
, console.warn()
, console.error()
,console.info()
with a log message. Provide a custom message to override the default one. You can also provide an options hash with a url
, for further reading.
import { logger } from "dcoo";
class Logger {
@logger("logger msg", {
type: "info"
})
loggerFn() {}
}
let logger = new Logger();
logger.loggerFn();
// Logger#loggerFn: logger msg