Extract a Reusable Library From Repeated Code
Turn duplicated code into a tested shared component.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
Extract shared code. Examples of repeated code: [CODE_EXAMPLES]. Where it is used: [USAGE_LOCATIONS]. Language: [LANGUAGE]. Consumers: [CONSUMERS]. Compare the copies and list differences that matter. Propose an interface that covers the common behaviour with explicit options for differences, avoiding a parameter explosion. Write the plan to create the library, test it, publish or share it, and migrate one consumer at a time. Return the proposed API, a table of differences between copies, tests to write, a versioning approach, a deprecation plan for the old code, and the cases where duplication is better than abstraction. Do not merge code that merely looks alike but changes for different reasons. Add the process for naming and documenting the library: a one-paragraph description, install and usage examples, a changelog, and a policy for who may change it. Explain how to avoid breaking consumers with semantic versioning and a short list of tests that every consumer must pass. Provide an example showing two similar functions with a small difference and how options keep a single implementation readable.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.