Case 1.6.0

An extensible utility to convert, identify, and flip string case.

There is a newer version of this package available.
See the version list below for details.
Install-Package Case -Version 1.6.0
dotnet add package Case --version 1.6.0
<PackageReference Include="Case" Version="1.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Case --version 1.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Case, 1.6.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Case as a Cake Addin
#addin nuget:?package=Case&version=1.6.0

// Install Case as a Cake Tool
#tool nuget:?package=Case&version=1.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Case: An extensible utility to convert, identify, and flip string case.

Download: Case.min.js or Case.js
NPM: npm install case (little 'c' due to NPM restrictions)
NuGet: Install-Package Case

Build Status NPM version NPM

Documentation

Each of the following functions will first "undo" previous case manipulations before applying the desired case to the given string.

Foundations

Case.upper('foo_bar')     -> 'FOO BAR'
Case.lower('fooBar')      -> 'foo bar'
Case.capital('foo_v_bar') -> 'Foo V Bar'

Code Helpers

Case.snake('Foo bar!')   -> 'foo_bar'
Case.pascal('foo.bar')   -> 'FooBar'
Case.camel('foo, bar')   -> 'fooBar'
Case.kebab('Foo? Bar.')  -> 'foo-bar'
Case.header('fooBar=')   -> 'Foo-Bar'
Case.constant('Foo-Bar') -> 'FOO_BAR'

UI Helpers

Case.title('foo v. bar')                    -> 'Foo v. Bar'
Case.sentence('"foo!" said bar', ['Bar'])   -> '"Foo!" said Bar'
Case.sentence('the 12 oz. can', null, ['oz'])   -> 'The 12 oz. can'

Case.sentence(str, names, abbreviations) accepts an array of proper names that should be capitalized, regardless of location in the sentence. This function is specialized, but useful when dealing with input generated with capslock on (i.e. everything my grandma types). It can also accept a list of abbreviations (words that may end in a period but aren't meant to end a sentence).

Custom Casing

Case.lower('FOO-BAR', '.')                  -> 'foo.bar'
Case.upper('Foo? Bar.', '__')               -> 'FOO__BAR'
Case.capital('fooBar', ' + ')               -> 'Foo + Bar'

Case.lower("Don't keep 'em!", "/", true)    -> 'dont/keep/em'
Case.capital("'ello, world.", null, true)   -> 'Ello, World.'

Case.upper, Case.lower, and Case.capital accept an optional "fill" value that will replace any characters which are not letters and numbers. All three also accept a third optional boolean argument indicating if apostrophes are to be stripped out or left in. For example, programmatic case changes (snake, kebab, pascal, camel, constant) are best without apostrophes, but user-facing ones (title, sentence) do not want "don't" turned into "Dont".

Extending Case

Case.type('bang', function(s) {
    return Case.upper(s, '!')+'!';
});
Case.bang('bang')       -> 'BANG!'
Case.of('TEST!THIS!')   -> 'bang'

Case.type(name, fn): extends Case, creating a new function on Case and adding Case.of support automatically.

Utilities

Case.of('foo')          -> 'lower'
Case.of('foo_bar')      -> 'snake'
Case.of('Foo v Bar')    -> 'title'
Case.of('foo_ Bar')     -> undefined

Case.of('Hello there, Bob!', ['Bob']) -> 'sentence'

Case.flip('FlipMe')     -> 'fLIPmE'
Case.flip('TEST THIS!') -> 'test this!'

Case.random('Hello!')   -> 'hElLO!'
  • Case.of(str[, names]): identifies the case of a string, returns undefined if it doesn't match a known type
  • Case.flip(str): reverses the case of letters, no other changes
  • Case.random(str): randomizes the case of letters, no other changes

Case: An extensible utility to convert, identify, and flip string case.

Download: Case.min.js or Case.js
NPM: npm install case (little 'c' due to NPM restrictions)
NuGet: Install-Package Case

Build Status NPM version NPM

Documentation

Each of the following functions will first "undo" previous case manipulations before applying the desired case to the given string.

Foundations

Case.upper('foo_bar')     -> 'FOO BAR'
Case.lower('fooBar')      -> 'foo bar'
Case.capital('foo_v_bar') -> 'Foo V Bar'

Code Helpers

Case.snake('Foo bar!')   -> 'foo_bar'
Case.pascal('foo.bar')   -> 'FooBar'
Case.camel('foo, bar')   -> 'fooBar'
Case.kebab('Foo? Bar.')  -> 'foo-bar'
Case.header('fooBar=')   -> 'Foo-Bar'
Case.constant('Foo-Bar') -> 'FOO_BAR'

UI Helpers

Case.title('foo v. bar')                    -> 'Foo v. Bar'
Case.sentence('"foo!" said bar', ['Bar'])   -> '"Foo!" said Bar'
Case.sentence('the 12 oz. can', null, ['oz'])   -> 'The 12 oz. can'

Case.sentence(str, names, abbreviations) accepts an array of proper names that should be capitalized, regardless of location in the sentence. This function is specialized, but useful when dealing with input generated with capslock on (i.e. everything my grandma types). It can also accept a list of abbreviations (words that may end in a period but aren't meant to end a sentence).

Custom Casing

Case.lower('FOO-BAR', '.')                  -> 'foo.bar'
Case.upper('Foo? Bar.', '__')               -> 'FOO__BAR'
Case.capital('fooBar', ' + ')               -> 'Foo + Bar'

Case.lower("Don't keep 'em!", "/", true)    -> 'dont/keep/em'
Case.capital("'ello, world.", null, true)   -> 'Ello, World.'

Case.upper, Case.lower, and Case.capital accept an optional "fill" value that will replace any characters which are not letters and numbers. All three also accept a third optional boolean argument indicating if apostrophes are to be stripped out or left in. For example, programmatic case changes (snake, kebab, pascal, camel, constant) are best without apostrophes, but user-facing ones (title, sentence) do not want "don't" turned into "Dont".

Extending Case

Case.type('bang', function(s) {
    return Case.upper(s, '!')+'!';
});
Case.bang('bang')       -> 'BANG!'
Case.of('TEST!THIS!')   -> 'bang'

Case.type(name, fn): extends Case, creating a new function on Case and adding Case.of support automatically.

Utilities

Case.of('foo')          -> 'lower'
Case.of('foo_bar')      -> 'snake'
Case.of('Foo v Bar')    -> 'title'
Case.of('foo_ Bar')     -> undefined

Case.of('Hello there, Bob!', ['Bob']) -> 'sentence'

Case.flip('FlipMe')     -> 'fLIPmE'
Case.flip('TEST THIS!') -> 'test this!'

Case.random('Hello!')   -> 'hElLO!'
  • Case.of(str[, names]): identifies the case of a string, returns undefined if it doesn't match a known type
  • Case.flip(str): reverses the case of letters, no other changes
  • Case.random(str): randomizes the case of letters, no other changes

Dependencies

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.6.3 311 3/24/2020
1.6.2 322 7/26/2019
1.6.1 458 1/11/2019
1.6.0 418 11/15/2018
1.5.5 709 5/4/2018
1.5.3 623 7/11/2017
1.5.0 674 3/10/2017