UNPKG

@visulima/string

Version:

Functions for manipulating strings.

60 lines (56 loc) 2.22 kB
'use strict'; const constants = require('../packem_shared/constants-nihvIvk5.cjs'); const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs'); const case_lowerFirst = require('./lower-first.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'); const normalizeGermanEszett = require('../packem_shared/normalize-german-eszett-DJK0S2qj.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const defaultCacheStore = new LRUCache(1e3); const camelCase = /* @__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.generateCacheKey(value, options); } if (shouldCache && cacheKey && cacheStore.has(cacheKey)) { return cacheStore.get(cacheKey); } let firstWord = true; 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((word) => { if (options?.handleAnsi && constants.RE_FAST_ANSI.test(word)) { return word; } word = options?.locale?.startsWith("de") ? normalizeGermanEszett.normalizeGermanEszett(word) : word; word = options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase(); if (firstWord) { firstWord = false; return case_lowerFirst(word, options); } return case_upperFirst(word, options); }), "" ); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "camelCase"); module.exports = camelCase;