UNPKG

@visulima/string

Version:

Functions for manipulating strings.

43 lines (40 loc) 1.48 kB
import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs'; import { splitByCase } from './split-by-case.mjs'; import upperFirst from './upper-first.mjs'; import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs'; import joinSegments from '../packem_shared/joinSegments-B2-yNNIj.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const defaultCacheStore = new LRUCache(1e3); const trainCase = /* @__PURE__ */ __name((value, options) => { if (typeof value !== "string") { return ""; } const shouldCache = options?.cache ?? false; const cacheStore = options?.cacheStore ?? defaultCacheStore; let cacheKey; if (shouldCache) { cacheKey = generateCacheKey(value, options); } if (shouldCache && cacheKey && cacheStore.has(cacheKey)) { return cacheStore.get(cacheKey); } const result = joinSegments( splitByCase(value, { handleAnsi: options?.handleAnsi, handleEmoji: options?.handleEmoji, knownAcronyms: options?.knownAcronyms, locale: options?.locale, normalize: options?.normalize, separators: void 0, stripAnsi: options?.stripAnsi, stripEmoji: options?.stripEmoji }).map((p) => upperFirst(p, { locale: options?.locale })), "-" ); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "trainCase"); export { trainCase as default };