项目作者: justjavac

项目描述 :
Convert strings between camelCase, PascalCase, Title Case, snake_case and more
高级语言: TypeScript
项目地址: git://github.com/justjavac/deno-change-case.git
创建时间: 2019-07-08T07:34:47Z
项目社区:https://github.com/justjavac/deno-change-case

开源协议:MIT License

下载


Change Case

Convert strings between camelCase, PascalCase, Title Case, snake_case,
lowercase, UPPERCASE, CONSTANT_CASE and more.

All methods support Unicode (non-ASCII characters) and non-string entities, such
as objects with a toString property, numbers and booleans. Empty values
(null and undefined) will result in an empty string.

Source code based on
blakeembrey/change-case with
TypeScript.

Usage

  1. import { camelCase } from "https://deno.land/x/case/mod.ts";
  2. camelCase("test string");
  3. // => 'testString'

or

  1. import camelCase from "https://deno.land/x/case/camelCase.ts";
  2. camelCase("test string");
  3. // => 'testString'

Available methods (short-hand shown below, long-hand available in examples):

All methods accept two arguments, the string to change case and an optional
locale.

camelCase

Return as a string with the separators denoted by having the next letter
capitalized.

  1. camelCase("test string");
  2. //=> "testString"

constantCase

Return as an upper case, underscore separated string.

  1. constantCase("test string");
  2. //=> "TEST_STRING"

dotCase

Return as a lower case, period separated string.

  1. dotCase("test string");
  2. //=> "test.string"

headerCase

Return as a title cased, dash separated string.

  1. headerCase("test string");
  2. //=> "Test-String"

lowerCase

Return the string in lower case.

  1. lowerCase("TEST STRING");
  2. //=> "test string"

lowerFirstCase

Return the string with the first character lower cased.

  1. lowerFirstCase("TEST");
  2. //=> "tEST"

normalCase

  • no
  • clear

Return the string without any casing (lower case, space separated).

  1. normalCase("test string");
  2. //=> "test string"

paramCase

Aliases

  • kebabCase
  • hyphenCase

Return as a lower case, dash separated string.

  1. paramCase("test string");
  2. //=> "test-string"

pascalCase

Return as a string denoted in the same fashion as camelCase, but with the
first letter also capitalized.

  1. pascalCase("test string");
  2. //=> "TestString"

pathCase

Return as a lower case, slash separated string.

  1. pathCase("test string");
  2. //=> "test/string"

sentenceCase

Return as a lower case, space separated string with the first letter upper case.

  1. sentenceCase("testString");
  2. //=> "Test string"

snakeCase

Return as a lower case, underscore separated string.

  1. snakeCase("test string");
  2. //=> "test_string"

swapCase

Return as a string with every character case reversed.

  1. swapCase("Test String");
  2. //=> "tEST sTRING"

titleCase

Return as a space separated string with the first character of every word upper
cased.

  1. titleCase("a simple test");
  2. //=> "A Simple Test"

upperCase

Return the string in upper case.

  1. upperCase("test string");
  2. //=> "TEST STRING"

upperFirstCase

Return the string with the first character upper cased.

  1. upperFirstCase("test");
  2. //=> "Test"

Credits

License

deno-change-case is released under the MIT License. See the bundled
LICENSE file for details.