Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/strdr4605/mockingcase

node package that converts a string to mOcKiNgCaSe
https://github.com/strdr4605/mockingcase

converts converts-string defaultoptions hacktoberfest javascript meme npm package spongebob

Last synced: 29 days ago
JSON representation

node package that converts a string to mOcKiNgCaSe

Awesome Lists containing this project

README

        

# mockingcase [![Build Status](https://travis-ci.org/strdr4605/mockingcase.svg?branch=master)](https://travis-ci.org/strdr4605/mockingcase) [![Hits-of-Code](https://hitsofcode.com/github/strdr4605/mockingcase)](https://hitsofcode.com/view/github/strdr4605/mockingcase) [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fstrdr4605%2Fmockingcase&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)

> Convert a string to mOcKiNgCaSe.

Read more on wikipedia [Studly caps](https://en.wikipedia.org/wiki/Studly_caps).

mocking spongebob

Inspired by the meme [Mocking Spongebob](https://knowyourmeme.com/memes/mocking-spongebob) and http://dannypage.github.io/spongebob.html

## Install

```bash
npm install @strdr4605/mockingcase --save
```

## Usage

```js
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](#mockingcase)
- [mockingcase.overrideString() ⇒ mockingcase](#mockingcase.overrideString)
- [String.prototype.toMockingCase([options]) ⇒ string](#String.prototype.toMockingCase)
- [mockingcase.config(defaultOptions) ⇒ mockingcase](#mockingcase.config)
- [mockingcase.log(input, [options])](#mockingcase.log)
- [mockingcase.overrideConsole([options]) ⇒ mockingcase](#mockingcase.overrideConsole)
- [Options](#Options)
- [Browser Usage](#mockingcase.browserUsage)

## Functions



mockingcase(input, [options])string


Converts the input string(s) to mOcKiNgCaSe.



## Typedefs



Options : Object


Options for mockingcase



## mockingcase(input, [options]) ⇒ string [:arrow_up:](#api)
Converts the input string(s) to mOcKiNgCaSe.

**Kind**: global function
**Returns**: string - string in mOcKiNgCaSe

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| input | string \| Array.<string> | | String(s) to be converted. |
| [options] | [Options](#Options) | {random: false, onlyLetters: false, firstUpper: false, upper: '', lower: ''} | Conversion options. |

```js
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 [:arrow_up:](#api)
Creates `String.prototype.toMockingCase()`.

**Kind**: static method of [mockingcase](#mockingcase)
**Returns**: mockingcase

```js
mockingcase.overrideString();

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

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


### String.prototype.toMockingCase([options]) ⇒ string [:arrow_up:](#api)
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 |
| --- | --- | --- | --- |
| input | string \| Array.<string> | | String(S) to be converted. |
| [options] | [Options](#Options) | {random: false, onlyLetters: false, firstUpper: false, upper: '', lower: ''} | Conversion options. |

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

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


### mockingcase.config(defaultOptions) ⇒ mockingcase [:arrow_up:](#api)
Outputs a mockingcase with default options.

**Kind**: static method of [mockingcase](#mockingcase)
**Returns**: mockingcase with default options

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| defaultOptions | [Options](#Options) | {random: false, onlyLetters: false, firstUpper: false, upper: '', lower: ''} | Conversion options. |

```js
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]) [:arrow_up:](#api)
Outputs a message to the console in mOcKiNgCaSe.

**Kind**: static method of [mockingcase](#mockingcase)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| input | string \| Array.<string> | | String(S) to be converted. |
| [options] | [Options](#Options) | {random: false, onlyLetters: false, firstUpper: false, upper: '', lower: ''} | Conversion options. |

```js
mockingcase.log('foo bar');
// console.log('fOo bAr');
```


### mockingcase.overrideConsole([options]) ⇒ mockingcase [:arrow_up:](#api)
Overrides console.log input to print the input mOcKiNgCaSe.

**Kind**: static method of [mockingcase](#mockingcase)
**Returns**: function - mockingcase function
**See**: mockingcase

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | [Options](#Options) | {random: false, onlyLetters: false, firstUpper: false, upper: '', lower: ''} | Conversion options. |

```js
const mockingcase = require('@strdr4605/mockingcase').overrideConsole();
console.log('foobar')
// => 'fOoBaR'
mockingcase('foobar');
// => 'fOoBaR'
```


## Options : Object [:arrow_up:](#api)
Options for mockingcase

**Kind**: global typedef
**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [random] | boolean | false | If case conversion should be randomized. |
| [onlyLetters] | boolean | false | If non letters characters should be removed. |
| [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. |
| [upper] | string \| RegExp | '' | Characters or substring set to change to uppercase, `upper` has higher priority that `lower`. |
| [lower] | string \| RegExp | '' | Characters or substring set to change to lowercase. |


## Browser Usage [:arrow_up:](#api)
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:
```html

mockingcase

const output = mockingcase('foo-bar');
console.log(output);
const output2 = mockingcase('foo-bar');
console.log(output2);

```
### Self Hosting
To host mockingcase yourself simply put `src/mockingcase.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/@strdr4605/mockingcase|
|JSDelivr.com|https://cdn.jsdelivr.net/npm/@strdr4605/mockingcase|

**See also [Mockingcase bindings for ReasonML](https://redex.github.io/package/unpublished/strdr4605/bs-mockingcase)**