Skip to content

Commit

Permalink
Replaced internal memoize function with "lomemo"
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Apr 14, 2024
1 parent abd5226 commit 8f2cd60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"json-sorted-stringify": "^1.0.0",
"json5": "^2.2.3",
"kasi": "^1.1.0",
"lomemo": "^1.0.0",
"pioppo": "^1.1.1",
"specialist": "^1.4.0",
"tiny-editorconfig": "^1.0.0",
Expand Down
17 changes: 1 addition & 16 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import findUp from "find-up-json";
import { moduleResolve } from "import-meta-resolve";
import memoize from "lomemo";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
Expand All @@ -12,22 +13,6 @@ import zeptomatchIsStatic from "zeptomatch-is-static";
import type { ContextOptions, FormatOptions, FunctionMaybe, Key, LogLevel, Options, PrettierConfigWithOverrides, PrettierPlugin } from "./types.js";
import type { PluginsOptions, PromiseMaybe } from "./types.js";

//FIXME: Ensure all arguments are actually taken into account
//TODO: Publish something like this as a standalone module, rather than manually hoisting this up
function memoize<Args extends unknown[], Return>(fn: (...args: Args) => Return): ((...args: Args) => Return) & { cache: Map<Args[0], Return> } {
const memoized = (...args: Args): Return => {
const { cache } = memoized;
const id = args[0];
const cached = cache.get(id);
if (!isUndefined(cached) || cache.has(id)) return cached;
const result = fn(...args);
cache.set(id, result);
return result;
};
memoized.cache = new Map();
return memoized;
}

function castArray<T>(value: T | T[]): T[] {
return isArray(value) ? value : [value];
}
Expand Down

0 comments on commit 8f2cd60

Please sign in to comment.