gustavoguichard / string-ts
Strongly typed string functions
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing gustavoguichard/string-ts in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewStrongly-typed string functions for all! 😬 The problem When you are working with literal strings, the string manipulation functions only work at the runtime level and the types don't follow those transformations. You end up losing type information and possibly having to cast the result. 🤓 The solution This library aims to solve this problem by providing a set of common functions that work with literal strings at both type and runtime level. 🔍 Why this matters TypeScript yields the best static analysis when types are highly specific. Literals are more specific than type . This library preserves literals (and unions of literals) after transformations, unlike most existing utility libraries (and built-in string methods.) I still don't get the purpose of this library 🤔 In-depth example In the below example, I want to get a strongly-typed, camel-case version of . One flow results in a loose type, and the other results in a more precise type. This example should illustrate the highly-specific and flexible nature of . 📦 Installation 🌳 Tree shaking has been designed with tree shaking in mind. We have tested it with build tools like Webpack, Vite, Rollup, etc. 👌 Supported TypeScript versions currently only works on TypeScript v5+. It also only work with common ASCII characters characters. We don't plan to support international characters or emojis. 🪄 Native String Method Overrides Extracting functions from is the recommended usage, but if you'd like to apply strongly-typed versions of native string methods project-wide, you can do so with a single import. Inspired by ts-reset, this import overrides the native type declarations, giving you strong typing for supported methods like , , , , , and more. This has minimal impact on type-checker performance. In our tests, TSC went from 17.21s to 17.41s. _Note: Only methods already supported by the library are typed. The property cannot be strongly-typed as it's a read-only property, not a method._ --- 📖 API • Runtime counterparts of native type utilities • capitalize • uncapitalize • Strongly-typed alternatives to native runtime utilities • charAt • concat • endsWith • includes • join • length • padEnd • padStart • repeat • replace • replaceAll • slice • split • startsWith • toLowerCase • toUpperCase • trim • trimEnd • trimStart • Strongly-typed alternatives to common loosely-typed functions • camelCase • constantCase • delimiterCase • kebabCase • pascalCase • reverse • snakeCase • titleCase • truncate • words • Strongly-typed shallow transformation of objects • camelKeys • constantKeys • delimiterKeys • kebabKeys • pascalKeys • replaceKeys • snakeKeys • Strongly-typed deep transformation of objects • deepCamelKeys • deepConstantKeys • deepDelimiterKeys • deepKebabKeys • deepPascalKeys • deepSnakeKeys • Type Utilities • Native TS type utilities • General Type utilities from this library • Casing type utilities • Other exported type utilities • Runtime-only utilities • deepTransformKeys --- Runtime counterparts of native type utilities capitalize Capitalizes the first letter of a string. This is a runtime counterpart of from . uncapitalize Uncapitalizes the first letter of a string. This is a runtime counterpart of from . Strongly-typed alternatives to native runtime utilities charAt This function is a strongly-typed counterpart of . concat This function is a strongly-typed counterpart of . endsWith This function is a strongly-typed counterpart of . includes This function is a strongly-typed counterpart of . join This function is a strongly-typed counterpart of . length This function is a strongly-typed counterpart of . padEnd This function is a strongly-typed counterpart of . padStart This function is a strongly-typed counterpart of . repeat This function is a strongly-typed counterpart of . replace This function is a strongly-typed counterpart of . _Warning: this is a partial implementation, as we don't fully support Regex. Using a RegExp lookup will result in a loose typing._ replaceAll This function is a strongly-typed counterpart of . It also has a polyfill for runtimes older than ES2021. _Warning: this is a partial implementation, as we don't fully support Regex. Using a RegExp lookup will result in a loose typing._ slice This function is a strongly-typed counterpart of . split This function is a strongly-typed counterpart of . startsWith This function is a strongly-typed counterpart of . toLowerCase This function is a strongly-typed counterpart of . toUpperCase This function is a strongly-typed counterpart of . trim This function is a strongly-typed counterpart of . trimEnd This function is a strongly-typed counterpart of . trimStart This function is a strongly-typed counterpart of . Strongly-typed alternatives to common loosely-typed functions lowerCase This function converts a string to at both runtime and type levels. _NOTE: this function will split by words and join them with , unlike ._ camelCase This function converts a string to at both runtime and type levels. constantCase This function converts a string to at both runtime and type levels. delimiterCase This function converts a string to a new case with a custom delimiter at both runtime and type levels. kebabCase This function converts a string to at both runtime and type levels. pascalCase This function converts a string to at both runtime and type levels. snakeCase This function converts a string to at both runtime and type levels. titleCase This function converts a string to at both runtime and type levels. upperCase This function converts a string to at both runtime and type levels. _NOTE: this function will split by words and join them with , unlike ._ reverse This function reverses a string. truncate This function truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "…