Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .npmignore

This file was deleted.

86 changes: 49 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "jest",
"test:all": "npm run lint && npm run test:typescript && npm run test",
"test:coverage": "covert test/*.js",
"test:typescript": "cd ./typings/tests && npm install-test"
"test:typescript": "tsc -P typings"
},
"files": [
"README.md",
Expand Down Expand Up @@ -54,6 +54,7 @@
"ora": "^0.3.0",
"ramda": "^0.22.1",
"standard": "^10.0.2",
"typescript": "^4.9.5",
"underscore": "^1.8.3"
},
"jest": {
Expand Down
36 changes: 18 additions & 18 deletions typings/fast-memoize.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
type Func = (...args: any[]) => any;

export interface Cache<K, V> {
create: CacheCreateFunc<K, V>
}

interface CacheCreateFunc<K, V> {
(): {
get(key: K): V;
Expand All @@ -12,25 +8,29 @@ interface CacheCreateFunc<K, V> {
}
}

export type Serializer = (args: any[]) => string;
declare namespace memoize {
interface Cache<K, V> {
create: CacheCreateFunc<K, V>
}

export interface Options<F extends Func> {
cache?: Cache<string, ReturnType<F>>;
serializer?: Serializer;
strategy?: MemoizeFunc;
}
type Serializer = (args: any[]) => string;

export interface MemoizeFunc {
<F extends Func>(fn: F, options?: Options<F>): F;
}
interface Options<F extends Func> {
cache?: Cache<string, ReturnType<F>>;
serializer?: Serializer;
strategy?: MemoizeFunc;
}

interface MemoizeFunc {
<F extends Func>(fn: F, options?: Options<F>): F;
}

interface Memoize extends MemoizeFunc {
strategies: {
const strategies: {
variadic: MemoizeFunc;
monadic: MemoizeFunc;
};
}
}

declare const memoize: Memoize;
declare function memoize<F extends Func>(fn: F, options?: memoize.Options<F>): F;

export default memoize;
export = memoize;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import memoize, { Options, Cache, Serializer } from "fast-memoize";
import memoize = require("fast-memoize");

function add(a: number, b: number): number {
return a + b;
}

const cache: Cache<string, number> = {
const cache: memoize.Cache<string, number> = {
create: () => {
const storage = new Map<string, number>();
return {
Expand All @@ -29,9 +29,9 @@ const cache: Cache<string, number> = {

};

const serializer: Serializer = (args: any[]) => args.join("-");
const serializer: memoize.Serializer = (args: any[]) => args.join("-");

const options: Options<typeof add> = {
const options: memoize.Options<typeof add> = {
cache,
serializer,
strategy: memoize.strategies.variadic
Expand Down
1 change: 0 additions & 1 deletion typings/tests/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions typings/tests/package-lock.json

This file was deleted.

26 changes: 0 additions & 26 deletions typings/tests/package.json

This file was deleted.

8 changes: 5 additions & 3 deletions typings/tests/tsconfig.json → typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"compilerOptions": {
"target": "es6",
"module": "es2015",
"module": "commonjs",
"noEmit": true,
"jsx": "react",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node"
"moduleResolution": "node",
"paths": {
"fast-memoize": ["./fast-memoize"]
}
}
}