@braindb/core
Version:
markdown-graph-content-layer-database
31 lines (30 loc) • 1.05 kB
JavaScript
import { xxh64, xxh32 } from "@node-rs/xxhash";
import { deterministicString } from "deterministic-object-hash";
const memoizeSecret = {};
export const memoizeOnce = (f) => {
let arg = memoizeSecret;
let result;
return (x) => {
if (x !== arg) {
arg = x;
result = f(x);
}
return result;
};
};
export const cheksumConfig = memoizeOnce((conf) => xxh32(deterministicString(conf)));
// can use streaming instead of reading whole file
export const cheksum64str = (str) => xxh64(str).toString(36);
const externalLinkRegexp = RegExp(`^[a-z]+://`);
export const isExternalLink = (link) => externalLinkRegexp.test(link);
export const symmetricDifference = (arrayA, arrayB) => {
if (arrayA.length === 0)
return arrayB;
if (arrayB.length === 0)
return arrayA;
const setA = new Set(arrayA);
const setB = new Set(arrayB);
const diffA = arrayA.filter((x) => !setB.has(x));
const diffB = arrayB.filter((x) => !setA.has(x));
return [...diffA, ...diffB];
};