UNPKG

jsmodern

Version:

An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.

19 lines 574 B
export const insert = { label: 'insert', fn: function stringInsert(index, s) { const ctx = this; const len = ctx.length; if (index < 0 || index > len) throw new TypeError('String index out of bound'); if (!len) return s; if (index === len) return `${ctx}${s}`; if (!index) return `${s}${ctx}`; const slice0 = ctx.slice(0, index); const sliceRest = ctx.slice(index); return `${slice0}${s}${sliceRest}`; }, }; //# sourceMappingURL=insert.js.map