UNPKG

@visulima/string

Version:

Functions for manipulating strings.

45 lines (41 loc) 1.55 kB
'use strict'; const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs'); const case_splitByCase = require('./split-by-case.cjs'); const case_upperFirst = require('./upper-first.cjs'); const generateCacheKey = require('../packem_shared/generate-cache-key-D8f1auDB.cjs'); const joinSegments = require('../packem_shared/joinSegments-CqLUoCzF.cjs'); 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.generateCacheKey(value, options); } if (shouldCache && cacheKey && cacheStore.has(cacheKey)) { return cacheStore.get(cacheKey); } const result = joinSegments( case_splitByCase.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) => case_upperFirst(p, { locale: options?.locale })), "-" ); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "trainCase"); module.exports = trainCase;