Sha256: f23468e8987deeb6b95d94b72d9d0a38fa4ef183926ac8e56fe32fac4ef3a314

Contents?: true

Size: 804 Bytes

Versions: 13

Compression:

Stored size: 804 Bytes

Contents

/*global cull*/
this.gts = this.gts || {};

/**
 * Abbreviates a string to fit within a predefined width. If the
 * string is shorter than, or just as long as the specified width, it
 * is returned untouched.
 *
 * If the optional suffix is provided, it is appended to the
 * abbreviated string, and the full length of the abbreviated string
 * with the suffix is guaranteed to not be wider than the specified
 * width.
 */
this.gts.abbrev = function (sentence, width, suffix) {
    if (sentence.length <= width) { return sentence; }
    suffix = suffix || "";

    return cull.reduce(function (words, word) {
        if (words.join(" ").length + word.length + suffix.length <= width) {
            words.push(word);
        }
        return words;
    }, [], sentence.split(" ")).join(" ") + suffix;
};

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dolt-0.29.0 vendor/ui/js/src/components/abbrev.js
dolt-0.28.1 vendor/ui/js/src/components/abbrev.js
dolt-0.28.0 vendor/ui/js/src/components/abbrev.js
dolt-0.27.0 vendor/ui/js/src/components/abbrev.js
dolt-0.26.0 vendor/ui/js/src/components/abbrev.js
dolt-0.25.0 vendor/ui/js/src/components/abbrev.js
dolt-0.24.0 vendor/ui/js/src/components/abbrev.js
dolt-0.23.0 vendor/ui/js/src/components/abbrev.js
dolt-0.22.0 vendor/ui/js/src/components/abbrev.js
dolt-0.21.0 vendor/ui/js/src/components/abbrev.js
dolt-0.20.0 vendor/ui/js/src/components/abbrev.js
dolt-0.19.0 vendor/ui/js/src/components/abbrev.js
dolt-0.18.0 vendor/ui/js/src/components/abbrev.js