{"id":13625573,"url":"https://github.com/gustavoguichard/string-ts","last_synced_at":"2025-05-13T20:11:45.577Z","repository":{"id":179154798,"uuid":"657643653","full_name":"gustavoguichard/string-ts","owner":"gustavoguichard","description":"Strongly typed string functions","archived":false,"fork":false,"pushed_at":"2024-10-18T05:37:56.000Z","size":3135,"stargazers_count":1192,"open_issues_count":9,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-29T15:37:40.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gustavoguichard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-23T14:05:39.000Z","updated_at":"2024-10-24T13:26:13.000Z","dependencies_parsed_at":"2023-10-12T15:12:24.178Z","dependency_job_id":"c808a770-297f-4756-ae9f-d21caca481d1","html_url":"https://github.com/gustavoguichard/string-ts","commit_stats":null,"previous_names":["gustavoguichard/string-ts"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavoguichard%2Fstring-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavoguichard%2Fstring-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavoguichard%2Fstring-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gustavoguichard%2Fstring-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gustavoguichard","download_url":"https://codeload.github.com/gustavoguichard/string-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199258,"owners_count":21063642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:01:57.834Z","updated_at":"2025-04-10T10:40:15.838Z","avatar_url":"https://github.com/gustavoguichard.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"StringTs Banner\" src=\"./docs/string-ts-banner.png\" width=\"800\" /\u003e\n\u003c/p\u003e\n\n[![NPM](https://img.shields.io/npm/v/string-ts)](https://www.npmjs.org/package/string-ts)\n![Library size](https://img.shields.io/bundlephobia/minzip/string-ts)\n[![Code Coverage](https://img.shields.io/codecov/c/github/gustavoguichard/string-ts)](https://app.codecov.io/gh/gustavoguichard/string-ts)\n[![All Contributors](https://img.shields.io/github/contributors/gustavoguichard/string-ts)](#-contributors)\n\n## Strongly-typed string functions for all!\n\n![A demonstration of string-ts](https://github.com/gustavoguichard/string-ts/assets/566971/0aa5603f-871d-4eb7-8ace-6a73466cec4d)\n\n## 😬 The problem\n\nWhen you are working with literal strings, the string manipulation functions only work at the runtime level and the types don't follow those transformations.\nYou end up losing type information and possibly having to cast the result.\n\n```ts\nconst str = 'hello-world'\nconst result = str.replace('-', ' ') // you should use: as 'hello world'\n//    ^? string\n```\n\n## 🤓 The solution\n\nThis library aims to solve this problem by providing a set of common functions that work with literal strings at both type and runtime level.\n\n```ts\nimport { replace } from 'string-ts'\n\nconst str = 'hello-world'\nconst result = replace(str, '-', ' ')\n//    ^ 'hello world'\n```\n\n## 🔍 Why this matters\n\nTypeScript yields the best static analysis when types are highly specific.\nLiterals are more specific than type `string`.\nThis library preserves literals (and unions of literals) after transformations, unlike most existing utility libraries (and built-in string methods.)\n\n[I still don't get the purpose of this library 🤔](#%EF%B8%8F-interview)\n\n### In-depth example\n\nIn the below example, I want to get a strongly-typed, camel-case version of `process.env`.\nOne flow results in a loose type, and the other results in a more precise type.\nThis example should illustrate the highly-specific and flexible nature of `string-ts`.\n\n```ts\nimport { deepCamelKeys } from 'string-ts'\nimport { camelCase, mapKeys } from 'lodash-es'\nimport z from 'zod'\n\nconst EnvSchema = z.object({\n  NODE_ENV: z.string(),\n})\n\nfunction getEnvLoose() {\n  const rawEnv = EnvSchema.parse(process.env)\n  const env = mapKeys(rawEnv, (_v, k) =\u003e camelCase(k))\n  //    ^? Dictionary\u003cstring\u003e\n\n  // `Dictionary\u003cstring\u003e` is too loose\n  // TypeScript is okay with this, 'abc' is expected to be of type `string`\n  // This will have unexpected behavior at runtime\n  console.log(env.abc)\n}\n\nfunction getEnvPrecise() {\n  const rawEnv = EnvSchema.parse(process.env)\n  const env = deepCamelKeys(rawEnv)\n  //    ^? { nodeEnv: string }\n\n  // Error: Property 'abc' does not exist on type '{ nodeEnv: string; }'\n  // Our type is more specific, so TypeScript catches this error.\n  // This mistake will be caught at compile time\n  console.log(env.abc)\n}\n\nfunction main() {\n  getEnvLoose()\n  getEnvPrecise()\n}\n\nmain()\n```\n\n## 📦 Installation\n\n```bash\nnpm install string-ts\n```\n\n## 🌳 Tree shaking\n\n`string-ts` has been designed with tree shaking in mind.\nWe have tested it with build tools like Webpack, Vite, Rollup, etc.\n\n## 👌 Supported TypeScript versions\n\n`string-ts` currently only works on TypeScript v5+.\n\nIt also only work with common ASCII characters characters. We don't plan to support international characters or emojis.\n\n---\n\n# 📖 API\n\n- [Runtime counterparts of native type utilities](#runtime-counterparts-of-native-type-utilities)\n  - [capitalize](#capitalize)\n  - [uncapitalize](#uncapitalize)\n- [Strongly-typed alternatives to native runtime utilities](#strongly-typed-alternatives-to-native-runtime-utilities)\n  - [charAt](#charat)\n  - [concat](#concat)\n  - [endsWith](#endsWith)\n  - [includes](#includes)\n  - [join](#join)\n  - [length](#length)\n  - [padEnd](#padend)\n  - [padStart](#padstart)\n  - [repeat](#repeat)\n  - [replace](#replace)\n  - [replaceAll](#replaceall)\n  - [slice](#slice)\n  - [split](#split)\n  - [startsWith](#startsWith)\n  - [toLowerCase](#tolowercase)\n  - [toUpperCase](#touppercase)\n  - [trim](#trim)\n  - [trimEnd](#trimend)\n  - [trimStart](#trimstart)\n- [Strongly-typed alternatives to common loosely-typed functions](#strongly-typed-alternatives-to-common-loosely-typed-functions)\n  - [camelCase](#camelcase)\n  - [constantCase](#constantcase)\n  - [delimiterCase](#delimitercase)\n  - [kebabCase](#kebabcase)\n  - [pascalCase](#pascalcase)\n  - [reverse](#reverse)\n  - [snakeCase](#snakecase)\n  - [titleCase](#titlecase)\n  - [truncate](#truncate)\n  - [words](#words)\n- [Strongly-typed shallow transformation of objects](#strongly-typed-shallow-transformation-of-objects)\n  - [camelKeys](#camelkeys)\n  - [constantKeys](#constantkeys)\n  - [delimiterKeys](#delimiterkeys)\n  - [kebabKeys](#kebabkeys)\n  - [pascalKeys](#pascalkeys)\n  - [replaceKeys](#replacekeys)\n  - [snakeKeys](#snakekeys)\n- [Strongly-typed deep transformation of objects](#strongly-typed-deep-transformation-of-objects)\n  - [deepCamelKeys](#deepcamelkeys)\n  - [deepConstantKeys](#deepconstantkeys)\n  - [deepDelimiterKeys](#deepdelimiterkeys)\n  - [deepKebabKeys](#deepkebabkeys)\n  - [deepPascalKeys](#deeppascalkeys)\n  - [deepSnakeKeys](#deepsnakekeys)\n- [Type Utilities](#type-utilities)\n  - [Native TS type utilities](#native-ts-type-utilities)\n  - [General Type utilities from this library](#general-type-utilities-from-this-library)\n  - [Casing type utilities](#casing-type-utilities)\n  - [Other exported type utilities](#other-exported-type-utilities)\n- [Runtime-only utilities](#runtime-only-utilities)\n  - [deepTransformKeys](#deeptransformkeys)\n\n---\n\n## Runtime counterparts of native type utilities\n\n### capitalize\n\nCapitalizes the first letter of a string. This is a runtime counterpart of `Capitalize\u003cT\u003e` from `src/types.d.ts`.\n\n```ts\nimport { capitalize } from 'string-ts'\n\nconst str = 'hello world'\nconst result = capitalize(str)\n//    ^ 'Hello world'\n```\n\n### uncapitalize\n\nUncapitalizes the first letter of a string. This is a runtime counterpart of `Uncapitalize\u003cT\u003e` from `src/types.d.ts`.\n\n```ts\nimport { uncapitalize } from 'string-ts'\n\nconst str = 'Hello world'\nconst result = uncapitalize(str)\n//    ^ 'hello world'\n```\n\n## Strongly-typed alternatives to native runtime utilities\n\n### charAt\n\nThis function is a strongly-typed counterpart of `String.prototype.charAt`.\n\n```ts\nimport { charAt } from 'string-ts'\n\nconst str = 'hello world'\nconst result = charAt(str, 6)\n//    ^ 'w'\n```\n\n### concat\n\nThis function is a strongly-typed counterpart of `String.prototype.concat`.\n\n```ts\nimport { concat } from 'string-ts'\n\nconst result = concat('a', 'bc', 'def')\n//    ^ 'abcdef'\n```\n\n### endsWith\n\nThis function is a strongly-typed counterpart of `String.prototype.endsWith`.\n\n```ts\nimport { endsWith } from 'string-ts'\n\nconst result = endsWith('abc', 'c')\n//    ^ true\n```\n\n### includes\n\nThis function is a strongly-typed counterpart of `String.prototype.includes`.\n\n```ts\nimport { includes } from 'string-ts'\n\nconst result = includes('abcde', 'bcd')\n//    ^ true\n```\n\n### join\n\nThis function is a strongly-typed counterpart of `Array.prototype.join`.\n\n```ts\nimport { join } from 'string-ts'\n\nconst str = ['hello', 'world']\nconst result = join(str, ' ')\n//    ^ 'hello world'\n```\n\n### length\n\nThis function is a strongly-typed counterpart of `String.prototype.length`.\n\n```ts\nimport { length } from 'string-ts'\n\nconst str = 'hello'\nconst result = length(str)\n//    ^ 5\n```\n\n### padEnd\n\nThis function is a strongly-typed counterpart of `String.prototype.padEnd`.\n\n```ts\nimport { padEnd } from 'string-ts'\n\nconst str = 'hello'\nconst result = padEnd(str, 10, '=')\n//    ^ 'hello====='\n```\n\n### padStart\n\nThis function is a strongly-typed counterpart of `String.prototype.padStart`.\n\n```ts\nimport { padStart } from 'string-ts'\n\nconst str = 'hello'\nconst result = padStart(str, 10, '=')\n//    ^ '=====hello'\n```\n\n### repeat\n\nThis function is a strongly-typed counterpart of `String.prototype.repeat`.\n\n```ts\nimport { repeat } from 'string-ts'\n\nconst str = 'abc'\nconst result = repeat(str, 3)\n//    ^ 'abcabcabc'\n```\n\n### replace\n\nThis function is a strongly-typed counterpart of `String.prototype.replace`.\n\n_Warning: this is a partial implementation, as we don't fully support Regex. Using a RegExp lookup will result in a loose typing._\n\n```ts\nimport { replace } from 'string-ts'\n\nconst str = 'hello-world-'\nconst result = replace(str, '-', ' ')\n//    ^ 'hello world-'\nconst looselyTypedResult = replace(str, /-/, ' ')\n//    ^ string\n```\n\n### replaceAll\n\nThis function is a strongly-typed counterpart of `String.prototype.replaceAll`.\nIt also has a polyfill for runtimes older than ES2021.\n\n_Warning: this is a partial implementation, as we don't fully support Regex. Using a RegExp lookup will result in a loose typing._\n\n```ts\nimport { replaceAll } from 'string-ts'\n\nconst str = 'hello-world-'\nconst result = replaceAll(str, '-', ' ')\n//    ^ 'hello world '\nconst looselyTypedResult = replaceAll(str, /-/g, ' ')\n//    ^ string\n```\n\n### slice\n\nThis function is a strongly-typed counterpart of `String.prototype.slice`.\n\n```ts\nimport { slice } from 'string-ts'\n\nconst str = 'hello-world'\nconst result = slice(str, 6)\n//    ^ 'world'\nconst result2 = slice(str, 1, 5)\n//    ^ 'ello'\nconst result3 = slice(str, -5)\n//    ^ 'world'\n```\n\n### split\n\nThis function is a strongly-typed counterpart of `String.prototype.split`.\n\n```ts\nimport { split } from 'string-ts'\n\nconst str = 'hello-world'\nconst result = split(str, '-')\n//    ^ ['hello', 'world']\n```\n\n### startsWith\n\nThis function is a strongly-typed counterpart of `String.prototype.startsWith`.\n\n```ts\nimport { startsWith } from 'string-ts'\n\nconst result = startsWith('abc', 'a')\n//    ^ true\n```\n\n### toLowerCase\n\nThis function is a strongly-typed counterpart of `String.prototype.toLowerCase`.\n\n```ts\nimport { toLowerCase } from 'string-ts'\n\nconst str = 'HELLO WORLD'\nconst result = toLowerCase(str)\n//    ^ 'hello world'\n```\n\n### toUpperCase\n\nThis function is a strongly-typed counterpart of `String.prototype.toUpperCase`.\n\n```ts\nimport { toUpperCase } from 'string-ts'\n\nconst str = 'hello world'\nconst result = toUpperCase(str)\n//    ^ 'HELLO WORLD'\n```\n\n### trim\n\nThis function is a strongly-typed counterpart of `String.prototype.trim`.\n\n```ts\nimport { trim } from 'string-ts'\n\nconst str = '  hello world  '\nconst result = trim(str)\n//    ^ 'hello world'\n```\n\n### trimEnd\n\nThis function is a strongly-typed counterpart of `String.prototype.trimEnd`.\n\n```ts\nimport { trimEnd } from 'string-ts'\n\nconst str = '  hello world  '\nconst result = trimEnd(str)\n//    ^ '  hello world'\n```\n\n### trimStart\n\nThis function is a strongly-typed counterpart of `String.prototype.trimStart`.\n\n```ts\nimport { trimStart } from 'string-ts'\n\nconst str = '  hello world  '\nconst result = trimStart(str)\n//    ^ 'hello world  '\n```\n\n## Strongly-typed alternatives to common loosely-typed functions\n\n### lowerCase\n\nThis function converts a string to `lower case` at both runtime and type levels.\n_NOTE: this function will split by words and join them with `\" \"`, unlike `toLowerCase`._\n\n```ts\nimport { lowerCase } from 'string-ts'\n\nconst str = 'HELLO-WORLD'\nconst result = lowerCase(str)\n//    ^ 'hello world'\n```\n\n### camelCase\n\nThis function converts a string to `camelCase` at both runtime and type levels.\n\n```ts\nimport { camelCase } from 'string-ts'\n\nconst str = 'hello-world'\nconst result = camelCase(str)\n//    ^ 'helloWorld'\n```\n\n### constantCase\n\nThis function converts a string to `CONSTANT_CASE` at both runtime and type levels.\n\n```ts\nimport { constantCase } from 'string-ts'\n\nconst str = 'helloWorld'\nconst result = constantCase(str)\n//    ^ 'HELLO_WORLD'\n```\n\n### delimiterCase\n\nThis function converts a string to a new case with a custom delimiter at both runtime and type levels.\n\n```ts\nimport { delimiterCase } from 'string-ts'\n\nconst str = 'helloWorld'\nconst result = delimiterCase(str, '.')\n//    ^ 'hello.World'\n```\n\n### kebabCase\n\nThis function converts a string to `kebab-case` at both runtime and type levels.\n\n```ts\nimport { kebabCase } from 'string-ts'\n\nconst str = 'helloWorld'\nconst result = kebabCase(str)\n//    ^ 'hello-world'\n```\n\n### pascalCase\n\nThis function converts a string to `PascalCase` at both runtime and type levels.\n\n```ts\nimport { pascalCase } from 'string-ts'\n\nconst str = 'hello-world'\nconst result = pascalCase(str)\n//    ^ 'HelloWorld'\n```\n\n### snakeCase\n\nThis function converts a string to `snake_case` at both runtime and type levels.\n\n```ts\nimport { snakeCase } from 'string-ts'\n\nconst str = 'helloWorld'\nconst result = snakeCase(str)\n//    ^ 'hello_world'\n```\n\n### titleCase\n\nThis function converts a string to `Title Case` at both runtime and type levels.\n\n```ts\nimport { titleCase } from 'string-ts'\n\nconst str = 'helloWorld'\nconst result = titleCase(str)\n//    ^ 'Hello World'\n```\n\n### upperCase\n\nThis function converts a string to `UPPER CASE` at both runtime and type levels.\n_NOTE: this function will split by words and join them with `\" \"`, unlike `toUpperCase`._\n\n```ts\nimport { upperCase } from 'string-ts'\n\nconst str = 'hello-world'\nconst result = upperCase(str)\n//    ^ 'HELLO WORLD'\n```\n\n### reverse\n\nThis function reverses a string.\n\n```ts\nimport { reverse } from 'string-ts'\n\nconst str = 'Hello StringTS!'\nconst result = reverse(str)\n//    ^ '!TSgnirtS olleH'\n```\n\n### truncate\n\nThis 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 \"...\".\n\n```ts\nimport { truncate } from 'string-ts'\n\nconst str = '-20someVery-weird String'\nconst result = truncate(str, 8)\n//    ^ '-20so...'\n```\n\n### words\n\nThis function identifies the words in a string and returns a tuple of words split by separators, differences in casing, numbers, and etc.\n\n```ts\nimport { words } from 'string-ts'\n\nconst str = '-20someVery-weird String'\nconst result = words(str)\n//    ^ ['20', 'some', 'Very', 'weird', 'String']\n```\n\n## Strongly-typed shallow transformation of objects\n\n### camelKeys\n\nThis function shallowly converts the keys of an object to `camelCase` at both runtime and type levels.\n\n```ts\nimport { camelKeys } from 'string-ts'\n\nconst data = {\n  'hello-world': {\n    'foo-bar': 'baz',\n  },\n} as const\nconst result = camelKeys(data)\n//    ^ { helloWorld: { 'foo-bar': 'baz' } }\n```\n\n### constantKeys\n\nThis function shallowly converts the keys of an object to `CONSTANT_CASE` at both runtime and type levels.\n\n```ts\nimport { constantKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = constantKeys(data)\n//    ^ { 'HELLO_WORLD': { 'fooBar': 'baz' } }\n```\n\n### delimiterKeys\n\nThis function shallowly converts the keys of an object to a new case with a custom delimiter at both runtime and type levels.\n\n```ts\nimport { delimiterKeys } from 'string-ts'\n\nconst data = {\n  'hello-world': {\n    'foo-bar': 'baz',\n  },\n} as const\nconst result = delimiterKeys(data, '.')\n//    ^ { 'hello.world': { 'foo-bar': 'baz' } }\n```\n\n### kebabKeys\n\nThis function shallowly converts the keys of an object to `kebab-case` at both runtime and type levels.\n\n```ts\nimport { kebabKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = kebabKeys(data)\n//    ^ { 'hello-world': { fooBar: 'baz' } }\n```\n\n### pascalKeys\n\nThis function shallowly converts the keys of an object to `PascalCase` at both runtime and type levels.\n\n```ts\nimport { pascalKeys } from 'string-ts'\n\nconst data = {\n  'hello-world': {\n    'foo-bar': 'baz',\n  },\n} as const\nconst result = pascalKeys(data)\n//    ^ { HelloWorld: { FooBar: 'baz' } }\n```\n\n### snakeKeys\n\nThis function shallowly converts the keys of an object to `snake_case` at both runtime and type levels.\n\n```ts\nimport { snakeKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = snakeKeys(data)\n//    ^ { 'hello_world': { 'fooBar': 'baz' } }\n```\n\n### replaceKeys\n\nThis function shallowly transforms the keys of an object by applying [`replace`](#replace) to each of its keys at both runtime and type levels.\n\n```ts\nimport { replaceKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = replaceKeys(data, 'o', 'a')\n//    ^ { 'hellaWorld': { 'fooBar': 'baz' } }\n```\n\n## Strongly-typed deep transformation of objects\n\n### deepCamelKeys\n\nThis function recursively converts the keys of an object to `camelCase` at both runtime and type levels.\n\n```ts\nimport { deepCamelKeys } from 'string-ts'\n\nconst data = {\n  'hello-world': {\n    'foo-bar': 'baz',\n  },\n} as const\nconst result = deepCamelKeys(data)\n//    ^ { helloWorld: { fooBar: 'baz' } }\n```\n\n### deepConstantKeys\n\nThis function recursively converts the keys of an object to `CONSTANT_CASE` at both runtime and type levels.\n\n```ts\nimport { deepConstantKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = deepConstantKeys(data)\n//    ^ { 'HELLO_WORLD': { 'FOO_BAR': 'baz' } }\n```\n\n### deepDelimiterKeys\n\nThis function recursively converts the keys of an object to a new case with a custom delimiter at both runtime and type levels.\n\n```ts\nimport { deepDelimiterKeys } from 'string-ts'\n\nconst data = {\n  'hello-world': {\n    'foo-bar': 'baz',\n  },\n} as const\nconst result = deepDelimiterKeys(data, '.')\n//    ^ { 'hello.world': { 'foo.bar': 'baz' } }\n```\n\n### deepKebabKeys\n\nThis function recursively converts the keys of an object to `kebab-case` at both runtime and type levels.\n\n```ts\nimport { deepKebabKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = deepKebabKeys(data)\n//    ^ { 'hello-world': { 'foo-bar': 'baz' } }\n```\n\n### deepPascalKeys\n\nThis function recursively converts the keys of an object to `PascalCase` at both runtime and type levels.\n\n```ts\nimport { deepPascalKeys } from 'string-ts'\n\nconst data = {\n  'hello-world': {\n    'foo-bar': 'baz',\n  },\n} as const\nconst result = deepPascalKeys(data)\n//    ^ { HelloWorld: { FooBar: 'baz' } }\n```\n\n### deepSnakeKeys\n\nThis function recursively converts the keys of an object to `snake_case` at both runtime and type levels.\n\n```ts\nimport { deepSnakeKeys } from 'string-ts'\n\nconst data = {\n  helloWorld: {\n    fooBar: 'baz',\n  },\n} as const\nconst result = deepSnakeKeys(data)\n//    ^ { 'hello_world': { 'foo_bar': 'baz' } }\n```\n\n## Type utilities\n\nAll the functions presented in this API have associated type counterparts.\n\n```ts\nimport type * as St from 'string-ts'\n```\n\n### Native TS type utilities\n\n```ts\nCapitalize\u003c'hello world'\u003e // 'Hello world'\nLowercase\u003c'HELLO WORLD'\u003e // 'hello world'\nUppercase\u003c'hello world'\u003e // 'HELLO WORLD'\n```\n\n### General type utilities from this library\n\n```ts\nSt.CharAt\u003c'hello world', 6\u003e // 'w'\nSt.Concat\u003c['a', 'bc', 'def']\u003e // 'abcdef'\nSt.EndsWith\u003c'abc', 'c'\u003e // true\nSt.Includes\u003c'abcde', 'bcd'\u003e // true\nSt.Join\u003c['hello', 'world'], '-'\u003e // 'hello-world'\nSt.Length\u003c'hello'\u003e // 5\nSt.PadEnd\u003c'hello', 10, '='\u003e // 'hello====='\nSt.PadStart\u003c'hello', 10, '='\u003e // '=====hello'\nSt.Repeat\u003c'abc', 3\u003e // 'abcabcabc'\nSt.Replace\u003c'hello-world', 'l', '1'\u003e // 'he1lo-world'\nSt.ReplaceAll\u003c'hello-world', 'l', '1'\u003e // 'he11o-wor1d'\nSt.Reverse\u003c'Hello World!'\u003e // '!dlroW olleH'\nSt.Slice\u003c'hello-world', -5\u003e // 'world'\nSt.Split\u003c'hello-world', '-'\u003e // ['hello', 'world']\nSt.Trim\u003c' hello world '\u003e // 'hello world'\nSt.StartsWith\u003c'abc', 'a'\u003e // true\nSt.TrimEnd\u003c' hello world '\u003e // ' hello world'\nSt.TrimStart\u003c' hello world '\u003e // 'hello world '\nSt.Truncate\u003c'hello world', 9, '[...]'\u003e // 'hello[...]\nSt.Words\u003c'hello-world'\u003e // ['hello', 'world']\n```\n\n### Casing type utilities\n\n#### Core\n\n```ts\nSt.CamelCase\u003c'hello-world'\u003e // 'helloWorld'\nSt.ConstantCase\u003c'helloWorld'\u003e // 'HELLO_WORLD'\nSt.DelimiterCase\u003c'hello world', '.'\u003e // 'hello.world'\nSt.KebabCase\u003c'helloWorld'\u003e // 'hello-world'\nSt.PascalCase\u003c'hello-world'\u003e // 'HelloWorld'\nSt.SnakeCase\u003c'helloWorld'\u003e // 'hello_world'\nSt.TitleCase\u003c'helloWorld'\u003e // 'Hello World'\n```\n\n##### Missing types\n\n_Note that we do not include `UpperCase` and `LowerCase` types. These would be too close to the existing TS types `Uppercase` and `Lowercase`._\n\nOne could create either by doing like so:\n\n```ts\ntype LowerCase\u003cT extends string\u003e = Lowercase\u003cDelimiterCase\u003cT, ' '\u003e\u003e\ntype UpperCase\u003cT extends string\u003e = Uppercase\u003cDelimiterCase\u003cT, ' '\u003e\u003e\n// or\ntype LowerCase\u003cT extends string\u003e = ReturnType\u003ctypeof lowerCase\u003cT\u003e\u003e\ntype UpperCase\u003cT extends string\u003e = ReturnType\u003ctypeof upperCase\u003cT\u003e\u003e\n```\n\n#### Shallow object key transformation\n\n```ts\nSt.CamelKeys\u003c{\n  'hello-world': { 'foo-bar': 'baz' }\n}\u003e // { helloWorld: { 'foo-bar': 'baz' } }\nSt.ConstantKeys\u003c{\n  helloWorld: { fooBar: 'baz' }\n}\u003e // { 'HELLO_WORLD': { fooBar: 'baz' } }\nSt.DelimiterKeys\u003c{ 'hello-world': { 'foo-bar': 'baz' } }, '.'\u003e\n// { 'hello.world': { 'foo-bar': 'baz' } }\nSt.KebabKeys\u003c{\n  helloWorld: { fooBar: 'baz' }\n}\u003e // { 'hello-world': { fooBar: 'baz' } }\nSt.PascalKeys\u003c{\n  'hello-world': { 'foo-bar': 'baz' }\n}\u003e // { HelloWorld: { 'foo-bar': 'baz' } }\nSt.SnakeKeys\u003c{\n  helloWorld: { fooBar: 'baz' }\n}\u003e // { 'hello_world': { fooBar: 'baz' } }\n```\n\n#### Deep object key transformation\n\n```ts\nSt.DeepCamelKeys\u003c{\n  'hello-world': { 'foo-bar': 'baz' }\n}\u003e // { helloWorld: { fooBar: 'baz' } }\nSt.DeepConstantKeys\u003c{\n  helloWorld: { fooBar: 'baz' }\n}\u003e // { 'HELLO_WORLD': { 'FOO_BAR': 'baz' } }\nSt.DeepDelimiterKeys\u003c\n  {\n    'hello-world': { 'foo-bar': 'baz' }\n  },\n  '.'\n\u003e // { 'hello.world': { 'foo.bar': 'baz' } }\nSt.DeepKebabKeys\u003c{\n  helloWorld: { fooBar: 'baz' }\n}\u003e // { 'hello-world': { 'foo-bar': 'baz' } }\nSt.DeepPascalKeys\u003c{\n  'hello-world': { 'foo-bar': 'baz' }\n}\u003e // { HelloWorld: { FooBar: 'baz' } }\nSt.DeepSnakeKeys\u003c{\n  helloWorld: { fooBar: 'baz' }\n}\u003e // { 'hello_world': { 'foo_bar': 'baz' } }\n```\n\n### Other exported type utilities\n\n```ts\nSt.IsDigit\u003c'a'\u003e // false\nSt.IsDigit\u003c'1'\u003e // true\nSt.IsLetter\u003c'a'\u003e // true\nSt.IsLetter\u003c'1'\u003e // false\nSt.IsLower\u003c'a'\u003e // true\nSt.IsLower\u003c'A'\u003e // false\nSt.IsUpper\u003c'a'\u003e // false\nSt.IsUpper\u003c'A'\u003e // true\nSt.IsSeparator\u003c' '\u003e // true\nSt.IsSeparator\u003c'-'\u003e // true\nSt.IsSeparator\u003c'a'\u003e // false\nSt.IsSpecial\u003c'a'\u003e // false\nSt.IsSpecial\u003c'!'\u003e // true\nSt.IsSpecial\u003c' '\u003e // false\n```\n\n## Runtime-only utilities\n\n### deepTransformKeys\n\nThis function recursively converts the keys of an object to a custom format, but only at runtime level.\n\n```ts\nimport { deepTransformKeys, toUpperCase } from 'string-ts'\n\nconst data = { helloWorld: 'baz' } as const\n\ntype MyType\u003cT\u003e = { [K in keyof T as Uppercase\u003cK\u003e]: T[K] }\nconst result = deepTransformKeys(data, toUpperCase) as MyType\u003ctypeof data\u003e\n//    ^ { 'HELLOWORLD': 'baz' }\n```\n\n## 🎙️ Interview\n\nFor a deeper dive into the code, reasoning, and how this library came to be, check out this interview with the author of StringTs on the Michigan TypeScript Meetup.\n\n[![StringTs on Michigan TS](https://img.youtube.com/vi/dOXpkAmmahw/0.jpg)](https://www.youtube.com/watch?v=dOXpkAmmahw)\n\n## 🐝 Contributors\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/gustavoguichard\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/566971?v=4?s=100\" width=\"100px;\" alt=\"Guga Guichard\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGuga Guichard\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=gustavoguichard\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#projectManagement-gustavoguichard\" title=\"Project Management\"\u003e📆\u003c/a\u003e \u003ca href=\"#promotion-gustavoguichard\" title=\"Promotion\"\u003e📣\u003c/a\u003e \u003ca href=\"#maintenance-gustavoguichard\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=gustavoguichard\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/issues?q=author%3Agustavoguichard\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#infra-gustavoguichard\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"#question-gustavoguichard\" title=\"Answering Questions\"\u003e💬\u003c/a\u003e \u003ca href=\"#research-gustavoguichard\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/pulls?q=is%3Apr+reviewed-by%3Agustavoguichard\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e \u003ca href=\"#ideas-gustavoguichard\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#example-gustavoguichard\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/jly36963\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/33426811?v=4?s=100\" width=\"100px;\" alt=\"Landon Yarrington\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eLandon Yarrington\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=jly36963\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-jly36963\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=jly36963\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/pulls?q=is%3Apr+reviewed-by%3Ajly36963\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e \u003ca href=\"#ideas-jly36963\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#example-jly36963\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"#question-jly36963\" title=\"Answering Questions\"\u003e💬\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/issues?q=author%3Ajly36963\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/p9f\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/20539361?v=4?s=100\" width=\"100px;\" alt=\"Guillaume\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGuillaume\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=p9f\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-p9f\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=p9f\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/issues?q=author%3Ap9f\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#infra-p9f\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"#question-p9f\" title=\"Answering Questions\"\u003e💬\u003c/a\u003e \u003ca href=\"#ideas-p9f\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://totaltypescript.com\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/28293365?v=4?s=100\" width=\"100px;\" alt=\"Matt Pocock\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMatt Pocock\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=mattpocock\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=mattpocock\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#promotion-mattpocock\" title=\"Promotion\"\u003e📣\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://luca.md\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1881266?v=4?s=100\" width=\"100px;\" alt=\"Andrew Luca\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAndrew Luca\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=iamandrewluca\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#promotion-iamandrewluca\" title=\"Promotion\"\u003e📣\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/mjuksel\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/10691584?v=4?s=100\" width=\"100px;\" alt=\"Mjuksel\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMjuksel\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=mjuksel\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#ideas-mjuksel\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://huguesverlin.fr\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/9151470?v=4?s=100\" width=\"100px;\" alt=\"hverlin\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ehverlin\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/gustavoguichard/string-ts/commits?author=hverlin\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\nStringTs logo by [NUMI](https://github.com/numi-hq/open-design):\n\n[\u003cimg src=\"https://raw.githubusercontent.com/numi-hq/open-design/main/assets/numi-lockup.png\" alt=\"NUMI Logo\" style=\"width: 200px;\"/\u003e](https://numi.tech/?ref=string-ts)\n\n## 🫶 Acknowledgements\n\nThis library got a lot of inspiration from libraries such as [lodash](https://github.com/lodash/lodash), [ts-reset](https://github.com/total-typescript/ts-reset), [type-fest](https://github.com/sindresorhus/type-fest), [HOTScript](https://github.com/gvergnaud/hotscript), and many others.\n","funding_links":[],"categories":["TypeScript","others","Types","**1. Libraries**"],"sub_categories":["IDE","Functional Programming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgustavoguichard%2Fstring-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgustavoguichard%2Fstring-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgustavoguichard%2Fstring-ts/lists"}