New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

variable-name-conversion

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

variable-name-conversion

To easily convert a variable name to camelCase, kebab-case, etc.

latest
Source
npmnpm
Version
1.7.0
Version published
Maintainers
1
Created
Source

Variable Name Conversion

npm GitHub License: MIT

To easily convert a variable name to camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, etc.

Supports strong typing hints of TypeScript for static strings.

Installation

# npm
npm install variable-name-conversion

# yarn
yarn add variable-name-conversion

# pnpm
pnpm add variable-name-conversion

Usage

Value with Type

import VariableName from "variable-name-conversion";

const camel = new VariableName("hello_world").camel; //=> "helloWorld"
const kebab = new VariableName("fooBarBaz").kebab; //=> "foo-bar-baz"

Type only

Useful when you want to use static string type conversion without introduce runtime.

import type VariableName from "variable-name-conversion";

type Camel = VariableName<"hello_world">["camel"]; //=> "helloWorld"
type Kebab = VariableName<"fooBarBaz">["kebab"]; //=> "foo-bar-baz"

Cases

CaseExampleNotes
camelcamelCase
pascalPascalCase
kebabkebab-case
snakesnake_case
constCONSTANT_CASE
trainTrain-Case
cobolCOBOL-CASE
pascalSnakePascal_Snake_Case
camelSnakecamel_Snake_Case
dotdot.case
pathpath/case
pathAltpath\alt\case
lowerlowercaseWith no separators.
upperUPPERCASEWith no separators.
wordsword caseSeparated by spaces, all in lowercase.
sentenceSentence caseSeparated by spaces, with only the first letter of the sentence capitalized.
titleTitle CaseSeparated by spaces, with all first letters of words capitalized.
cssVar--css-custom-property-name-formkebab-case with two dashes as the prefix.
cssPropcss-property-name-form
-webkit-css-property-name-form
Just like kebab-case, but if the first word is in "webkit", "moz", "ms", "o", it will use one dash as the prefix.

Options

keepCase

Should it maintain case sensitivity when converting to kebab-case, snake_case, etc.?

Default: false

Example:

const snakeI = new VariableName("XMLHttpRequest").snake; //=> "xml_http_request"
const snakeS = new VariableName("XMLHttpRequest", true).snake; //=> "XML_Http_Request"

const camelI = new VariableName("XMLHttpRequest").camel; //=> "xmlHttpRequest"
const camelS = new VariableName("XMLHttpRequest", true).camel; //=> "XMLHttpRequest"

type SnakeI = VariableName<"XMLHttpRequest">["snake"]; //=> "xml_http_request"
type SnakeS = VariableName<"XMLHttpRequest", true>["snake"]; //=> "XML_Http_Request"

type CamelI = VariableName<"XMLHttpRequest">["camel"]; //=> "xmlHttpRequest"
type CamelS = VariableName<"XMLHttpRequest", true>["camel"]; //=> "XMLHttpRequest"

With numbers

Special case when handling value mixed with numbers.

Example:

const snake1 = new VariableName("resolve404Error").snake; //=> "resolve_404_error"
const snake2 = new VariableName("watch3d1080pVideo").snake; //=> "watch_3d_1080p_video"

type Snake1 = VariableName<"resolve404Error">["snake"]; //=> "resolve_404_error"
type Snake2 = VariableName<"watch3d1080pVideo">["snake"]; //=> "watch_3d_1080p_video"

License

variable-name-conversion is available under the MIT License. See the LICENSE file for more info.

Keywords

variable

FAQs

Package last updated on 29 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts