swapcase
v1.1.0
Published
A letter case swapper with full Unicode support, i.e. based on the official Unicode case folding mappings.
Downloads
9
Maintainers
Readme
swapcase
swapcase is a letter case swapper with full Unicode support, i.e. based on the official Unicode case folding mappings.
Installation
Via npm:
npm install swapcase
Via Bower:
bower install swapcase
Via Component:
component install mathiasbynens/swapcase
In a browser:
<script src="swapcase.js"></script>
In Narwhal, Node.js, and RingoJS:
var swapCase = require('swapcase');
In Rhino:
load('swapcase.js');
Using an AMD loader like RequireJS:
require(
{
'paths': {
'swapcase': 'path/to/swapcase'
}
},
['swapcase'],
function(swapCase) {
console.log(swapCase);
}
);
API
swapCase.version
A string representing the semantic version number.
swapCase(text)
This function takes a string of text and swaps the case for each letter: lowercase letters become uppercase letters, and vice versa. All the Unicode ‘Full’ case folding mappings are used.
swapcase.encode('aBcDeFg');
// → 'AbCdEfG'
Using the swapcase
binary
To use the swapcase
binary in your shell, simply install swapcase globally using npm:
npm install -g swapcase
After that you will be able to case-swap text from the command line:
$ swapcase 'föo ♥ bår 𝌆 baz'
FÖO ♥ BÅR 𝌆 BAZ
Read a local text file, case-swap any letters it contains, and save the result to a new file:
$ swapcase < foo.txt > foo-case-swapped.html
Or do the same with an online text file:
$ curl -sL "http://git.io/HnfEaw" | swapcase > case-swapped.html
See swapcase --help
for the full list of options.
Support
swapcase has been tested in at least Chrome 27-29, Firefox 3-22, Safari 4-6, Opera 10-12, IE 6-10, Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, and Rhino 1.7RC4.
Unit tests & code coverage
After cloning this repository, run npm install
to install the dependencies needed for swapcase development and testing. You may want to install Istanbul globally using npm install istanbul -g
.
Once that’s done, you can run the unit tests in Node using npm test
or node tests/tests.js
. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use grunt test
.
To generate the code coverage report, use grunt cover
.
Author
| | |---| | Mathias Bynens |
License
swapcase is available under the MIT license.