v.insert(subjectopt='', toInsertopt='', positionopt=0) → {string}
Inserts into subject
a string toInsert
at specified position
.
Parameters:
subject |
{string}
The string where to insert.
[optional='' ]
|
toInsert |
{string}
The string to be inserted.
[optional='' ]
|
position |
{number}
The position to insert.
[optional=0 ]
|
Returns:
{string}
Returns the string after insertion.
Availability:
1.0.0
Example:
v.insert('ct', 'a', 1);
// => 'cat'
v.insert('sunny', ' day', 5);
// => 'sunny day'
v.latinise(subjectopt='') → {string}
Latinises the subject
by removing diacritic characters.
Parameters:
subject |
{string}
The string to latinise.
[optional='' ]
|
Returns:
{string}
Returns the latinised string.
Availability:
1.0.0
Example:
v.latinise('cafe\u0301'); // or 'café'
// => 'cafe'
v.latinise('août décembre');
// => 'aout decembre'
v.latinise('как прекрасен этот мир');
// => 'kak prekrasen etot mir'
v.pad(subjectopt='', lengthopt=0, padopt=' ') → {string}
Pads subject
to a new length
.
Parameters:
subject |
{string}
The string to pad.
[optional='' ]
|
length |
{int}
The length to pad the string. No changes are made if length is less than subject.length .
[optional=0 ]
|
pad |
{string}
The string to be used for padding.
[optional=' ' ]
|
Returns:
{string}
Returns the padded string.
Availability:
1.0.0
Example:
v.pad('dog', 5);
// => ' dog '
v.pad('bird', 6, '-');
// => '-bird-'
v.pad('cat', 6, '-=');
// => '-cat-='
v.padLeft(subjectopt='', lengthopt=0, padopt=' ') → {string}
Pads subject
from left to a new length
.
Parameters:
subject |
{string}
The string to pad.
[optional='' ]
|
length |
{int}
The length to left pad the string. No changes are made if length is less than subject.length .
[optional=0 ]
|
pad |
{string}
The string to be used for padding.
[optional=' ' ]
|
Returns:
{string}
Returns the left padded string.
Availability:
1.0.0
Example:
v.padLeft('dog', 5);
// => ' dog'
v.padLeft('bird', 6, '-');
// => '--bird'
v.padLeft('cat', 6, '-=');
// => '-=-cat'
v.padRight(subjectopt='', lengthopt=0, padopt=' ') → {string}
Pads subject
from right to a new length
.
Parameters:
subject |
{string}
The string to pad.
[optional='' ]
|
length |
{int}
The length to right pad the string. No changes are made if length is less than subject.length .
[optional=0 ]
|
pad |
{string}
The string to be used for padding.
[optional=' ' ]
|
Returns:
{string}
Returns the right padded string.
Availability:
1.0.0
Example:
v.padRight('dog', 5);
// => 'dog '
v.padRight('bird', 6, '-');
// => 'bird--'
v.padRight('cat', 6, '-=');
// => 'cat-=-'
v.repeat(subjectopt='', timesopt=1) → {string}
Repeats the subject
number of times
.
Parameters:
subject |
{string}
The string to repeat.
[optional='' ]
|
times |
{number}
The number of times to repeat.
[optional=1 ]
|
Returns:
{string}
Returns the repeated string.
Availability:
1.0.0
Example:
v.repeat('w', 3);
// => 'www'
v.repeat('world', 0);
// => ''
v.replace(subjectopt='', search, replace) → {string}
Replaces the matches of search
with replace
.
Parameters:
subject |
{string}
The string to verify.
[optional='' ]
|
search |
{string|RegExp}
The search pattern to replace. If search is a string,
a simple string match is evaluated and only the first occurrence replaced.
|
replace |
{string|function}
The string or function which invocation result replaces search match.
|
Returns:
{string}
Returns the replacement result.
Availability:
1.0.0
Example:
v.replace('swan', 'wa', 'u');
// => 'sun'
v.replace('domestic duck', /domestic\s/, '');
// => 'duck'
v.replace('nice duck', /(nice)(duck)/, function(match, nice, duck) {
return 'the ' + duck + ' is ' + nice;
});
// => 'the duck is nice'
v.replaceAll(subjectopt='', search, replace) → {string}
Replaces all occurrences of search
with replace
.
Parameters:
subject |
{string}
The string to verify.
[optional='' ]
|
search |
{string|RegExp}
The search pattern to replace. If search is a string, a simple string match is evaluated.
All matches are replaced.
|
replace |
{string|function}
The string or function which invocation result replaces all search matches.
|
Returns:
{string}
Returns the replacement result.
Availability:
1.0.0
Example:
v.replaceAll('good morning', 'o', '*');
// => 'g**d m*rning'
v.replaceAll('evening', /n/g, 's');
// => 'evesisg'
v.reverse(subjectopt='') → {string}
Parameters:
subject |
{string}
The string to reverse.
[optional='' ]
|
Returns:
{string}
Returns the reversed string.
Availability:
1.0.0
Example:
v.reverse('winter');
// => 'retniw'
v.reverseGrapheme(subjectopt='') → {string}
Parameters:
subject |
{string}
The string to reverse.
[optional='' ]
|
Returns:
{string}
Returns the reversed string.
Availability:
1.0.0
Example:
v.reverseGrapheme('summer');
// => 'remmus'
v.reverseGrapheme('𝌆 bar mañana mañana');
// => 'anañam anañam rab 𝌆'
v.slugify(subjectopt='') → {string}
Slugifies the subject
. Cleans the subject
by replacing diacritics with corresponding latin characters.
Parameters:
subject |
{string}
The string to slugify.
[optional='' ]
|
Returns:
{string}
Returns the slugified string.
Availability:
1.0.0
Example:
v.slugify('Italian cappuccino drink');
// => 'italian-cappuccino-drink'
v.slugify('caffé latté');
// => 'caffe-latte'
v.slugify('хорошая погода');
// => 'horoshaya-pogoda'
v.splice(subjectopt='', start, deleteCountopt=subject.length-start, toAddopt='') → {string}
Changes subject
by deleting deleteCount
of characters starting at position start
. Places a new string
toAdd
instead of deleted characters.
Parameters:
subject |
{string}
The string where to insert.
[optional='' ]
|
start |
{string}
The position to start changing the string. For a negative position will start from the end of
the string.
|
deleteCount |
{number}
The number of characters to delete from string.
[optional=subject.length-start ]
|
toAdd |
{string}
The string to be added instead of deleted characters.
[optional='' ]
|
Returns:
{string}
Returns the modified string.
Availability:
1.0.0
Example:
v.splice('new year', 0, 4);
// => 'year'
v.splice('new year', 0, 3, 'happy');
// => 'happy year'
v.splice('new year', -4, 4, 'day');
// => 'new day'
v.tr(subjectopt='', from, to) → {string}
Translates characters or replaces substrings in subject
.
Parameters:
subject |
{string}
The string to translate.
[optional='' ]
|
from |
{string|Object}
The string of characters to translate from. Or an object, then the object keys are replaced with corresponding values (longest keys are tried first).
|
to |
{string}
The string of characters to translate to. Ignored when from is an object.
|
Returns:
{string}
Returns the translated string.
Availability:
1.3.0
Example:
v.tr('hello', 'el', 'ip');
// => 'hippo'
v.tr('légèreté', 'éè', 'ee');
// => 'legerete'
v.tr('Yes. The fire rises.', {
'Yes': 'Awesome',
'fire': 'flame'
})
// => 'Awesome. The flame rises.'
v.tr(':where is the birthplace of :what', {
':where': 'Africa',
':what': 'Humanity'
});
// => 'Africa is the birthplace of Humanity'
v.trim(subjectopt='', whitespaceopt=whitespace) → {string}
Removes whitespaces from left and right sides of the subject
.
Parameters:
subject |
{string}
The string to trim.
[optional='' ]
|
whitespace |
{string}
The whitespace characters to trim. List all characters that you want to be stripped.
[optional=whitespace ]
|
Returns:
{string}
Returns the trimmed string.
Availability:
1.0.0
Example:
v.trim(' Mother nature ');
// => 'Mother nature'
v.trim('--Earth--', '-');
// => 'Earth'
v.trimLeft(subjectopt='', whitespaceopt=whitespace) → {string}
Removes whitespaces from the left side of the subject
.
Parameters:
subject |
{string}
The string to trim.
[optional='' ]
|
whitespace |
{string}
The whitespace characters to trim. List all characters that you want to be stripped.
[optional=whitespace ]
|
Returns:
{string}
Returns the trimmed string.
Availability:
1.0.0
Example:
v.trimLeft(' Starship Troopers');
// => 'Starship Troopers'
v.trimLeft('***Mobile Infantry', '*');
// => 'Mobile Infantry'
v.trimRight(subjectopt='', whitespaceopt=whitespace) → {string}
Removes whitespaces from the right side of the subject
.
Parameters:
subject |
{string}
The string to trim.
[optional='' ]
|
whitespace |
{string}
The whitespace characters to trim. List all characters that you want to be stripped.
[optional=whitespace ]
|
Returns:
{string}
Returns the trimmed string.
Availability:
1.0.0
Example:
v.trimRight('the fire rises ');
// => 'the fire rises'
v.trimRight('do you feel in charge?!!!', '!');
// => 'do you feel in charge?'
v.wordWrap(subjectopt='', optionsopt={}) → {string}
Wraps subject
to a given number of characters using a string break character.
Parameters:
subject |
{string}
The string to wrap.
[optional='' ]
|
options |
{Object}
The wrap options.
[optional={} ]
Properties:
width |
{number}
The number of characters at which to wrap.
[optional=75 ]
|
newLine |
{string}
The string to add at the end of line.
[optional='\n' ]
|
indent |
{string}
The string to intend the line.
[optional='' ]
|
cut |
{boolean}
When false (default) does not split the word even if word length is bigger than width .
When true breaks the word that has length bigger than width .
[optional=false ]
|
|
Returns:
{string}
Returns wrapped string.
Availability:
1.0.0
Example:
v.wordWrap('Hello world', {
width: 5
});
// => 'Hello\nworld'
v.wordWrap('Hello world', {
width: 5,
newLine: '<br/>',
indent: '__'
});
// => '__Hello<br/>__world'
v.wordWrap('Wonderful world', {
width: 5,
cut: true
});
// => 'Wonde\nrful\nworld'