@visulima/string
Version:
Functions for manipulating strings.
48 lines (44 loc) • 1.74 kB
JavaScript
;
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 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);
function titleCase(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 = 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?.locale?.startsWith("de")) {
word = normalizeGermanEszett.normalizeGermanEszett(word);
}
return case_upperFirst(options?.locale ? word.toLocaleLowerCase(options.locale) : word.toLowerCase(), { locale: options?.locale });
}).join(" ");
if (shouldCache && cacheKey) {
cacheStore.set(cacheKey, result);
}
return result;
}
__name(titleCase, "titleCase");
module.exports = titleCase;