@boost/decorators
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -6,2 +6,18 @@ # Change Log | ||
## 2.1.0 - 2021-01-16 | ||
#### 🚀 Updates | ||
- Migrate to Packemon for package building. (#135) ([1a0e9d8](https://github.com/milesj/boost/commit/1a0e9d8)), closes [#135](https://github.com/milesj/boost/issues/135) | ||
#### 📦 Dependencies | ||
- Update dev dependencies. Migrate to TypeScript v4.1. ([578d5e3](https://github.com/milesj/boost/commit/578d5e3)) | ||
**Note:** Version bump only for package @boost/decorators | ||
# 2.0.0 - 2020-08-17 | ||
@@ -8,0 +24,0 @@ |
108
esm/index.js
@@ -0,1 +1,3 @@ | ||
function _extends() { _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; }; return _extends.apply(this, arguments); } | ||
function isMethod(target, property, descriptor) { | ||
@@ -7,3 +9,3 @@ return Boolean(property && descriptor && typeof descriptor === 'object' && !('initializer' in descriptor) && ('value' in descriptor || 'get' in descriptor)); | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function')) { | ||
@@ -18,4 +20,3 @@ throw new TypeError("`@Bind` may only be applied to class methods."); | ||
get: function get() { | ||
var bound = func.bind(this); // Only cache the bound function when in the deepest sub-class, | ||
// otherwise any `super` calls will overwrite each other. | ||
var bound = func.bind(this); | ||
@@ -38,14 +39,11 @@ if (target.constructor.name === this.constructor.name) { | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function')) { | ||
throw new TypeError("`@Debounce` may only be applied to class methods."); | ||
} | ||
} // We must use a map as all class instances would share the | ||
// same timer value otherwise. | ||
} | ||
var timers = new WeakMap(); | ||
var func = descriptor.value; | ||
var timers = new WeakMap(); // Overwrite the value function with a new debounced function | ||
var func = descriptor.value; // @ts-expect-error | ||
descriptor.value = function debounce() { | ||
@@ -76,2 +74,6 @@ var _this = this; | ||
function isParam(target, property, index) { | ||
return Boolean(property && typeof index === 'number'); | ||
} | ||
function isProperty(target, property, descriptor) { | ||
@@ -81,7 +83,2 @@ return Boolean(property && (descriptor && typeof descriptor === 'object' && 'initializer' in descriptor || descriptor === undefined)); | ||
function isParam(target, property, index) { | ||
return Boolean(property && typeof index === 'number'); | ||
} | ||
/* eslint-disable no-console */ | ||
function Deprecate(message) { | ||
@@ -91,39 +88,19 @@ return function (target, property, descriptor) { | ||
var className = isProtoOrStatic ? target.name : target.constructor.name; | ||
var accessSymbol = isProtoOrStatic ? "." + String(property) : "#" + String(property); // Class | ||
var accessSymbol = isProtoOrStatic ? "." + String(property) : "#" + String(property); | ||
if (isClass(target, property, descriptor)) { | ||
console.debug(message || "Class `" + className + "` has been deprecated."); // Method | ||
console.debug(message || "Class `" + className + "` has been deprecated."); | ||
} else if (isMethod(target, property, descriptor)) { | ||
console.debug(message || "Method `" + (className + accessSymbol) + "()` has been deprecated."); // Property | ||
console.debug(message || "Method `" + (className + accessSymbol) + "()` has been deprecated."); | ||
} else if (isProperty(target, property, descriptor)) { | ||
console.debug(message || "Property `" + (className + accessSymbol) + "` has been deprecated."); // Param (Babel/Jest doesnt support them) | ||
console.debug(message || "Property `" + (className + accessSymbol) + "` has been deprecated."); | ||
} else if (isParam(target, property, descriptor)) { | ||
console.debug(message || "Parameter " + descriptor + " for `" + (className + accessSymbol) + "()` has been deprecated."); | ||
} | ||
/* istanbul ignore next */ | ||
else if (isParam(target, property, descriptor)) { | ||
console.debug(message || "Parameter " + descriptor + " for `" + (className + accessSymbol) + "()` has been deprecated."); | ||
} | ||
}; | ||
} | ||
function _extends() { | ||
_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; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function hasher() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
@@ -135,5 +112,3 @@ | ||
function createMemoizer(method, rootCache, options) { | ||
// Must be a normal function as we require `this` | ||
return function memoizer() { | ||
// Extract the cache for this specific instance | ||
var cache = rootCache.get(this); | ||
@@ -144,7 +119,6 @@ | ||
rootCache.set(this, cache); | ||
} // Hash the key and check the cache | ||
} | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
@@ -157,5 +131,4 @@ | ||
return item.value; | ||
} // No cache so execute and cache the result | ||
} | ||
var value = method.apply(this, args); | ||
@@ -166,3 +139,3 @@ var time = options.expires > 0 ? Date.now() + options.expires : null; | ||
value: value | ||
}); // Only cache if successful | ||
}); | ||
@@ -186,5 +159,4 @@ if (value instanceof Promise) { | ||
// eslint-disable-next-line complexity | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function') && !('get' in descriptor && typeof descriptor.get === 'function')) { | ||
@@ -203,3 +175,3 @@ throw new TypeError("`@Memoize` may only be applied to class methods or getters."); | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (config.cache && !(config.cache instanceof Map)) { | ||
@@ -216,13 +188,9 @@ throw new Error('`cache` must be an instance of `Map`.'); | ||
} | ||
} // We must use a map as all class instances would share the | ||
// same cache otherwise. Probability of collision is high. | ||
} | ||
var rootCache = new WeakMap(); | ||
if (descriptor.get) { | ||
// @ts-expect-error | ||
descriptor.get = createMemoizer(descriptor.get, rootCache, config); | ||
} else if (descriptor.value) { | ||
// @ts-expect-error | ||
descriptor.value = createMemoizer(descriptor.value, rootCache, config); | ||
@@ -235,16 +203,13 @@ } | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function')) { | ||
throw new TypeError("`@Throttle` may only be applied to class methods."); | ||
} | ||
} // We must use a map as all class instances would share the | ||
// same boolean value otherwise. | ||
} | ||
var throttling = new WeakMap(); | ||
var func = descriptor.value; | ||
var throttling = new WeakMap(); // Overwrite the value function with a new throttled function | ||
var func = descriptor.value; // @ts-expect-error | ||
descriptor.value = function throttle() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -255,4 +220,4 @@ if (throttling.get(this)) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
@@ -263,3 +228,3 @@ | ||
setTimeout(function () { | ||
throttling.delete(_this); | ||
throttling.delete(_this2); | ||
}, delay); | ||
@@ -271,1 +236,2 @@ }; | ||
export { Bind, Debounce, Deprecate, Memoize, Throttle }; | ||
//# sourceMappingURL=index.js.map |
112
lib/index.js
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _extends() { _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; }; return _extends.apply(this, arguments); } | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function isMethod(target, property, descriptor) { | ||
@@ -11,3 +15,3 @@ return Boolean(property && descriptor && typeof descriptor === 'object' && !('initializer' in descriptor) && ('value' in descriptor || 'get' in descriptor)); | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function')) { | ||
@@ -22,4 +26,3 @@ throw new TypeError("`@Bind` may only be applied to class methods."); | ||
get: function get() { | ||
var bound = func.bind(this); // Only cache the bound function when in the deepest sub-class, | ||
// otherwise any `super` calls will overwrite each other. | ||
var bound = func.bind(this); | ||
@@ -42,14 +45,11 @@ if (target.constructor.name === this.constructor.name) { | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function')) { | ||
throw new TypeError("`@Debounce` may only be applied to class methods."); | ||
} | ||
} // We must use a map as all class instances would share the | ||
// same timer value otherwise. | ||
} | ||
var timers = new WeakMap(); | ||
var func = descriptor.value; | ||
var timers = new WeakMap(); // Overwrite the value function with a new debounced function | ||
var func = descriptor.value; // @ts-expect-error | ||
descriptor.value = function debounce() { | ||
@@ -80,2 +80,6 @@ var _this = this; | ||
function isParam(target, property, index) { | ||
return Boolean(property && typeof index === 'number'); | ||
} | ||
function isProperty(target, property, descriptor) { | ||
@@ -85,7 +89,2 @@ return Boolean(property && (descriptor && typeof descriptor === 'object' && 'initializer' in descriptor || descriptor === undefined)); | ||
function isParam(target, property, index) { | ||
return Boolean(property && typeof index === 'number'); | ||
} | ||
/* eslint-disable no-console */ | ||
function Deprecate(message) { | ||
@@ -95,39 +94,19 @@ return function (target, property, descriptor) { | ||
var className = isProtoOrStatic ? target.name : target.constructor.name; | ||
var accessSymbol = isProtoOrStatic ? "." + String(property) : "#" + String(property); // Class | ||
var accessSymbol = isProtoOrStatic ? "." + String(property) : "#" + String(property); | ||
if (isClass(target, property, descriptor)) { | ||
console.debug(message || "Class `" + className + "` has been deprecated."); // Method | ||
console.debug(message || "Class `" + className + "` has been deprecated."); | ||
} else if (isMethod(target, property, descriptor)) { | ||
console.debug(message || "Method `" + (className + accessSymbol) + "()` has been deprecated."); // Property | ||
console.debug(message || "Method `" + (className + accessSymbol) + "()` has been deprecated."); | ||
} else if (isProperty(target, property, descriptor)) { | ||
console.debug(message || "Property `" + (className + accessSymbol) + "` has been deprecated."); // Param (Babel/Jest doesnt support them) | ||
console.debug(message || "Property `" + (className + accessSymbol) + "` has been deprecated."); | ||
} else if (isParam(target, property, descriptor)) { | ||
console.debug(message || "Parameter " + descriptor + " for `" + (className + accessSymbol) + "()` has been deprecated."); | ||
} | ||
/* istanbul ignore next */ | ||
else if (isParam(target, property, descriptor)) { | ||
console.debug(message || "Parameter " + descriptor + " for `" + (className + accessSymbol) + "()` has been deprecated."); | ||
} | ||
}; | ||
} | ||
function _extends() { | ||
_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; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function hasher() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
@@ -139,5 +118,3 @@ | ||
function createMemoizer(method, rootCache, options) { | ||
// Must be a normal function as we require `this` | ||
return function memoizer() { | ||
// Extract the cache for this specific instance | ||
var cache = rootCache.get(this); | ||
@@ -148,7 +125,6 @@ | ||
rootCache.set(this, cache); | ||
} // Hash the key and check the cache | ||
} | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
@@ -161,5 +137,4 @@ | ||
return item.value; | ||
} // No cache so execute and cache the result | ||
} | ||
var value = method.apply(this, args); | ||
@@ -170,3 +145,3 @@ var time = options.expires > 0 ? Date.now() + options.expires : null; | ||
value: value | ||
}); // Only cache if successful | ||
}); | ||
@@ -190,5 +165,4 @@ if (value instanceof Promise) { | ||
// eslint-disable-next-line complexity | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function') && !('get' in descriptor && typeof descriptor.get === 'function')) { | ||
@@ -207,3 +181,3 @@ throw new TypeError("`@Memoize` may only be applied to class methods or getters."); | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (config.cache && !(config.cache instanceof Map)) { | ||
@@ -220,13 +194,9 @@ throw new Error('`cache` must be an instance of `Map`.'); | ||
} | ||
} // We must use a map as all class instances would share the | ||
// same cache otherwise. Probability of collision is high. | ||
} | ||
var rootCache = new WeakMap(); | ||
if (descriptor.get) { | ||
// @ts-expect-error | ||
descriptor.get = createMemoizer(descriptor.get, rootCache, config); | ||
} else if (descriptor.value) { | ||
// @ts-expect-error | ||
descriptor.value = createMemoizer(descriptor.value, rootCache, config); | ||
@@ -239,16 +209,13 @@ } | ||
return function (target, property, descriptor) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!isMethod(target, property, descriptor) || !('value' in descriptor && typeof descriptor.value === 'function')) { | ||
throw new TypeError("`@Throttle` may only be applied to class methods."); | ||
} | ||
} // We must use a map as all class instances would share the | ||
// same boolean value otherwise. | ||
} | ||
var throttling = new WeakMap(); | ||
var func = descriptor.value; | ||
var throttling = new WeakMap(); // Overwrite the value function with a new throttled function | ||
var func = descriptor.value; // @ts-expect-error | ||
descriptor.value = function throttle() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -259,4 +226,4 @@ if (throttling.get(this)) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
@@ -267,3 +234,3 @@ | ||
setTimeout(function () { | ||
throttling.delete(_this); | ||
throttling.delete(_this2); | ||
}, delay); | ||
@@ -279,1 +246,2 @@ }; | ||
exports.Throttle = Throttle; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@boost/decorators", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Experimental decorators for common patterns.", | ||
@@ -11,7 +11,12 @@ "keywords": [ | ||
"module": "./esm/index.js", | ||
"types": "./lib/index.d.ts", | ||
"types": "./dts/index.d.ts", | ||
"engines": { | ||
"node": ">=10.17.0" | ||
"node": ">=10.3.0" | ||
}, | ||
"repository": "https://github.com/milesj/boost/tree/master/packages/decorators", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:milesj/boost.git", | ||
"directory": "packages/decorators" | ||
}, | ||
"author": "Miles Johnson", | ||
"license": "MIT", | ||
@@ -25,3 +30,9 @@ "publishConfig": { | ||
}, | ||
"gitHead": "7982950ce80d97d1815234ee0d66b5dc4ac3a843" | ||
"packemon": { | ||
"platform": [ | ||
"browser", | ||
"node" | ||
] | ||
}, | ||
"gitHead": "e2c452ee0c15aa7db91d1945e23ac6951028e672" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
37526
28
1
0
393