P

add-cookie-path-to-all-methods

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

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) into cookies.set(key, value, { path: '/' }).
  • Delete Cookie: Transforms cookies.delete(key) into cookies.delete(key, { path: '/' }).
  • Serialize Cookie: Transforms cookies.serialize(key, value) into cookies.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

typescript

After

ts

Ready to contribute?

Build your own codemod and share it with the community.