@dhmk/utils
Advanced tools
Comparing version 4.4.0 to 4.4.1
@@ -44,2 +44,3 @@ import { StrKeyOf, DeepReadonly, DeepPartial } from "./types"; | ||
export declare function overwrite<T extends object>(x: T, fn: (x: T) => Partial<T>): T; | ||
export declare function memoize<A extends any[], R>(fn: (...args: A) => R): (...args: A) => R; | ||
export {}; |
@@ -156,1 +156,18 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
export function memoize(fn) { | ||
var prevArgs; | ||
var prevResult; | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (prevArgs && arraysEqual(prevArgs, args)) { | ||
return prevResult; | ||
} | ||
prevArgs = undefined; // in case of exception | ||
prevResult = fn.apply(void 0, args); | ||
prevArgs = args; | ||
return prevResult; | ||
}; | ||
} |
@@ -44,2 +44,3 @@ import { StrKeyOf, DeepReadonly, DeepPartial } from "./types"; | ||
export declare function overwrite<T extends object>(x: T, fn: (x: T) => Partial<T>): T; | ||
export declare function memoize<A extends any[], R>(fn: (...args: A) => R): (...args: A) => R; | ||
export {}; |
@@ -23,3 +23,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.overwrite = exports.diff = exports.flatMap = exports.isPlainObject = exports.assert = exports.namespace = exports.join = exports.mergeDeep = exports.merge = exports.deepReadonly = exports.call = exports.createFactoryAs = exports.createFactory = exports.getter = exports.objectTransform = exports.objectMap = exports.objectFrom = exports.shallowEqual = exports.arraysEqual = exports.range = exports.id = exports.noop = void 0; | ||
exports.memoize = exports.overwrite = exports.diff = exports.flatMap = exports.isPlainObject = exports.assert = exports.namespace = exports.join = exports.mergeDeep = exports.merge = exports.deepReadonly = exports.call = exports.createFactoryAs = exports.createFactory = exports.getter = exports.objectTransform = exports.objectMap = exports.objectFrom = exports.shallowEqual = exports.arraysEqual = exports.range = exports.id = exports.noop = void 0; | ||
var noop = function () { }; | ||
@@ -182,1 +182,19 @@ exports.noop = noop; | ||
exports.overwrite = overwrite; | ||
function memoize(fn) { | ||
var prevArgs; | ||
var prevResult; | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (prevArgs && (0, exports.arraysEqual)(prevArgs, args)) { | ||
return prevResult; | ||
} | ||
prevArgs = undefined; // in case of exception | ||
prevResult = fn.apply(void 0, args); | ||
prevArgs = args; | ||
return prevResult; | ||
}; | ||
} | ||
exports.memoize = memoize; |
{ | ||
"name": "@dhmk/utils", | ||
"version": "4.4.0", | ||
"version": "4.4.1", | ||
"description": "A collection of frequently used functions and primitives", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
133713
3099