You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
457 B
22 lines
457 B
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
|
|
}
|
|
|