match-casing
Match the case of value
to that of base
.
Installation
npm:
npm install match-casing
Usage
var casing = require('match-casing')
casing('foo', 'BAZ')
casing('foo', 'Baz')
casing('foo', 'baz')
casing('foo', 'BaZ')
casing('FOO', 'BAZ')
casing('FOO', 'Baz')
casing('FOO', 'baz')
casing('FOO', 'BaZ')
casing('Foo', 'BAZ')
casing('Foo', 'Baz')
casing('Foo', 'baz')
casing('Foo', 'BaZ')
casing('’90S', '’twas')
casing('’N’', 'a')
API
matchCasing(value, base)
Transform the case in value
(string
) to match that of base
(string
).
Algorithm
- If
base
is uppercase, value
is uppercased - Else, if
base
is lowercase, value
is lowercased - Else, if the first alphabetic character in
base
is uppercase,
and the rest of base
is lowercase, uppercase the first alphabetic
character in value
and lowercase the rest - Else, return
value
unmodified
The third case, where value
takes on a capitalised, deals with
initial non-alphabetical characters as expected.
License
MIT © Titus Wormer