MCPcopy
hub / github.com/autoNumeric/autoNumeric / insertAt

Method insertAt

src/AutoNumericHelper.js:1542–1558  ·  view source on GitHub ↗

* Insert the single character `char` in the string `str` at the given position `index` * * @param {string} str * @param {string} char * @param {int} index * @returns {string}

(str, char, index)

Source from the content-addressed store, hash-verified

1540 * @returns {string}
1541 */
1542 static insertAt(str, char, index) {
1543 str = String(str);
1544
1545 if (index > str.length) {
1546 throw new Error(`The given index is out of the string range.`);
1547 }
1548
1549 if (char.length !== 1) {
1550 throw new Error('The given string `char` should be only one character long.');
1551 }
1552
1553 if (str === '' && index === 0) {
1554 return char;
1555 }
1556
1557 return `${str.slice(0, index)}${char}${str.slice(index)}`;
1558 }
1559
1560 /**
1561 * Convert the given scientific notation to the 'expanded' decimal notation

Callers 1

scientificToDecimalMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected