Javascript String endsWith(substr)

Description

Javascript String endsWith(substr)


/*global require*/
var fs = require("fs");


var re = new RegExp("\\." + process.argv[3] + "$");
String.prototype.endsWith = function(substr) {
    var idx = this.lastIndexOf(substr);
    return idx == -1 || idx + substr.length != this.length ? false : true;
}

// console.log("dir: " + process.argv[2]);
// console.log("ext: " + process.argv[3]);
var buf = fs.readdir(process.argv[2],
    function(err, files) {
        files.forEach(function (file) {
            if(re.test(file))
                console.log(file);/*  ww  w .jav a  2s.com*/
        });
    }
);



PreviousNext

Related