UNPKG

@visulima/string

Version:

Functions for manipulating strings.

51 lines (48 loc) 1.96 kB
import { R as RE_FAST_ANSI } from '../packem_shared/constants-CKNmLDBQ.mjs'; 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'; import { n as normalizeGermanEszett } from '../packem_shared/normalize-german-eszett-fpJ4lZL6.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const defaultCacheStore = new LRUCache(1e3); const pascalCase = /* @__PURE__ */ __name((value, options) => { if (typeof value !== "string" || !value) { 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((word) => { if (options?.handleAnsi && RE_FAST_ANSI.test(word)) { return word; } const split = options?.locale?.startsWith("de") ? normalizeGermanEszett(word) : word; return upperFirst(options?.locale ? split.toLocaleLowerCase(options.locale) : split.toLowerCase(), { locale: options?.locale }); }), "" ); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "pascalCase"); export { pascalCase as default };