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

kashe

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kashe - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

4

dist/es2015/utils.js

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

export var isWeakable = function (value) { return (value && (typeof value === 'object')); };
export var isWeakable = function (value) { return (value && (typeof value === 'object')
// || typeof value === 'function' // not using function to prevent leaks
); };

@@ -7,5 +7,21 @@ import { WeakStorage } from "./types";

declare type BoxedCall<T extends any[], K> = (state: object, ...rest: T) => K;
/**
* Prepends function with an additional argument, which would be used as a "box" key layer
* @param fn
*/
export declare function boxed<T extends any[], K>(fn: (...args: T) => K): BoxedCall<T, K>;
/**
* Prepends function with an additional argument, which would be used as "cache-dimension" key later
* @param fn
*/
export declare function inboxed<T extends any[], K>(fn: (...args: T) => K): BoxedCall<T, K>;
export declare function fork<T extends any[], K>(fn: (...args: T) => K): (...args: T) => K;
/**
* Forks internal cache, creating another cache dimension
* @param fn - function to memoize
* @param [options]
* @param [options.singleton=false] force single variant for an internal cache
*/
export declare function fork<T extends any[], K>(fn: (...args: T) => K, options?: {
singleton?: boolean;
}): (...args: T) => K;
export {};

@@ -28,3 +28,6 @@ import functionDouble from "function-double";

if (cacheCreator === void 0) { cacheCreator = createWeakStorage; }
return function kasheCreator(func, cache) {
/**
* memoizes a function
*/
return function kashe(func, cache) {
if (cache === void 0) { cache = cacheCreator(); }

@@ -42,3 +45,5 @@ var _this_ = { func: func };

}
return localCache.set(args, func.apply(void 0, args));
return localCache.set(args,
// @ts-ignore
func.apply(void 0, args));
}, func, { name: addKashePrefix });

@@ -62,3 +67,5 @@ };

}
return localCache.set(cacheArg, func.apply(void 0, args));
return localCache.set(cacheArg,
// @ts-ignore
func.apply(void 0, args));
};

@@ -69,2 +76,6 @@ }

}
/**
* Prepends function with an additional argument, which would be used as a "box" key layer
* @param fn
*/
export function boxed(fn) {

@@ -80,2 +91,6 @@ return kashe(function (_) {

var localCacheCreator = kashe(function (_) { return createWeakStorage(); });
/**
* Prepends function with an additional argument, which would be used as "cache-dimension" key later
* @param fn
*/
export function inboxed(fn) {

@@ -106,4 +121,11 @@ var factory = weakKasheFactory(function (cacheVariation) {

}
export function fork(fn) {
/**
* Forks internal cache, creating another cache dimension
* @param fn - function to memoize
* @param [options]
* @param [options.singleton=false] force single variant for an internal cache
*/
export function fork(fn, options) {
var cache = localCacheCreator({});
var genLocalCache = function () { return localCacheCreator({}); };
return function () {

@@ -115,3 +137,3 @@ var rest = [];

try {
pushCache(cache);
pushCache((!options || !options.singleton && getCacheFor(cache, genLocalCache)) || cache);
return fn.apply(void 0, rest);

@@ -118,0 +140,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWeakable = function (value) { return (value && (typeof value === 'object')); };
exports.isWeakable = function (value) { return (value && (typeof value === 'object')
// || typeof value === 'function' // not using function to prevent leaks
); };

@@ -7,5 +7,21 @@ import { WeakStorage } from "./types";

declare type BoxedCall<T extends any[], K> = (state: object, ...rest: T) => K;
/**
* Prepends function with an additional argument, which would be used as a "box" key layer
* @param fn
*/
export declare function boxed<T extends any[], K>(fn: (...args: T) => K): BoxedCall<T, K>;
/**
* Prepends function with an additional argument, which would be used as "cache-dimension" key later
* @param fn
*/
export declare function inboxed<T extends any[], K>(fn: (...args: T) => K): BoxedCall<T, K>;
export declare function fork<T extends any[], K>(fn: (...args: T) => K): (...args: T) => K;
/**
* Forks internal cache, creating another cache dimension
* @param fn - function to memoize
* @param [options]
* @param [options.singleton=false] force single variant for an internal cache
*/
export declare function fork<T extends any[], K>(fn: (...args: T) => K, options?: {
singleton?: boolean;
}): (...args: T) => K;
export {};

@@ -30,3 +30,6 @@ "use strict";

if (cacheCreator === void 0) { cacheCreator = weakStorage_1.createWeakStorage; }
return function kasheCreator(func, cache) {
/**
* memoizes a function
*/
return function kashe(func, cache) {
if (cache === void 0) { cache = cacheCreator(); }

@@ -44,3 +47,5 @@ var _this_ = { func: func };

}
return localCache.set(args, func.apply(void 0, args));
return localCache.set(args,
// @ts-ignore
func.apply(void 0, args));
}, func, { name: addKashePrefix });

@@ -65,3 +70,5 @@ };

}
return localCache.set(cacheArg, func.apply(void 0, args));
return localCache.set(cacheArg,
// @ts-ignore
func.apply(void 0, args));
};

@@ -73,2 +80,6 @@ }

exports.swap = swap;
/**
* Prepends function with an additional argument, which would be used as a "box" key layer
* @param fn
*/
function boxed(fn) {

@@ -85,2 +96,6 @@ return exports.kashe(function (_) {

var localCacheCreator = exports.kashe(function (_) { return weakStorage_1.createWeakStorage(); });
/**
* Prepends function with an additional argument, which would be used as "cache-dimension" key later
* @param fn
*/
function inboxed(fn) {

@@ -112,4 +127,11 @@ var factory = weakKasheFactory(function (cacheVariation) {

exports.inboxed = inboxed;
function fork(fn) {
/**
* Forks internal cache, creating another cache dimension
* @param fn - function to memoize
* @param [options]
* @param [options.singleton=false] force single variant for an internal cache
*/
function fork(fn, options) {
var cache = localCacheCreator({});
var genLocalCache = function () { return localCacheCreator({}); };
return function () {

@@ -121,3 +143,3 @@ var rest = [];

try {
pushCache(cache);
pushCache((!options || !options.singleton && getCacheFor(cache, genLocalCache)) || cache);
return fn.apply(void 0, rest);

@@ -124,0 +146,0 @@ }

{
"name": "kashe",
"version": "0.1.3",
"version": "0.2.0",
"description": "Stateless memoization replacement for reselect and memoize-one",

@@ -5,0 +5,0 @@ "main": "dist/es5/index.js",

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