1 | var clamp = require('../math/clamp');
|
2 | var toString = require('../lang/toString');
|
3 |
|
4 | /**
|
5 | * Inserts a string at a given index.
|
6 | */
|
7 | function insert(string, index, partial){
|
8 | string = toString(string);
|
9 |
|
10 | if (index < 0) {
|
11 | index = string.length + index;
|
12 | }
|
13 |
|
14 | index = clamp(index, 0, string.length);
|
15 |
|
16 | return string.substr(0, index) + partial + string.substr(index);
|
17 | }
|
18 |
|
19 | module.exports = insert;
|
20 |
|
21 |
|