Giter Club home page Giter Club logo

case's Introduction

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

Download: Case.min.js or Case.js
Bower: bower install Case (note the big 'C')
NPM: npm install case (little 'c' due to NPM restrictions)

Documentation

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

Case.upper('foo_bar')                       -> 'FOO BAR'
Case.lower('fooBar')                        -> 'foo bar'
Case.snake('Foo bar!')                      -> 'foo_bar'
Case.squish('foo.bar')                      -> 'FooBar'
Case.camel('foo, bar')                      -> 'fooBar'
Case.constant('Foo-Bar')                    -> 'FOO_BAR'
Case.title('foo v. bar')                    -> 'Foo v. Bar'
Case.capital('foo_v_bar')                   -> 'Foo V Bar'
Case.sentence('"foo!" said bar', ['Bar'])   -> '"Foo!" said Bar'

sentence(str, names) 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).

There are three additional functions:

  • of(str): identifies the case of a string, returns undefined if it doesn't match a known type
  • flip(str): reverses the case of letters, no other changes
  • type(name, fn): extends Case with a new case type
Case.of('foo')          -> 'lower'
Case.of('foo_bar')      -> 'snake'
Case.of('Foo v Bar')    -> 'title'
Case.of('foo_ Bar')     -> undefined

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

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

Registering functions via type() means Case.of supports them automatically.

Oh, did you notice that little Case.upper(s, '!')? Yeah, upper() and lower() accept a second "fill" argument that will replace any characters which are not letters or numbers. It's handy, sometimes. :)

Release History

  • 2013-06-10 v1.0.0 (public, initial)
  • 2013-06-20 v1.0.1 (regex improvements)
  • 2013-08-23 v1.0.3 (better support for Node, Component and AMD)

case's People

Contributors

ianstormtaylor avatar nbubna avatar yields avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.