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 1.1.0 to 1.2.0

4

dist/es2015/strongStorage.d.ts

@@ -1,2 +0,2 @@

import { WeakMappable, WeakStorage } from "./types";
export declare const createStrongStorage: (startIndex?: number, endIndex?: number, storage?: WeakMappable) => WeakStorage;
import { Mappable, WeakStorage } from "./types";
export declare const createStrongStorage: (startIndex?: number, endIndex?: number, storage?: Mappable) => WeakStorage;

@@ -8,5 +8,5 @@ export interface WeakResult {

}
export interface WeakMappable<T = any> {
export interface Mappable<T = any> {
get(key: any): T | undefined;
set(set: any, value: T): void;
}

@@ -1,9 +0,9 @@

import { WeakMappable, WeakStorage } from "./types";
import { Mappable, WeakStorage } from "./types";
export declare const breakdownArgs: (args: any[]) => any[];
declare type Test = {
arguments?: any[];
storedValue?: any;
storage?: WeakMappable<Test>;
strong?: Mappable<Test>;
weak?: Mappable<Test>;
};
export declare const createWeakStorage: (storage?: WeakMappable<Test>) => WeakStorage;
export declare const createWeakStorage: (storage?: Mappable<Test>) => WeakStorage;
export {};

@@ -0,25 +1,15 @@

import { __spreadArrays } from "tslib";
import { isWeakable } from "./utils";
export var breakdownArgs = function (args) {
var saveSlice = [];
var weaks = [];
var strongs = [];
for (var i = 0; i < args.length; i++) {
if (isWeakable(args[i])) {
saveSlice.push(args[i]);
weaks.push(args[i]);
}
}
return saveSlice;
};
var testArgs = function (test, args) {
var a = test.arguments;
if (!a) {
return undefined;
}
if (a.length === args.length) {
for (var i = 0; i < a.length; ++i) {
if (a[i] !== args[i]) {
return undefined;
}
else {
strongs.push(args[i]);
}
return test;
}
return undefined;
return __spreadArrays(weaks, strongs);
};

@@ -32,13 +22,14 @@ export var createWeakStorage = function (storage) {

if (!slices.length) {
throw new Error("No weak-mappable (object, function, symbol) arguments found.");
throw new Error("No weak-mappable (object, function, symbol) argument found.");
}
var readFrom = storage;
console.log('get breakdown', slices);
var test = { weak: storage };
for (var i = 0; i < slices.length; ++i) {
var test_1 = readFrom.get(slices[i]);
if (!test_1 || !test_1.storage) {
console.log('get: no forward');
var storageKey = isWeakable(slices[i]) ? 'weak' : 'strong';
readFrom = test[storageKey];
test = readFrom.get(slices[i]);
if (!test) {
// get: no forward
return undefined;
}
readFrom = test_1.storage;
}

@@ -48,38 +39,26 @@ if (!readFrom) {

}
var test = readFrom.get(slices[0]);
if (test) {
var storedValue = testArgs(test, args);
if (storedValue) {
return {
value: test.storedValue,
};
}
else {
console.log('get: arg mismatch');
}
}
else {
console.log('get: no key');
}
return undefined;
return {
value: test.storedValue,
};
},
set: function (args, value) {
var _a;
var slices = breakdownArgs(args);
console.log('set breakdown', slices);
var writeTo = storage;
var next = { weak: storage };
for (var i = 0; i < slices.length; ++i) {
var next = writeTo.get(slices[i]);
if (!next || !next.storage) {
next = {
storage: new WeakMap()
};
var _b = isWeakable(slices[i]) ? ['weak', function () { return new WeakMap(); }] : ['strong', function () { return new Map(); }], storageKey = _b[0], factory = _b[1];
writeTo = next[storageKey];
if (!writeTo) {
next[storageKey] = writeTo = factory();
}
next = writeTo.get(slices[i]);
if (!next || !next[storageKey]) {
next = (_a = {},
_a[storageKey] = factory(),
_a);
writeTo.set(slices[i], next);
}
writeTo = next.storage;
}
writeTo.set(slices[0], {
storedValue: value,
arguments: args,
storage: undefined
});
next.storedValue = value;
return value;

@@ -86,0 +65,0 @@ },

@@ -1,2 +0,2 @@

import { WeakMappable, WeakStorage } from "./types";
export declare const createStrongStorage: (startIndex?: number, endIndex?: number, storage?: WeakMappable) => WeakStorage;
import { Mappable, WeakStorage } from "./types";
export declare const createStrongStorage: (startIndex?: number, endIndex?: number, storage?: Mappable) => WeakStorage;

@@ -8,5 +8,5 @@ export interface WeakResult {

}
export interface WeakMappable<T = any> {
export interface Mappable<T = any> {
get(key: any): T | undefined;
set(set: any, value: T): void;
}

@@ -1,9 +0,9 @@

import { WeakMappable, WeakStorage } from "./types";
import { Mappable, WeakStorage } from "./types";
export declare const breakdownArgs: (args: any[]) => any[];
declare type Test = {
arguments?: any[];
storedValue?: any;
storage?: WeakMappable<Test>;
strong?: Mappable<Test>;
weak?: Mappable<Test>;
};
export declare const createWeakStorage: (storage?: WeakMappable<Test>) => WeakStorage;
export declare const createWeakStorage: (storage?: Mappable<Test>) => WeakStorage;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWeakStorage = exports.breakdownArgs = void 0;
var tslib_1 = require("tslib");
var utils_1 = require("./utils");
exports.breakdownArgs = function (args) {
var saveSlice = [];
var weaks = [];
var strongs = [];
for (var i = 0; i < args.length; i++) {
if (utils_1.isWeakable(args[i])) {
saveSlice.push(args[i]);
weaks.push(args[i]);
}
}
return saveSlice;
};
var testArgs = function (test, args) {
var a = test.arguments;
if (!a) {
return undefined;
}
if (a.length === args.length) {
for (var i = 0; i < a.length; ++i) {
if (a[i] !== args[i]) {
return undefined;
}
else {
strongs.push(args[i]);
}
return test;
}
return undefined;
return tslib_1.__spreadArrays(weaks, strongs);
};

@@ -35,13 +25,14 @@ exports.createWeakStorage = function (storage) {

if (!slices.length) {
throw new Error("No weak-mappable (object, function, symbol) arguments found.");
throw new Error("No weak-mappable (object, function, symbol) argument found.");
}
var readFrom = storage;
console.log('get breakdown', slices);
var test = { weak: storage };
for (var i = 0; i < slices.length; ++i) {
var test_1 = readFrom.get(slices[i]);
if (!test_1 || !test_1.storage) {
console.log('get: no forward');
var storageKey = utils_1.isWeakable(slices[i]) ? 'weak' : 'strong';
readFrom = test[storageKey];
test = readFrom.get(slices[i]);
if (!test) {
// get: no forward
return undefined;
}
readFrom = test_1.storage;
}

@@ -51,38 +42,26 @@ if (!readFrom) {

}
var test = readFrom.get(slices[0]);
if (test) {
var storedValue = testArgs(test, args);
if (storedValue) {
return {
value: test.storedValue,
};
}
else {
console.log('get: arg mismatch');
}
}
else {
console.log('get: no key');
}
return undefined;
return {
value: test.storedValue,
};
},
set: function (args, value) {
var _a;
var slices = exports.breakdownArgs(args);
console.log('set breakdown', slices);
var writeTo = storage;
var next = { weak: storage };
for (var i = 0; i < slices.length; ++i) {
var next = writeTo.get(slices[i]);
if (!next || !next.storage) {
next = {
storage: new WeakMap()
};
var _b = utils_1.isWeakable(slices[i]) ? ['weak', function () { return new WeakMap(); }] : ['strong', function () { return new Map(); }], storageKey = _b[0], factory = _b[1];
writeTo = next[storageKey];
if (!writeTo) {
next[storageKey] = writeTo = factory();
}
next = writeTo.get(slices[i]);
if (!next || !next[storageKey]) {
next = (_a = {},
_a[storageKey] = factory(),
_a);
writeTo.set(slices[i], next);
}
writeTo = next.storage;
}
writeTo.set(slices[0], {
storedValue: value,
arguments: args,
storage: undefined
});
next.storedValue = value;
return value;

@@ -89,0 +68,0 @@ },

{
"name": "kashe",
"version": "1.1.0",
"version": "1.2.0",
"description": "Stateless weak memoization replacement for reselect and memoize-one",

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

"function-double": "^1.0.4",
"reselect": "^4.0.0"
"reselect": "^4.0.0",
"tslib": "^2.6.2"
}
}
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