-
repeat(obj, count)
- repeats given obj as string -
fill(obj, size)
- creates new string with given size using obj -
pad
-
pad(text, filler, length)
- adds filler to match target length -
padLeft(text, filler, length)
- adds leading filler to match target length -
padRight(text, filler, length)
- adds terminating filler to match target length -
padCenter(text, filler, length)
- surrounds text with filler to match target length
-
-
insert
-
insertAt(text, sti, position)
- inserts sti at given position into text -
insertStep(text, sti, step)
- inserts sti after each step symbols into text
-
Returns
new string with obj being repeated count times
Returns
empty string if count was less that 0
Converts
any obj to type string
// Repeating strings
str_mod.repeat('X', 4); // Output: XXXXX
str_mod.repeat('*-', 4); // Output: *-*-*-*-
// Repeating other types
str_mod.repeat(5, 4); // Output: 5555
srt_mod.repeat(true, 4); // Output: truetruetruetrue
str_mod.repeat({}), 4); // Output: [object Object][object Object][object Object][object Object]
Returns
new string with size length, filled by obj(cyclic)
Returns
empty string if size is less than 0
Converts
any obj to type string
// Filling with characters
str_mod.fill('X', 5); // Output: XXXXX
// Filling with strings
str_mod.fill('*-', 5); // Output: *-*-*
Returns
text with added filler to match given length
If
length is less than 0 filler will be added to the right of text
// Left pad
str_mod.pad('xxx', '-', 5); // Output: --xxx
str_mod.pad('xxx', '-', 2); // Output: xxx
// Right pad
str_mod.pad('xxx', '-', -5); // Output: xxx--
str_mod.pad('xxx', '-', -2); // Output: xxx
Returns
text with leading filler to match given length
// Left pad
str_mod.padLeft('xxx', '-', 5); // Output: --xxx
str_mod.padLeft('xxx', '-', 2); // Output: xxx
str_mod.padLeft('xxx', '-', -5); // Output: xxx
Returns
text with terminating filler to match given length
// Right pad
str_mod.padRight('xxx', '-', 5); // Output: xxx--
str_mod.padRight('xxx', '-', 2); // Output: xxx
str_mod.padRight('xxx', '-', -5); // Output: xxx
Returns
text with added filler around it to match given length
Returns
text if length is less than text.length
// Odd length
str_mod.padCenter('xxx', '-', 7); // Outputs: --xxx--
str_mod.padCenter('xxx', '-', 1); // Outputs: xxx
// Even length
str_mod.padCenter('xxx', '-', 6); // Outputs: -xxx--
str_mod.padCenter('xxx', '-', 4); // Outputs: xxx-
// Length is less than text.length
str_mod.padCenter('xxx', '-', 1); // Ouputs: xxx
Returns
new string from text with sti inserted before given position
If
position is negative inserts after given position, going from right to left
Throws
error if position is out of bounds
// Inserting at positive position
str_mod.insertAt('xxxx', '-', 2); // Outputs: xx-xx
str_mod.insertAt('xxxx', '-', 3); // Outputs: xxx-x
// Inserting at negative position
str_mod.insertAt('xxxx', '-', -1); // Outputs: xxxx-
str_mod.insertAt('xxxx', '-', -3); // Outpus: xx-xx
// Bad insers
str_mod.insertAt('xxxx', '-', 8); // Throws error. 8 is greater than text length
str_mod.insertAt('xxxx', '-', -9); // Throws error. -9 is less than negative text length
Returns
new string with sti inserted in text after each step symbols. Does not insert sti at the end
Returns
new string with sti inserted in text after each step symbols from right to left if step is negative
Returns
text if step is more than text.length
Throws
error if step is 0
// Inserting with positive step
str_mod.insertStep('thetststr:)', '-', 3); // Outputs: the-tst-str-:)
str_mod.insertStep('D:thetststr', '-', 3); // Outputs: D:t-het-sts-tr
// Insert with negative step
str_mod.insertStep('thetststr:)', '-', -3); // Outputs: th-ets-tst-r:)
str_mod.insertStep('D:thetststr', '-', -3); // Outputs: D:-the-tst-str
// Inserting without end
str_mod.insertStep('thekey', '-', 3); // Outputs: the-key
// Bad insert
str_mod.insertStep('thekey', '-', 0); // Throws error. Step can not be 0