parsing-and-mutating-strings

Utilities in this library which provide effective ways to parse or mutate text at both runtime and design-time while ensuring that the resulting type is as narrow as possible.

⭐18stars🔀0forks📁View on GitHub🕐Updated Nov 21, 2025⬇️2downloads

When & Why to Use This Skill

This Claude skill provides a robust suite of utilities designed for high-precision string manipulation and parsing. It excels at both runtime execution and design-time type inference, ensuring that string transformations result in the narrowest possible TypeScript types. It is an essential tool for developers who need to maintain strict type safety while performing complex text mutations, such as stripping delimiters, retaining specific substrings, or parsing structured language features.

Use Cases

  • Type-Safe Data Transformation: Use runtime utilities to mutate strings while ensuring the TypeScript compiler recognizes the exact literal result, reducing 'any' or 'string' type pollution.
  • Advanced Text Cleaning: Efficiently strip or retain content based on specific delimiters (e.g., stripping everything after a semicolon or retaining content between brackets) for data sanitization.
  • Structured Language Parsing: Implement complex parsing logic for domain-specific languages (DSLs) where string segments require different rules based on preceding characters.
  • Automated Code Refactoring: Leverage design-time utilities to programmatically transform string literals within a codebase while maintaining type integrity.
nameParsing and Mutating Strings
descriptionUtilities in this library which provide effective ways to parse or mutate text at both runtime and design-time while ensuring that the resulting type is as narrow as possible.

Parsing and Mutating Strings

Instructions

  1. Identify which of the two best describe your needs:

    1. Simple
      • finding a sub-string inside a string variable
      • stripping or retaining content UNTIL a certain delimiter is found
      • ensuring that the string starts or ends with a certain sub-string
    2. Structured
      • you need to parse a string for language features
      • different parts of the string will have different parsing rules based on the characters which preceded it.
  2. If your need fits the Simple description then ...

    You will likely want to use one of the following type or runtime utilities found in this repo. Every utility's source will have a description above the symbol and many also may include a simple example.

    Type Utilities

    you can import all of these utilities from inferred-types/types

  3. If your need fits the Structured need then ...


Notes:

  • there is often (but not always) a 1:1 relationship between a type utility and a runtime function.
    • The runtime function (often but not always) will leverage the corresponding type utility to produce narrow types.
  • many example links are to test files; these test files use both runtime and type tests. For more about type tests you can read type testing document.