Add Cookie Path To All Methods
Add Cookie Path to All Methods
This codemod adds { path: '/' }
to all cookies
method calls in your TypeScript project. It ensures that cookies are set, deleted, or serialized with the correct path specified, which helps in consistent cookie handling across different environments.
Transformations
This codemod performs the following transformations:
- Set Cookie: Transforms
cookies.set(key, value)
intocookies.set(key, value, { path: '/' })
. - Delete Cookie: Transforms
cookies.delete(key)
intocookies.delete(key, { path: '/' })
. - Serialize Cookie: Transforms
cookies.serialize(key, value)
intocookies.serialize(key, value, { path: '/' })
.
Usage
To apply this codemod, run the workflow script on your TypeScript files. Ensure you have the necessary dependencies installed and your project is configured to use this codemod.
Example
Before
cookies.set('session', 'abc123');cookies.delete('user');cookies.serialize('token', 'xyz789');
After
cookies.set('session', 'abc123', { path: '/' });cookies.delete('user', { path: '/' });cookies.serialize('token', 'xyz789', { path: '/' });
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community