Code Monkey home page Code Monkey logo

mockingcase's Introduction

mOcKiNgCaSe Build Status

Convert a string to mOcKiNgCaSe.

Read more on wikipedia Studly caps.

mocking spongebob

Inspired by the meme Mocking Spongebob and http://dannypage.github.io/spongebob.html

Install

npm install @strdr4605/mockingcase --save

Usage

const mOcKiNgCaSe = require('@strdr4605/mockingcase');
// es6 - import mOcKiNgCaSe from '@strdr4605/mockingcase';
//  ts - import * as mOcKiNgCaSe from '@strdr4605/mockingcase';
//  ts - import mOcKiNgCaSe = require('@strdr4605/mockingcase');

mOcKiNgCaSe('foo-bar');
//=> 'fOo-bAr'

mOcKiNgCaSe('aa', {random: false});
//=> 'aA'

mOcKiNgCaSe('aa', {random: true});
//=> 'aa'
//=> 'aA'
//=> 'Aa'
//=> 'AA'

mOcKiNgCaSe('42foo!bar');
//=> '42fOo!bAr'

mOcKiNgCaSe('aa123', {onlyLetters: true});
//=> 'aA'

mOcKiNgCaSe('a13%$a', {onlyLetters: true});
//=> 'aA'

mOcKiNgCaSe('foo bar', {firstUpper: true});
//=> 'FoO BaR'

mOcKiNgCaSe('foo', {firstUpper: true, random: true});
//=> 'Foo'
//=> 'FOo'
//=> 'FoO'
//=> 'FOO'

mOcKiNgCaSe('abcdef', {upper: /[bdf]/});
//=> 'aBcDeF'

mOcKiNgCaSe('ABCDEF', {lower: 'bcd'});
//=> 'abcdeF'

API

mOcKiNgCaSe(input, [options]) ⇒ string

Converts the input string(s) to mOcKiNgCaSe.

Kind: global function Returns: string - string in mOcKiNgCaSe

Param Type Default Description
input string | string[] String(s) to be converted
[options] object {random: false, onlyLetters: false, firstUpper: false} Conversion options
options.random boolean false If case conversion should be randomized
options.onlyLetters boolean false If non letters characters should be removed
options.firstUpper boolean false If the first letter should be capitalized instead of the second when converting to mOcKiNgCaSe (e.g. MoCkInGcAsE). When combined with options.random, the first letter of the random string will be capitalized
options.upper RegExp | string null Characters or substring set to change to uppercase
options.lower RegExp | string null Characters or substring set to change to lowercase
mOcKiNgCaSe('foo-bar');
//=> 'fOo-bAr'

mOcKiNgCaSe('aa', {random: false});
//=> 'aA'

mOcKiNgCaSe('aa', {random: true});
//=> 'aa'
//=> 'aA'
//=> 'Aa'
//=> 'AA'

mOcKiNgCaSe('42foo!bar');
//=> '42fOo!bAr'

mOcKiNgCaSe('aa123', {onlyLetters: true});
//=> 'aA'

mOcKiNgCaSe('a13%$a', {onlyLetters: true});
//=> 'aA'

mOcKiNgCaSe('foo bar', {firstUpper: true});
//=> 'FoO BaR'

mOcKiNgCaSe('foo bar', {firstUpper: true, lower: /[fb]/});
//=> 'foO baR'

mOcKiNgCaSe('foo bar', {firstUpper: true, upper: /[oa]/});
//=> 'FOO BAR'

mOcKiNgCaSe('foo', {firstUpper: true, random: true});
//=> 'Foo'
//=> 'FOo'
//=> 'FoO'
//=> 'FOO'

mOcKiNgCaSe(['foo','bar']);
//=> 'fOoBaR'

mOcKiNgCaSe(undefined);
//=> Error "An input is required"

mOcKiNgCaSe.overrideString() ⇒ mOcKiNgCaSe

Creates String.prototype.toMockingCase().

Kind: global function Returns: mOcKiNgCaSe - The mOcKiNgCaSe module. See: toMockingCase

mOcKiNgCaSe.overrideString();

'foo_bar'.toMockingCase();
//=> 'fOo_bAr'

'foo_bar'.toMockingCase({firstUpper: true});
//=> 'FoO_BaR'

String.prototype.toMockingCase([options]) ⇒ string

Converts this string to mOcKiNgCaSe.

NOTE: this function is created by invoking mOcKiNgCaSe.overrideString().

Kind: prototype Returns: string - local string in mOcKiNgCaSe

Param Type Default Description
[options] object {random: false, onlyLetters: false, firstUpper: false} Conversion options
options.random boolean false If case conversion should be randomized
options.onlyLetters boolean false If non letters characters should be removed
options.firstUpper boolean false If the first letter should be capitalized instead of the second when converting to mOcKiNgCaSe (e.g. MoCkInGcAsE). When combined with options.random, the first letter of the random string will be capitalized
options.upper RegExp | string null Characters or substring set to change to uppercase
options.lower RegExp | string null Characters or substring set to change to lowercase
'foo_bar'.toMockingCase();
//=> 'fOo_bAr'

'foo_bar'.toMockingCase({firstUpper: true});
//=> 'FoO_BaR'

mOcKiNgCaSe.config(defaultOptions) ⇒ mOcKiNgCaSe

Outputs a mOcKiNgCaSe with default options.

Kind: static method of mOcKiNgCaSe Returns: mOcKiNgCaSe with default options

Param Type Default Description
defaultOptions object Options for converting
defaultOptions.random boolean false If case conversion should be randomized
defaultOptions.onlyLetters boolean false If non letters characters should be removed
defaultOptions.firstUpper boolean false If the first letter should be capitalized instead of the second when converting to mOcKiNgCaSe (e.g. MoCkInGcAsE). When combined with options.random, the first letter of the random string will be capitalized
options.upper RegExp | string null Characters or substring set to change to uppercase
options.lower RegExp | string null Characters or substring set to change to lowercase
const mOcKiNgCaSe = require('@strdr4605/mockingcase').config({onlyLetters: true, firstUpper: true});
// const mOcKiNgCaSe = mOcKiNgCaSe.config({onlyLetters: true, firstUpper: true});

mOcKiNgCaSe('foo bar42');
//=> 'FoO BaR'

mOcKiNgCaSe('foo bar42', {onlyLetters: false, firstUpper: false});
//=> 'fOo bAr42'

mOcKiNgCaSe.log(input, [options])

Outputs a message to the console in mOcKiNgCaSe.

Kind: static method of mOcKiNgCaSe

Param Type Default Description
input string | string[] String(S) to be converted
[options] object {random: false, onlyLetters: false, firstUpper: false} Conversion options
options.random boolean false If case conversion should be randomized
options.onlyLetters boolean false If non letters characters should be removed
options.firstUpper boolean false If the first letter should be capitalized instead of the second when converting to mOcKiNgCaSe (e.g. MoCkInGcAsE). When combined with options.random, the first letter of the random string will be capitalized
options.upper RegExp | string null Characters or substring set to change to uppercase
options.lower RegExp | string null Characters or substring set to change to lowercase
mOcKiNgCaSe.log('foo bar');
// console.log('fOo bAr');


mOcKiNgCaSe.overrideConsole([options]) ⇒ mOcKiNgCaSe

Overrides the console.log input annd prints it in the mOcKiNgCaSe.

Param Type Default Description
[options] object {random: false, onlyLetters: false, firstUpper: false} Conversion options
options.random boolean false If case conversion should be randomized
options.onlyLetters boolean false If non letters characters should be removed
options.firstUpper boolean false If the first letter should be capitalized instead of the second when converting to mOcKiNgCaSe (e.g. MoCkInGcAsE). When combined with options.random, the first letter of the random string will be capitalized
options.upper RegExp | string null Characters or substring set to change to uppercase
options.lower RegExp | string null Characters or substring set to change to lowercase
const mOcKiNgCaSe = require('@strdr4605/mockingcase').overrideConsole();
console.log('foobar')
// => 'fOoBaR'
mOcKiNgCaSe('foobar');
// => 'fOoBaR'


Browser Usage

mOcKiNgCaSe can be used in a node environment, as well as in the browser. You can serve it yourself, or pull it from a CDN. For example:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>mOcKiNgCaSe</title>
</head>
<body>
</body>
<script src="https://unpkg.com/mockingcase/index.js"></script>
<script>
  const output = mOcKiNgCaSe('foo-bar');
  console.log(output);
  const output2 = mockingcase('foo-bar');
  console.log(output2);
</script>
</html>

Self Hosting

To host mOcKiNgCaSe yourself simply put index.js wherever your static content (like CSS stylesheets) are kept. You can also download a minified file from one of the CDNs below.

CDN Usage

Simply pull in one of the following JS files below.

Name Link
unpkg.com https://unpkg.com/mockingcase/index.js
JSDelivr.com https://cdn.jsdelivr.net/npm/mockingcase/index.min.js

See also Mockingcase bindings for ReasonML

mockingcase's People

Contributors

strdr4605 avatar avahe-kellenberger avatar maxrumsey avatar dependabot[bot] avatar aawgit avatar abitbetterthanyesterday avatar anmol5varma avatar blueberryking avatar carlmathisen avatar cukejianya avatar jamesdevore avatar matthewnbrown avatar rubiin avatar stern-shawn avatar thunderlorn avatar

Watchers

James Cloos 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.