UNPKG

@visulima/string

Version:

Functions for manipulating strings.

62 lines (57 loc) 2.27 kB
'use strict'; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } }); const constants = require('../packem_shared/constants-nihvIvk5.cjs'); const LRUCache = require('../packem_shared/LRUCache-Crb-m7cw.cjs'); const case_splitByCase = require('./split-by-case.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 kebabCase = /* @__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_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 }); const processed = words.map((word) => { if (options?.handleAnsi && constants.RE_FAST_ANSI.test(word)) { return word; } if (options?.toUpperCase) { if (options.locale) { return word.toLocaleUpperCase(options.locale); } return word.toUpperCase(); } const split = options?.locale?.startsWith("de") ? normalizeGermanEszett.normalizeGermanEszett(word) : word; if (options?.locale) { return split.toLocaleLowerCase(options.locale); } return split.toLowerCase(); }); const result = joinSegments(processed, options?.joiner ?? "-"); if (shouldCache && cacheKey) { cacheStore.set(cacheKey, result); } return result; }, "kebabCase"); exports.kebabCase = kebabCase;