How to use the strip function from underscore.string

Find comprehensive JavaScript underscore.string.strip code examples handpicked from public code repositorys.

underscore.string.strip removes leading and trailing whitespace from a string.

49
50
51
52
53
54
55
56
57
// - "anchor text" or
// - "href"
function formatAnchor(elem, fn, options) {
        var href = '';
        // Always get the anchor text
        var result = _s.strip(fn(elem.children || [], options));
        if (!result) {
                result = '';
        }
fork icon214
star icon0
watch icon3

+ 3 other calls in file

265
266
267
268
269
270
271
272
273
274
// negation
if (negation && (!_.isUndefined(self.negations[w]))) {
  n = w;

// Retain negation across small words ("not a good").
} else if ((!_.isNull(n)) && _str.strip(w, "'").length > 1) {
  n = null;
}

// May be a negation preceded by a modifier ("really not good").
fork icon7
star icon36
watch icon4

How does underscore.string.strip work?

underscore.string.strip is a function that removes all leading and trailing whitespace characters from a string. It does not modify the original string, but returns a new string with the whitespace removed.

27
28
29
30
31
32
33
34
35
36
37
}


module.exports.parsecmd = function( line ) {
    var argv = _u.filter( 
            line.split(' '),
            function(x) { return Boolean( _s.strip(x) ) }
    );
    if( argv !== [] ) {
        argv[0] = argv[0][0] == '/' ? _s.splice( argv[0], 0, 1 ) : argv[0];
    }
fork icon0
star icon2
watch icon2

Ai Example

1
2
3
const _ = require("underscore.string");
const str = "   hello world   ";
const result = _.strip(str); // result = 'hello world'