Socket
Socket
Sign inDemoInstall

core-decorators

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-decorators - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

package.json
{
"name": "core-decorators",
"version": "0.1.0",
"version": "0.1.1",
"description": "Library of ES7 decorators inspired by languages that come with built-ins like @override, @deprecated, etc",

@@ -5,0 +5,0 @@ "main": "lib/core-decorators.js",

# core-decorators.js [![Build Status](https://travis-ci.org/jayphelps/core-decorators.js.svg?branch=master)](https://travis-ci.org/jayphelps/core-decorators.js)
Library of ES7 decorators inspired by languages that come with built-ins like @​override, @​deprecate, etc, similar to [pre-defined Annotations in Java](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html). Note that unlike Java annotations, decorators are functions which are applied at runtime.
Library of [ES2016 (ES7) decorators](https://github.com/wycats/javascript-decorators) inspired by languages that come with built-ins like @​override, @​deprecate, etc, similar to [pre-defined Annotations in Java](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html). Note that unlike Java annotations, decorators are functions which are applied at runtime.
### Get It
A version compiled to ES5 in CJS format is published to npm as [`core-decorators`](https://www.npmjs.com/package/core-decorators)
```bash
npm install core-decorators --save
```
This form could be consumed by any ES2016 (ES7) transpiler that supports decorators like [babel.js](https://babeljs.io/) with `babel --optional es7.decorators,es7.objectRestSpread` or `babel --stage 1` or using the recent iterations of TypeScript.
_*note that the compiled code is intentionally not checked into this repo_
## Decorators
* [@autobind](#autobind)
* [@readonly](#readonly)
* [@override](#override)
* [@deprecate](#deprecate-alias-deprecated)
* [@suppressWarnings](#suppresswarnings)
* [@memoize](#memoize)
##### Proposed (not implemented, PRs welcome!):
* @mixin
* @instrument/profile
* @debounce
* @throttle
* @private
* @nonenumerable
## Docs
### @autobind
Forces invocations of this function to always have `this` refer to the class instance, even if the function is passed around or would otherwise lose its `this` context. e.g. `var fn = context.method;`
```js
import { autobind } from 'core-decorators';
class Person {
@autobind
getPerson() {
return this;
}
}
let person = new Person();
let getPerson = person.getPerson;
getPerson() === person;
// true
```
### @readonly

@@ -11,10 +62,10 @@

class Woman {
class Hobbit {
@readonly
gender = 'female';
name = 'Bilbo Baggins';
}
var lady = new Woman();
lady.gender = 'male';
// Cannot assign to read only property 'gender' of [object Object]
var bilbo = new Hobbit();
bilbo.name = 'Frodo Baggins';
// Cannot assign to read only property 'name' of [object Object]

@@ -111,23 +162,2 @@ ```

### @autobind
Forces invocations of this function to always have `this` refer to the class instance, even if the function is passed around or would otherwise lose its `this` context. e.g. `var fn = context.method;`
```js
import { autobind } from 'core-decorators';
class Person {
@autobind
getPerson() {
return this;
}
}
let person = new Person();
let getPerson = person.getPerson;
getPerson() === person;
// true
```
### @memoize

@@ -134,0 +164,0 @@

@@ -0,1 +1,3 @@

import { decorate } from './private/utils';
function suppressedWarningNoop() {

@@ -24,2 +26,2 @@ // Warnings are currently suppressed via @suppressWarnings

return decorate(handleDescriptor, arguments);
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc