Files
2026-09-08 20:28:54 +08:00

23 lines
457 B
JavaScript

function cached (fn) {
const cache = Object.create(null)
return function cachedFn (str) {
const hit = cache[str]
return hit || (cache[str] = fn(str))
}
}
const camelizeRE = /-(\w)/g
const camelize = cached(function (str) {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
})
const capitalize = cached(function (str) {
return str.charAt(0).toUpperCase() + str.slice(1)
})
module.exports = {
camelize,
capitalize
}