UNPKG

@visulima/string

Version:

Functions for manipulating strings.

33 lines (29 loc) 1.21 kB
'use strict'; const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs'); const case_noCase = require('./no-case.cjs'); const case_upperFirst = require('./upper-first.cjs'); const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs'); 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.generateCacheKey(value, options); } if (shouldCache && cacheKey && cacheStore.has(cacheKey)) { return cacheStore.get(cacheKey); } const words = case_noCase(value, { ...options, cache: false }).split(" "); const result = words.map((word) => case_upperFirst(word, { locale: options?.locale })).join("_"); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "pascalSnakeCase"); module.exports = pascalSnakeCase;