Last Updated: February 25, 2016
·
364
· ashnur

Javascript stringSplice

void function(root){

    var splice = Array.prototype.splice;

    function toString(value){ return String(value || '') }

    function toArray(val){ return toString(val).split('') }

    function stringSplice(original, from, length, change){

        var org = toArray(original)
            , chg = toArray(change)

        splice.apply(org, [from, length].concat(chg)).join('')
        return org 
    }   

    module.exports = stringSplice

}(this)