v1.1.0 - More strongly-typed string methods π
What's Changed
This version adds a few more strongly-typed alternatives to the native string methods and by doing so we were able to simplify a lot of the internal methods' implementations.
With a lot of low level properly-typed utilities we can keep both type and runtime implementations in sync, like in this example:
// OLD Implementation
type CamelCase<T extends string> = T extends unknown
? PascalCase<T> extends `${infer first}${infer rest}`
? `${Lowercase<first>}${rest}`
: T
: never
function toCamelCase<T extends string>(str: T) {
const res = toPascalCase(str)
return (res.slice(0, 1).toLowerCase() + res.slice(1)) as CamelCase<T> // we needed to cast this type
}
// === πͺ ===
// NEW Implementation
type CamelCase<T extends string> = Uncapitalize<PascalCase<T>>
function toCamelCase<T extends string>(str: T): CamelCase<T> {
return uncapitalize(toPascalCase(str)) // type-checks without type casting
}
These changes aim to achieve the goal of this library which is the perfect synchrony between type-level and runtime string functions β€οΈ.
Support for older JS runtimes
We are now also able to run replaceAll
in older browsers that don't yet support it with a very simple polyfill .
Pull requests
- feat:
uncapitalize
,lengh
, andslice
methods by @gustavoguichard in #24 - feat:
concat
method by @jly36963 in #25 - feat: polyfill for
replaceAll
by @gustavoguichard in #26
Full Changelog: v1.0.0...v1.1.0