leading-chars
Description
Creates leading or trailing characters in a string or number
Install
Install with NPM
npm install leading-chars
Require
var LeadingChars =
LeadingChars(options)
LeadingChars is a constructor function that takes options and exports the user function.
options
If you don't understand these notes, check out the examples, they should make it more clear.
options
is an object with the following properties:len
is a number for how many characters to fill or concatenate (depending onoverall
).overall
is a boolean. It specifies whether thecharacter
is filled up tolen
, (true
), or if thecharacter
is concatenatedlen
times, (false
).character
is the character that is added to the string or number.leading
is a boolean of whethercharacter
should be added to the beginning or the end. If you want the concatenated characters to lead the string or number, set this totrue
. If you want them characters to trail, set this tofalse
.
- Returns:
constructed(input, options)
constructed(input, options)
input
This is the string or number that is appended to. This is not mutated.
options
Same as LeadingChars()
s options.
Examples
Leading Zeroes:
var leadingZeroes = //returns '005f39a6' //returns '00000000' //returns '00000ftw'
Indent with one tab:
var indent = //returns '\tHey what is up' //returns '\t' //returns '\t\tblah'
Append full stops: (Sometimes referred to as 'periods')
var addFullStop = //returns 'Hey what is up.' //returns '.' //returns 'blah...'
Fill with J's:
var fillWithJs = //returns 'JJJa' //returns 'Jaaa' //returns 'aaaaa'
Prefix 2 E's:
var prefixTwoEs = //returns 'EEa' //returns 'EEaaa' //returns 'EEaaaaa'
Leading Smileys:
var leadingSmileys = //returns ':) :) lol' //returns ':) :) wat' //returns ':) :) uber'
Trailing Frowneys:
var trailingFrowneys = //returns 'no :(' //returns 'so sad :(' //returns 'um why :('