pipr.tools

case-convert

Convert between camelCase, snake_case, kebab-case, PascalCase

Aa Text

Try it

stdin0 chars
stdout0 chars

Flags

--to select: camel | snake | kebab | pascal | constant default: camel

Example

Convert camelCase function names

Usage
$ echo "getUserProfile
setAuthToken" | case-convert
View source
(input, opts = {}) => {
      const to = opts.to || "camel";
      const words = input
        .replace(/([a-z])([A-Z])/g, "$1 $2")
        .replace(/[-_]+/g, " ")
        .toLowerCase()
        .split(/\s+/)
        .filter(Boolean);
      switch (to) {
        case "camel":
          return words
            .map((w, i) => (i === 0 ? w : w[0].toUpperCase() + w.slice(1)))
            .join("");
        case "pascal":
          return words.map((w) => w[0].toUpperCase() + w.slice(1)).join("");
        case "snake":
          return words.join("_");
        case "kebab":
          return words.join("-");
        case "constant":
          return words.join("_").toUpperCase();
        default:
          return input;
      }
    }

Suggested Pipelines

Related Tools