File Casing

Transform file and folder names to different case formats before adding them to your project.

The @jsrepo/transform-filecasing package is a transform plugin for jsrepo that transforms file and folder names to different case formats before adding them to your project.

This is useful when your project follows a specific file or folder naming convention and you want registry items to automatically conform to it.

The transform only affects the item's relative path, not the base path configured in your jsrepo.config. For example, if your config specifies src/lib/components/ui as the path for components, and you add a button component, only the part after that base path is transformed: button/index.tsButton/Index.ts, resulting in src/lib/components/ui/Button/Index.ts.

Installation

To add the @jsrepo/transform-filecasing transform to your config run the following command:

jsrepo config transform filecasing

This will automatically install the transform and add it to your config:

import { defineConfig } from "jsrepo";
import fileCasing from "@jsrepo/transform-filecasing"; 

export default defineConfig({
	transforms: [fileCasing({ to: "camel" })], 
});

Now when a file is added to your project its file and folder names will be transformed to the target case format. Note that only the item's relative path is transformed, not the base path from your config:

Config path: 'src/lib/components/ui', Item: 'button/index.ts' → Result: 'src/lib/components/ui/Button/Index.ts'
// Config path: 'src/lib/components/ui'
// Item path: 'button/index.ts'
// Result: 'src/lib/components/ui/Button/Index.ts'

Configuration

The transform accepts an options object with the following properties:

OptionTypeDescription
to"kebab" | "camel" | "snake" | "pascal"The target case format for file and folder names
transformDirectoriesbooleanWhether to transform directory segments in the path. When false, only the filename baseName is transformed. Defaults to true

Transform Directories and Filenames (Default)

By default, both directory segments and filenames are transformed:

import { defineConfig } from "jsrepo";
import fileCasing from "@jsrepo/transform-filecasing";

export default defineConfig({
	// Config path: 'src/lib/components/ui'
	transforms: [fileCasing({ to: "pascal" })],
});

This will transform the item's relative path:

  • Item: button/index.ts → Result: src/lib/components/ui/Button/Index.ts
  • Item: my-components/use-hook.ts → Result: src/lib/components/ui/MyComponents/UseHook.ts

Note that the config path (src/lib/components/ui) is never transformed.

Transform Only Filenames

To preserve directory names and only transform filenames, set transformDirectories to false:

import { defineConfig } from "jsrepo";
import fileCasing from "@jsrepo/transform-filecasing";

export default defineConfig({
	transforms: [fileCasing({ to: "camel", transformDirectories: false })],
});

This will transform only the filename in the item's relative path:

  • Item: my-components/use-hook.ts → Result: src/lib/components/ui/my-components/useHook.ts
  • Item: button/index.ts → Result: src/lib/components/ui/button/index.ts

Note that directory names in the item path are preserved, and the config path is never transformed.

This only transforms directories and files within added items and will never rename existing files or directories in your project.