String truncate Middle - Node.js String

Node.js examples for String:sub string

Description

String truncate Middle

Demo Code

String.prototype.truncateMiddle = function j(p, o) {
    if (p >= this.length) {
        return this
    }// w w w  .  jav a2s  .c om
    if (o === undefined) {
        o = "..."
    }
    var q = Math.floor(p) / 2;
    return this.substring(0, q) + o + this.substring(this.length - (p - q))
};

Related Tutorials