JSFiddle - React, Tailwind, and code Playground

by Fernando Leal

JavaScript

/* Fallbsack para manter o support ao metodo em todas as versões do javascript já que este método está em versão experiemntal : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith */

if (!String.prototype.endsWith) {
    console.log("not supported");
  Object.defineProperty(String.prototype, 'endsWith', {
    value: function(searchString, position) {
      var subjectString = this.toString();
      if (position === undefined || position > subjectString.length) {
        position = subjectString.length;
      }
      position -= searchString.length;
      var lastIndex = subjectString.indexOf(searchString, position);
      return lastIndex !== -1 && lastIndex === position;
    }
  });
}

// SOLUÇÂO

var extensions_ignore = ['.ejs'];
var proibidos = ['contatos/aq', 'contatos/aq1', 'contatos/aq4'];

var isPermitido = function(path_p){
    path_p = path_p.replace(extensions_ignore, "");
    for(var s=0; s < proibidos.length; s++) {
        if(path_p.endsWith(proibidos[s])) { 
            return false;
        }
    }
    return true;
};

var test = function(path){    
    console.log(path + " : " + isPermitido(path));
};

test('__dirname/pasta/subpasta/home/contatos/aq');
test('__dirname/pasta/subpasta/home/contatos/aq2.ejs');
test('__dirname/pasta/subpasta/home/contatos/aq3.ejs');
test('__dirname/pasta/subpasta/home/contatos/aq4.ejs');