UNPKG

crypto-shortener

Version:

Shorten crypto hashes, addresses with ellipsis

17 lines 640 B
function shortenWith(str, options = {}) { const { length = 4, prefixes = [] } = options; const prefix = prefixes.find((p) => str.startsWith(p)) || ""; const head = str.slice(prefix.length, prefix.length + length); const tail = str.slice(-length); return `${prefix}${head}...${tail}`; } export function shorten(arg, options) { if (typeof arg === "string") { return shortenWith(arg, options); } if (typeof arg === "object" && arg !== null) { return (str) => shortenWith(str, arg); } throw new TypeError("Argument is not string or an options object"); } //# sourceMappingURL=index.js.map