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

@boost/decorators

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boost/decorators - npm Package Compare versions

Comparing version 2.1.4 to 3.0.0

132

esm/index.js

@@ -1,13 +0,5 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
// Bundled with Packemon: https://packemon.dev
// Platform: browser, Support: legacy, Format: esm
// Platform: browser, Support: stable, Format: esm
function isMethod(target, property, descriptor) {
return Boolean(property && descriptor && _typeof(descriptor) === 'object' && !('initializer' in descriptor) && ('value' in descriptor || 'get' in descriptor));
return Boolean(property && descriptor && typeof descriptor === 'object' && !('initializer' in descriptor) && ('value' in descriptor || 'get' in descriptor));
}

@@ -21,12 +13,13 @@ /**

function Bind() {
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function'))) {
throw new TypeError("`@Bind` may only be applied to class methods.");
throw new TypeError(`\`@Bind\` may only be applied to class methods.`);
}
var func = descriptor.value;
const func = descriptor.value;
return {
configurable: true,
get: function get() {
var bound = func.bind(this); // Only cache the bound function when in the deepest sub-class,
get() {
const bound = func.bind(this); // Only cache the bound function when in the deepest sub-class,
// otherwise any `super` calls will overwrite each other.

@@ -45,2 +38,3 @@

}
};

@@ -56,5 +50,5 @@ };

function Debounce(delay) {
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function'))) {
throw new TypeError("`@Debounce` may only be applied to class methods.");
throw new TypeError(`\`@Debounce\` may only be applied to class methods.`);
} // We must use a map as all class instances would share the

@@ -64,15 +58,9 @@ // same timer value otherwise.

var timers = new WeakMap(); // Overwrite the value function with a new debounced function
const timers = new WeakMap(); // Overwrite the value function with a new debounced function
var func = descriptor.value; // @ts-expect-error Override generic
const func = descriptor.value; // @ts-expect-error Override generic
descriptor.value = function debounce() {
var _this = this;
descriptor.value = function debounce(...args) {
const timer = timers.get(this);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var timer = timers.get(this);
if (timer) {

@@ -83,4 +71,4 @@ clearTimeout(timer);

timers.set(this, setTimeout(function () {
func.apply(_this, args);
timers.set(this, setTimeout(() => {
func.apply(this, args);
}, delay));

@@ -100,3 +88,3 @@ };

function isProperty(target, property, descriptor) {
return Boolean(property && (descriptor && _typeof(descriptor) === 'object' && 'initializer' in descriptor || descriptor === undefined));
return Boolean(property && (descriptor && typeof descriptor === 'object' && 'initializer' in descriptor || descriptor === undefined));
}

@@ -113,17 +101,17 @@ /* eslint-disable no-console */

function Deprecate(message) {
return function (target, property, descriptor) {
var isProtoOrStatic = typeof target === 'function';
var className = isProtoOrStatic ? target.name : target.constructor.name;
var accessSymbol = isProtoOrStatic ? ".".concat(String(property)) : "#".concat(String(property)); // Class
return (target, property, descriptor) => {
const isProtoOrStatic = typeof target === 'function';
const className = isProtoOrStatic ? target.name : target.constructor.name;
const accessSymbol = isProtoOrStatic ? `.${String(property)}` : `#${String(property)}`; // Class
if (isClass(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Class `".concat(className, "` has been deprecated.")); // Method
console.debug(message !== null && message !== void 0 ? message : `Class \`${className}\` has been deprecated.`); // Method
} else if (isMethod(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Method `".concat(className + accessSymbol, "()` has been deprecated.")); // Property
console.debug(message !== null && message !== void 0 ? message : `Method \`${className + accessSymbol}()\` has been deprecated.`); // Property
} else if (isProperty(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Property `".concat(className + accessSymbol, "` has been deprecated.")); // Param (Babel/Jest doesnt support them)
console.debug(message !== null && message !== void 0 ? message : `Property \`${className + accessSymbol}\` has been deprecated.`); // Param (Babel/Jest doesnt support them)
}
/* istanbul ignore next */
else if (isParam(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Parameter ".concat(descriptor, " for `").concat(className + accessSymbol, "()` has been deprecated."));
console.debug(message !== null && message !== void 0 ? message : `Parameter ${descriptor} for \`${className + accessSymbol}()\` has been deprecated.`);
}

@@ -133,7 +121,3 @@ };

function hasher() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
function hasher(...args) {
return JSON.stringify(args);

@@ -144,5 +128,5 @@ }

// Must be a normal function as we require `this`
return function memoizer() {
return function memoizer(...args) {
// Extract the cache for this specific instance
var cache = rootCache.get(this);
let cache = rootCache.get(this);

@@ -155,9 +139,5 @@ if (!cache) {

for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
const key = options.hasher(...args);
const item = cache.get(key);
var key = options.hasher.apply(options, args);
var item = cache.get(key);
if (item && (!item.time || typeof item.time === 'number' && item.time > Date.now())) {

@@ -168,7 +148,7 @@ return item.value;

var value = method.apply(this, args);
var time = options.expires > 0 ? Date.now() + options.expires : null;
const value = method.apply(this, args);
const time = options.expires > 0 ? Date.now() + options.expires : null;
cache.set(key, {
time: time,
value: value
time,
value
}); // Only cache if successful

@@ -178,3 +158,3 @@

// eslint-disable-next-line promise/prefer-await-to-then
value.catch(function () {
value.catch(() => {
var _cache;

@@ -195,17 +175,17 @@

function Memoize() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function Memoize(options = {}) {
// eslint-disable-next-line complexity
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function') && !('get' in descriptor && typeof descriptor.get === 'function'))) {
throw new TypeError("`@Memoize` may only be applied to class methods or getters.");
throw new TypeError(`\`@Memoize\` may only be applied to class methods or getters.`);
}
var config = _objectSpread({
const config = {
cache: null,
expires: 0,
hasher: hasher
}, typeof options === 'function' ? {
hasher: options
} : options);
hasher,
...(typeof options === 'function' ? {
hasher: options
} : options)
};

@@ -228,3 +208,3 @@ if (process.env.NODE_ENV !== "production") {

var rootCache = new WeakMap();
const rootCache = new WeakMap();

@@ -247,5 +227,5 @@ if (descriptor.get) {

function Throttle(delay) {
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function'))) {
throw new TypeError("`@Throttle` may only be applied to class methods.");
throw new TypeError(`\`@Throttle\` may only be applied to class methods.`);
} // We must use a map as all class instances would share the

@@ -255,9 +235,7 @@ // same boolean value otherwise.

var throttling = new WeakMap(); // Overwrite the value function with a new throttled function
const throttling = new WeakMap(); // Overwrite the value function with a new throttled function
var func = descriptor.value; // @ts-expect-error Override generic
const func = descriptor.value; // @ts-expect-error Override generic
descriptor.value = function throttle() {
var _this2 = this;
descriptor.value = function throttle(...args) {
if (throttling.get(this)) {

@@ -267,10 +245,6 @@ return;

for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
func.apply(this, args);
throttling.set(this, true);
setTimeout(function () {
throttling.delete(_this2);
setTimeout(() => {
throttling.delete(this);
}, delay);

@@ -277,0 +251,0 @@ };

// Bundled with Packemon: https://packemon.dev
// Platform: browser, Support: legacy, Format: lib
// Platform: browser, Support: stable, Format: lib
'use strict';
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, '__esModule', {

@@ -18,3 +10,3 @@ value: true

function isMethod(target, property, descriptor) {
return Boolean(property && descriptor && _typeof(descriptor) === 'object' && !('initializer' in descriptor) && ('value' in descriptor || 'get' in descriptor));
return Boolean(property && descriptor && typeof descriptor === 'object' && !('initializer' in descriptor) && ('value' in descriptor || 'get' in descriptor));
}

@@ -28,12 +20,13 @@ /**

function Bind() {
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function'))) {
throw new TypeError("`@Bind` may only be applied to class methods.");
throw new TypeError(`\`@Bind\` may only be applied to class methods.`);
}
var func = descriptor.value;
const func = descriptor.value;
return {
configurable: true,
get: function get() {
var bound = func.bind(this); // Only cache the bound function when in the deepest sub-class,
get() {
const bound = func.bind(this); // Only cache the bound function when in the deepest sub-class,
// otherwise any `super` calls will overwrite each other.

@@ -52,2 +45,3 @@

}
};

@@ -63,5 +57,5 @@ };

function Debounce(delay) {
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function'))) {
throw new TypeError("`@Debounce` may only be applied to class methods.");
throw new TypeError(`\`@Debounce\` may only be applied to class methods.`);
} // We must use a map as all class instances would share the

@@ -71,15 +65,9 @@ // same timer value otherwise.

var timers = new WeakMap(); // Overwrite the value function with a new debounced function
const timers = new WeakMap(); // Overwrite the value function with a new debounced function
var func = descriptor.value; // @ts-expect-error Override generic
const func = descriptor.value; // @ts-expect-error Override generic
descriptor.value = function debounce() {
var _this = this;
descriptor.value = function debounce(...args) {
const timer = timers.get(this);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var timer = timers.get(this);
if (timer) {

@@ -90,4 +78,4 @@ clearTimeout(timer);

timers.set(this, setTimeout(function () {
func.apply(_this, args);
timers.set(this, setTimeout(() => {
func.apply(this, args);
}, delay));

@@ -107,3 +95,3 @@ };

function isProperty(target, property, descriptor) {
return Boolean(property && (descriptor && _typeof(descriptor) === 'object' && 'initializer' in descriptor || descriptor === undefined));
return Boolean(property && (descriptor && typeof descriptor === 'object' && 'initializer' in descriptor || descriptor === undefined));
}

@@ -120,17 +108,17 @@ /* eslint-disable no-console */

function Deprecate(message) {
return function (target, property, descriptor) {
var isProtoOrStatic = typeof target === 'function';
var className = isProtoOrStatic ? target.name : target.constructor.name;
var accessSymbol = isProtoOrStatic ? ".".concat(String(property)) : "#".concat(String(property)); // Class
return (target, property, descriptor) => {
const isProtoOrStatic = typeof target === 'function';
const className = isProtoOrStatic ? target.name : target.constructor.name;
const accessSymbol = isProtoOrStatic ? `.${String(property)}` : `#${String(property)}`; // Class
if (isClass(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Class `".concat(className, "` has been deprecated.")); // Method
console.debug(message !== null && message !== void 0 ? message : `Class \`${className}\` has been deprecated.`); // Method
} else if (isMethod(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Method `".concat(className + accessSymbol, "()` has been deprecated.")); // Property
console.debug(message !== null && message !== void 0 ? message : `Method \`${className + accessSymbol}()\` has been deprecated.`); // Property
} else if (isProperty(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Property `".concat(className + accessSymbol, "` has been deprecated.")); // Param (Babel/Jest doesnt support them)
console.debug(message !== null && message !== void 0 ? message : `Property \`${className + accessSymbol}\` has been deprecated.`); // Param (Babel/Jest doesnt support them)
}
/* istanbul ignore next */
else if (isParam(target, property, descriptor)) {
console.debug(message !== null && message !== void 0 ? message : "Parameter ".concat(descriptor, " for `").concat(className + accessSymbol, "()` has been deprecated."));
console.debug(message !== null && message !== void 0 ? message : `Parameter ${descriptor} for \`${className + accessSymbol}()\` has been deprecated.`);
}

@@ -140,7 +128,3 @@ };

function hasher() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
function hasher(...args) {
return JSON.stringify(args);

@@ -151,5 +135,5 @@ }

// Must be a normal function as we require `this`
return function memoizer() {
return function memoizer(...args) {
// Extract the cache for this specific instance
var cache = rootCache.get(this);
let cache = rootCache.get(this);

@@ -162,9 +146,5 @@ if (!cache) {

for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
const key = options.hasher(...args);
const item = cache.get(key);
var key = options.hasher.apply(options, args);
var item = cache.get(key);
if (item && (!item.time || typeof item.time === 'number' && item.time > Date.now())) {

@@ -175,7 +155,7 @@ return item.value;

var value = method.apply(this, args);
var time = options.expires > 0 ? Date.now() + options.expires : null;
const value = method.apply(this, args);
const time = options.expires > 0 ? Date.now() + options.expires : null;
cache.set(key, {
time: time,
value: value
time,
value
}); // Only cache if successful

@@ -185,3 +165,3 @@

// eslint-disable-next-line promise/prefer-await-to-then
value.catch(function () {
value.catch(() => {
var _cache;

@@ -202,17 +182,17 @@

function Memoize() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function Memoize(options = {}) {
// eslint-disable-next-line complexity
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function') && !('get' in descriptor && typeof descriptor.get === 'function'))) {
throw new TypeError("`@Memoize` may only be applied to class methods or getters.");
throw new TypeError(`\`@Memoize\` may only be applied to class methods or getters.`);
}
var config = _objectSpread({
const config = {
cache: null,
expires: 0,
hasher: hasher
}, typeof options === 'function' ? {
hasher: options
} : options);
hasher,
...(typeof options === 'function' ? {
hasher: options
} : options)
};

@@ -235,3 +215,3 @@ if (process.env.NODE_ENV !== "production") {

var rootCache = new WeakMap();
const rootCache = new WeakMap();

@@ -254,5 +234,5 @@ if (descriptor.get) {

function Throttle(delay) {
return function (target, property, descriptor) {
return (target, property, descriptor) => {
if (process.env.NODE_ENV !== "production" && (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function'))) {
throw new TypeError("`@Throttle` may only be applied to class methods.");
throw new TypeError(`\`@Throttle\` may only be applied to class methods.`);
} // We must use a map as all class instances would share the

@@ -262,9 +242,7 @@ // same boolean value otherwise.

var throttling = new WeakMap(); // Overwrite the value function with a new throttled function
const throttling = new WeakMap(); // Overwrite the value function with a new throttled function
var func = descriptor.value; // @ts-expect-error Override generic
const func = descriptor.value; // @ts-expect-error Override generic
descriptor.value = function throttle() {
var _this2 = this;
descriptor.value = function throttle(...args) {
if (throttling.get(this)) {

@@ -274,10 +252,6 @@ return;

for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
func.apply(this, args);
throttling.set(this, true);
setTimeout(function () {
throttling.delete(_this2);
setTimeout(() => {
throttling.delete(this);
}, delay);

@@ -284,0 +258,0 @@ };

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

var isMethod = require('./helpers/isMethod.js');
const isMethod = require('./helpers/isMethod.js');
/**

@@ -10,0 +10,0 @@ * A method decorator that automatically binds a class method's

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

var isMethod = require('./helpers/isMethod.js');
const isMethod = require('./helpers/isMethod.js');
/**

@@ -10,0 +10,0 @@ * A method decorator that delays the execution of the class method

@@ -7,9 +7,9 @@ 'use strict';

var isClass = require('./helpers/isClass.js');
const isClass = require('./helpers/isClass.js');
var isMethod = require('./helpers/isMethod.js');
const isMethod = require('./helpers/isMethod.js');
var isParam = require('./helpers/isParam.js');
const isParam = require('./helpers/isParam.js');
var isProperty = require('./helpers/isProperty.js');
const isProperty = require('./helpers/isProperty.js');
/* eslint-disable no-console */

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

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

var Bind = require('./Bind.js');
const Bind = require('./Bind.js');
var Debounce = require('./Debounce.js');
const Debounce = require('./Debounce.js');
var Deprecate = require('./Deprecate.js');
const Deprecate = require('./Deprecate.js');
var Memoize = require('./Memoize.js');
const Memoize = require('./Memoize.js');
var Throttle = require('./Throttle.js');
const Throttle = require('./Throttle.js');
/**

@@ -18,0 +18,0 @@ * @copyright 2020, Miles Johnson

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

var isMethod = require('./helpers/isMethod.js');
const isMethod = require('./helpers/isMethod.js');

@@ -16,0 +16,0 @@ function hasher(...args) {

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

var isMethod = require('./helpers/isMethod.js');
const isMethod = require('./helpers/isMethod.js');
/**

@@ -10,0 +10,0 @@ * A method decorator that throttles the execution of a class method to

{
"name": "@boost/decorators",
"version": "2.1.4",
"version": "3.0.0",
"description": "Experimental decorators for common patterns.",

@@ -20,4 +20,4 @@ "keywords": [

"engines": {
"node": ">=10.3.0",
"npm": ">=6.1.0"
"node": ">=12.17.0",
"npm": ">=6.13.0"
},

@@ -43,3 +43,2 @@ "repository": {

],
"support": "legacy",
"platform": [

@@ -50,3 +49,3 @@ "browser",

},
"gitHead": "a44772937c04f8f818884444faee5c2a9f44b5ac"
"gitHead": "3934541f918ab3c6a1b53e34f302121ccdd23b83"
}

@@ -16,3 +16,3 @@ /* eslint-disable no-console */

const isProtoOrStatic = typeof target === 'function';
const className = isProtoOrStatic ? (target as Function).name : target.constructor.name;
const className = isProtoOrStatic ? target.name : target.constructor.name;
const accessSymbol = isProtoOrStatic ? `.${String(property)}` : `#${String(property)}`;

@@ -19,0 +19,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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