0.0.2 • Published 5 years ago
@mmgj/triks v0.0.2
@mmgj/triks
npm i @mmgj/triks
yarn add @mmgj/triks
Usage
humanList / thingCommaThingAndThing / tctat
Takes an array of strings and an optional config object and returns a human-readable string.
import { humanList } from '@mmgj/triks';
...or, if you prefer:
import { thingCommaThingAndThing } from '@mmgj/triks';
Usage
const betterList = humanList(array, { config });
Arguments:
array (Array) : an array of strings. config (Object) : an optional config object. (see below)
Must be declared in the form of a config object. I.e. { oxford: true, andThen: '!' }
.
Prop | Type | Default | Description |
---|---|---|---|
oxford | boolean | false | Use Oxford comma? (I.e 'thingCommaThingCommaAndThing') |
and | string | 'and' | What's going in the 'and' place? |
andThen | string | '' | What goes after the string? (A period or exclamation mark for example) |
Returns
(String) : a string more resembling what a human might write.
Examples
humanList(['Tom', 'Dick', 'Harry']); // Tom, Dick and Harry
humanList(['Tom', 'Dick', 'Harry']); { oxford: true }); // Tom, Dick, and Harry
humanList(['Luke', 'Leia']); // Luke and Leia
humanList(['Luke', 'Leia'], { andThen: '!!!' }); // Luke and Leia!!!
humanList(['Pompel', 'Pilt'], { and: 'og' }); // Pompel og Pilt
humanList(['Stone', 'Scissors', 'Paper', 'Lizard', 'Spock'], { oxford: true, and: '', andThen: '!!!!'};
// Stone, Scissors, Paper, Lizard, Spock!!!!