Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.11.2 to 0.12.0

lib/applyDecorators.js

6

lib/autobind.js

@@ -63,2 +63,4 @@ 'use strict';

var fn = _ref.value;
var configurable = _ref.configurable;
var enumerable = _ref.enumerable;

@@ -72,4 +74,4 @@ if (typeof fn !== 'function') {

return {
configurable: true,
enumerable: false,
configurable: configurable,
enumerable: enumerable,

@@ -76,0 +78,0 @@ get: function get() {

/**
* core-decorators.js
* (c) 2016 Jay Phelps
* (c) 2016 Jay Phelps and contributors
* MIT Licensed

@@ -76,2 +76,12 @@ * https://github.com/jayphelps/core-decorators.js

exports.time = _interopRequire(_time);
exports.time = _interopRequire(_time);
var _extendDescriptor = require('./extendDescriptor');
exports.extendDescriptor = _interopRequire(_extendDescriptor);
// Helper to apply decorators to a class without transpiler support
var _applyDecorators = require('./applyDecorators');
exports.applyDecorators = _interopRequire(_applyDecorators);

@@ -7,2 +7,4 @@ 'use strict';

var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -12,4 +14,2 @@

function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }
var _privateUtils = require('./private/utils');

@@ -16,0 +16,0 @@

@@ -8,6 +8,6 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _privateUtils = require('./private/utils');

@@ -14,0 +14,0 @@

@@ -7,2 +7,4 @@ 'use strict';

var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -12,4 +14,2 @@

function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }
var _privateUtils = require('./private/utils');

@@ -31,3 +31,3 @@

var methodSignature = '' + target.constructor.name + '#' + key;
var methodSignature = target.constructor.name + '#' + key;

@@ -34,0 +34,0 @@ if (options.url) {

@@ -11,3 +11,3 @@ 'use strict';

function _defineProperty(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -14,0 +14,0 @@ var _privateUtils = require('./private/utils');

@@ -19,37 +19,3 @@ 'use strict';

var SyntaxErrorReporter = (function () {
function SyntaxErrorReporter(parentKlass, childKlass, parentDescriptor, childDescriptor) {
_classCallCheck(this, SyntaxErrorReporter);
this.parentKlass = parentKlass;
this.childKlass = childKlass;
this.parentDescriptor = parentDescriptor;
this.childDescriptor = childDescriptor;
}
_createClass(SyntaxErrorReporter, [{
key: 'key',
get: function () {
return this.childDescriptor.key;
}
}, {
key: 'parentNotation',
get: function () {
return '' + this.parentKlass.constructor.name + '#' + this.parentPropertySignature;
}
}, {
key: 'childNotation',
get: function () {
return '' + this.childKlass.constructor.name + '#' + this.childPropertySignature;
}
}, {
key: 'parentTopic',
get: function () {
return this._getTopic(this.parentDescriptor);
}
}, {
key: 'childTopic',
get: function () {
return this._getTopic(this.childDescriptor);
}
}, {
key: '_getTopic',

@@ -74,12 +40,2 @@ value: function _getTopic(descriptor) {

}, {
key: 'parentPropertySignature',
get: function () {
return this._extractTopicSignature(this.parentTopic);
}
}, {
key: 'childPropertySignature',
get: function () {
return this._extractTopicSignature(this.childTopic);
}
}, {
key: '_extractTopicSignature',

@@ -99,4 +55,4 @@ value: function _extractTopicSignature(topic) {

return fn.toString().replace(FUNCTION_REGEXP, function (match, _x, params) {
var name = arguments[1] === undefined ? _this.key : arguments[1];
return fn.toString().replace(FUNCTION_REGEXP, function (match, name, params) {
if (name === undefined) name = _this.key;
return name + params;

@@ -106,5 +62,51 @@ });

}, {
key: 'key',
get: function get() {
return this.childDescriptor.key;
}
}, {
key: 'parentNotation',
get: function get() {
return this.parentKlass.constructor.name + '#' + this.parentPropertySignature;
}
}, {
key: 'childNotation',
get: function get() {
return this.childKlass.constructor.name + '#' + this.childPropertySignature;
}
}, {
key: 'parentTopic',
get: function get() {
return this._getTopic(this.parentDescriptor);
}
}, {
key: 'childTopic',
get: function get() {
return this._getTopic(this.childDescriptor);
}
}, {
key: 'parentPropertySignature',
get: function get() {
return this._extractTopicSignature(this.parentTopic);
}
}, {
key: 'childPropertySignature',
get: function get() {
return this._extractTopicSignature(this.childTopic);
}
}]);
function SyntaxErrorReporter(parentKlass, childKlass, parentDescriptor, childDescriptor) {
_classCallCheck(this, SyntaxErrorReporter);
this.parentKlass = parentKlass;
this.childKlass = childKlass;
this.parentDescriptor = parentDescriptor;
this.childDescriptor = childDescriptor;
}
_createClass(SyntaxErrorReporter, [{
key: 'assert',
value: function assert(condition) {
var msg = arguments[1] === undefined ? '' : arguments[1];
var msg = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];

@@ -111,0 +113,0 @@ if (condition !== true) {

@@ -6,6 +6,6 @@ 'use strict';

});
var _slice = Array.prototype.slice;
var _createDecoratedClass = (function () { function defineProperties(target, descriptors, initializers) { for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === 'function') { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator); } } if (descriptor.initializer !== undefined) { initializers[key] = descriptor; continue; } } Object.defineProperty(target, key, descriptor); } } return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) { if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers); if (staticProps) defineProperties(Constructor, staticProps, staticInitializers); return Constructor; }; })();
var _slice = Array.prototype.slice;
exports.isDescriptor = isDescriptor;

@@ -19,8 +19,8 @@ exports.decorate = decorate;

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _defineDecoratedPropertyDescriptor(target, key, descriptors) { var _descriptor = descriptors[key]; if (!_descriptor) return; var descriptor = {}; for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; descriptor.value = descriptor.initializer.call(target); Object.defineProperty(target, key, descriptor); }
function _defineDecoratedPropertyDescriptor(target, key, descriptors) { var _descriptor = descriptors[key]; if (!_descriptor) return; var descriptor = {}; for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; descriptor.value = descriptor.initializer ? descriptor.initializer.call(target) : undefined; Object.defineProperty(target, key, descriptor); }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _lazyInitialize = require('../lazy-initialize');

@@ -77,3 +77,3 @@

decorators: [_lazyInitialize2['default']],
initializer: function () {
initializer: function initializer() {
return {};

@@ -85,3 +85,3 @@ },

decorators: [_lazyInitialize2['default']],
initializer: function () {
initializer: function initializer() {
return {};

@@ -93,3 +93,3 @@ },

decorators: [_lazyInitialize2['default']],
initializer: function () {
initializer: function initializer() {
return {};

@@ -96,0 +96,0 @@ },

@@ -13,3 +13,5 @@ 'use strict';

function suppressedWarningNoop() {}
function suppressedWarningNoop() {
// Warnings are currently suppressed via @suppressWarnings
}

@@ -40,4 +42,2 @@ function applyWithoutWarnings(context, fn, args) {

module.exports = exports['default'];
// Warnings are currently suppressed via @suppressWarnings
module.exports = exports['default'];

@@ -7,2 +7,4 @@ 'use strict';

var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -12,4 +14,2 @@

function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }
var _privateUtils = require('./private/utils');

@@ -16,0 +16,0 @@

@@ -7,2 +7,4 @@ 'use strict';

var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -12,4 +14,2 @@

function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }
var _privateUtils = require('./private/utils');

@@ -28,3 +28,3 @@

delete labels[label];
console.log('' + label + ': ' + timeTaken + 'ms');
console.log(label + ': ' + timeTaken + 'ms');
}

@@ -47,3 +47,3 @@ };

if (prefix === null) {
prefix = '' + target.constructor.name + '.' + key;
prefix = target.constructor.name + '.' + key;
}

@@ -57,3 +57,3 @@

value: function value() {
var label = '' + prefix + '-' + count;
var label = prefix + '-' + count;
count++;

@@ -60,0 +60,0 @@ console.time(label);

{
"name": "core-decorators",
"version": "0.11.2",
"version": "0.12.0",
"description": "Library of ES2016 (ES7) JavaScript decorators inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more! Works great with React/Angular/more!",

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

@@ -13,3 +13,3 @@ # core-decorators.js [![Build Status](https://travis-ci.org/jayphelps/core-decorators.js.svg?branch=master)](https://travis-ci.org/jayphelps/core-decorators.js)

This can be consumed by any transpiler that supports stage-0 of the decorators spec, like [babel.js](https://babeljs.io/) version 5 or using the recent iterations of TypeScript. *Babel 6 [does not yet support decorators](https://phabricator.babeljs.io/T2645), use Babel 5 until that is fixed.*
This can be consumed by any transpiler that supports stage-0 of the decorators spec, like [babel.js](https://babeljs.io/) version 5 or using the recent iterations of TypeScript. *Babel 6 [does not yet support decorators](https://phabricator.babeljs.io/T2645), use Babel 5 or the [`applyDecorators()` helper](#applyDecorators) until that is fixed.*

@@ -27,7 +27,8 @@ ##### Bower/globals

* [@nonconfigurable](#nonconfigurable)
* [@decorate](#decorate) :new:
* [@decorate](#decorate)
* [@extendDescriptor](#extendDescriptor) :new:
##### For Properties
* [@nonenumerable](#nonenumerable)
* [@lazyInitialize](#lazyinitialize) :new:
* [@lazyInitialize](#lazyinitialize)

@@ -38,12 +39,16 @@ ##### For Methods

* [@suppressWarnings](#suppresswarnings)
* [@enumerable](#enumerable) :new:
* [@enumerable](#enumerable)
* [@override](#override)
* [@debounce](#debounce)
* [@throttle](#throttle) :new:
* [@time](#time) :new:
* [@throttle](#throttle)
* [@time](#time)
##### For Classes
* [@autobind](#autobind) :new:
* [@mixin](#mixin-alias-mixins) :new:
* [@autobind](#autobind)
* [@mixin](#mixin-alias-mixins)
## Helpers
* [applyDecorators()](#applyDecorators) :new:
## Docs

@@ -299,3 +304,3 @@

Marks a property or method so that it cannot be reconfigured, changed, or deleted.
Marks a property or method so that it cannot be deleted; also prevents it from being reconfigured via `Object.defineProperty`, but **this may not always work how you expect** due to a quirk in JavaScript itself, not this library. Adding the `@readonly` decorator fixes it, but at the cost of obviously making the property readonly (aka `writable: false`). [You can read more about this here.](https://github.com/jayphelps/core-decorators.js/issues/58)

@@ -305,13 +310,12 @@ ```js

class Meal {
class Foo {
@nonconfigurable
entree = 'steak';
@readonly
bar() {};
}
var dinner = new Meal();
Object.defineProperty(dinner, 'entree', {
enumerable: false
Object.defineProperty(Foo.prototype, 'bar', {
value: 'I will error'
});
// Cannot redefine property: entree
// Cannot redefine property: bar

@@ -440,3 +444,55 @@ ```

### @extendDescriptor
Extends the new property descriptor with the descriptor from the super/parent class prototype. Although useful in various circumstances, it's particularly helpful to address the fact that getters and setters share a single descriptor so overriding only a getter or only a setter will blow away the other, without this decorator.
```js
class Base {
@nonconfigurable
get foo() {
return `hello ${this._foo}`;
}
}
class Derived extends Base {
@extendDescriptor
set foo(value) {
this._foo = value;
}
}
const derived = new Derived();
derived.foo = 'bar';
derived.foo === 'hello bar';
// true
const desc = Object.getOwnPropertyDescriptor(Derived.prototype, 'foo');
desc.configurable === false;
// true
```
### applyDecorators() helper
The `applyDecorators()` helper can be used when you don't have language support for decorators like in Babel 6 or even with vanilla ES5 code without a transpiler.
```js
class Foo {
getFoo() {
return this;
}
}
// This works on regular function prototypes
// too, like `function Foo() {}`
applyDecorators(Foo, {
getFoo: [autobind]
});
let foo = new Foo();
let getFoo = foo.getFoo;
getFoo() === foo;
// true
```
# Future Compatibility
Since most people can't keep up to date with specs, it's important to note that the spec is in-flux and subject to breaking changes. In fact, the [biggest change is coming shortly](https://github.com/wycats/javascript-decorators/pull/36) but I am active in the appropriate communities and will be keeping this project up to date as things progress. For the most part, these changes will usually be transparent to consumers of this project--that said, core-decorators has not yet reached 1.0 and may in fact introduce breaking changes. If you'd prefer not to receive these changes, be sure to lock your dependency to [PATCH](http://semver.org/). You can track the progress of core-decorators@1.0.0 in the [The Road to 1.0](https://github.com/jayphelps/core-decorators.js/issues/15) ticket.

@@ -54,3 +54,3 @@ import { decorate, createDefaultSetter, getOwnPropertyDescriptors } from './private/utils';

function autobindMethod(target, key, { value: fn }) {
function autobindMethod(target, key, { value: fn, configurable, enumerable }) {
if (typeof fn !== 'function') {

@@ -63,4 +63,4 @@ throw new SyntaxError(`@autobind can only be used on functions, not: ${fn}`);

return {
configurable: true,
enumerable: false,
configurable,
enumerable,

@@ -67,0 +67,0 @@ get() {

/**
* core-decorators.js
* (c) 2016 Jay Phelps
* (c) 2016 Jay Phelps and contributors
* MIT Licensed

@@ -23,1 +23,5 @@ * https://github.com/jayphelps/core-decorators.js

export { default as time } from './time';
export { default as extendDescriptor } from './extendDescriptor';
// Helper to apply decorators to a class without transpiler support
export { default as applyDecorators } from './applyDecorators';
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