Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @shipengine/capitalization with all npm packages installed. Try it out:

var capitalization = require("@shipengine/capitalization")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@shipengine/capitalization v1.2.1

String capitalization functions with special cases for certain ShipEngine words and phrases

ShipEngine Capitalization

String capitalization functions with special cases for certain ShipEngine words and phrases

Cross-Platform Compatibility Build Status

Coverage Status Dependencies

npm License

Example

import { snakeCase, pascalCase, titleCase } from "@shipengine/capitalization";

snakeCase("TheShipEngineSDKForWoocommerce");        // --> the_shipengine_sdk_for_woo_commerce
pascalCase("the_shipengine_sdk_for_woocommerce");   // --> TheShipEngineSdkForWooCommerce
titleCase("theShipengineSDKForWoocommerce");        // --> The ShipEngine SDK for WooCommerce

Installation

You can install ShipEngine Capitalization via npm.

npm install @shipengine/capitalization

Usage

You can import the specific capitalization function(s) that you need to use:

import { kebabCase, camelCase, sentenceCase } from "@shipengine/capitalization";

Or you can import the entire capitalization module and use its methods:

import capitalization from "@shipengine/capitalization";

capitalization.kebabCase("some text");

API

ShipEngine Capitalization exports several different capitalization functions, each of which accepts the same parameters:

  • text - A string containing one or more words. The string can be in any format (snake case, camel case, pascal case, sentence case, etc.)

  • options - An optional Options object

snakeCase(text, [options])

Snake case strings are all lowercase with underscores as word separators. No whitespace or punctuation characters are allowed, and the string must begin with a letter.

Example inputsExample outputs
Hello, World!hello_world
TheShipEngineAPIthe_shipengine_api

kebabCase(text, [options])

Kebab case strings are all lowercase with hyphens as word separators. No whitespace or punctuation characters are allowed, and the string must begin with a letter.

Example inputsExample outputs
Hello, World!hello-world
TheShipEngineAPIthe-shipengine-api

camelCase(text, [options])

Camel case strings use capitalization as word separators. Each new word begins with a capital letter, followed by lowercase letters. No whitespace or punctuation characters are allowed, and the string must begin with a lowercase letter.

Example inputsExample outputs
Hello, World!helloWorld
this is the shipengine apithisIsTheShipEngineApi

pascalCase(text, [options])

Pascal case strings use capitalization as word separators. Each new word begins with a capital letter, followed by lowercase letters. No whitespace or punctuation characters are allowed, and the string must begin with an uppercase letter.

Example inputsExample outputs
Hello, World!HelloWorld
this is the shipengine apiThisIsTheShipEngineApi

sentenceCase(text, [options])

Sentence case strings follow basic English sentence rules. Words are separated by spaces. The first word is capitalized, and most other words are lowercase, except for proper nouns and acronyms. Punctuation characters are allowed.

Example inputsExample outputs
hello_worldHello world
this is the shipengine apiThis is the ShipEngine API

titleCase(text, [options])

Title case strings follow title case rules. Words are separated by spaces, most words are capitalized, and punctuation characters are allowed.

Example inputsExample outputs
hello_worldHello World
this is the shipengine apiThis is the ShipEngine API

Options object

All of the ShipEngine Capitalization function accept an optional second argument, which is an options object. This object can contain any of the following options:

OptionTypeDefaultDescription
prefixstringn/aA prefix to be used when the result would otherwise be invalid due to starting with an illegal character.

For example, snakeCase("4x6 label") would throw an error because snake case strings cannot start with a number. But snakeCase("4x6 label", { prefix: "size" }) would return size_4x6_label.

Note: The prefix is only added when needed. So snakeCase("label size 4x6", { prefix: "size" }) would not use the prefix.
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free