UNPKG

@visulima/string

Version:

Functions for manipulating strings.

31 lines (28 loc) 1.16 kB
import LRUCache from '../packem_shared/LRUCache-udNErhWw.mjs'; import noCase from './no-case.mjs'; import upperFirst from './upper-first.mjs'; import { g as generateCacheKey } from '../packem_shared/generate-cache-key-YSju5pj2.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const defaultCacheStore = new LRUCache(1e3); const pascalSnakeCase = /* @__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 words = noCase(value, { ...options, cache: false }).split(" "); const result = words.map((word) => upperFirst(word, { locale: options?.locale })).join("_"); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "pascalSnakeCase"); export { pascalSnakeCase as default };