How to use the endsWith function from underscore.string

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

underscore.string.endsWith is a utility function in the Underscore.string library that checks if a given string ends with the specified suffix.

31
32
33
34
35
36
37
38
39
40
41
  this.synset = args.synset;
  this.synsets = {};
  this.labeler = {};
  this.negations = def(args.negations, ["no", "not", "n't", "never"]);
  this.modifiers = def(args.modifiers, ["RB"]);
  this.modifier = def(args.modifier, function (w) { return _str.endsWith(w, "ly"); });
  this.tokenizer = def(args.tokenizer, find_tokens);
}



fork icon7
star icon36
watch icon4

137
138
139
140
141
142
143
144
    );
    return _u.filter( _u.map( files, load_module ), module.exports.boolof )
}


function load_module( file ) {
    return _s.endsWith(file, '.js') ? require( file ) : null;
}
fork icon0
star icon2
watch icon2

How does underscore.string.endsWith work?

underscore.string.endsWith is a function that determines whether a given string ends with a specified suffix, and it works by comparing the end of the string with the suffix using the substr() method.

234
235
236
237
238
239
240
241
242
243
244
245
BPMNProcess.prototype.triggerEvent = function(eventName, data) {
    var self = this;
    var processDefinition = self.processDefinition;
    var flowObjectName = eventName;
    var flowObject = processDefinition.getFlowObjectByName(flowObjectName);
    var taskDoneMatch = _s.endsWith(eventName, activityEndHandlerPostfix);


    if (flowObject) {


        this.logger.trace("Trigger " + flowObject.type + " '" + flowObject.name + "'", data);
fork icon0
star icon0
watch icon2

+ 3 other calls in file

119
120
121
122
123
124
125
126
127
128
});
hawtio.use('/', function(req, res, next) {
        const path = req.originalUrl;
        if (path === '/') {
          res.redirect('/hawtio');
        } else if (s.startsWith(path, '/plugins/') && s.endsWith(path, 'html')) {
          // avoid returning these files, they should get pulled from js
          console.log("returning 404 for: ", path);
          res.statusCode = 404;
          res.end();
fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
const _ = require("underscore.string");

console.log(_.endsWith("Hello world", "world")); // true
console.log(_.endsWith("Hello world", "World")); // false
console.log(_.endsWith("Hello world", "lo", 5)); // true

In this example, we first import the underscore.string library and assign it to the _ variable. We then use the _.endsWith() function to check if the string 'Hello world' ends with the substring 'world', 'World', and 'lo' starting at the index 5, respectively. The function returns true for the first and third examples, and false for the second example.