robots-txt-guard
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -34,32 +34,32 @@ 'use strict'; | ||
// strip last character if $ | ||
pattern = pattern.replace(/\$$/, ''); | ||
if (pattern.includes('*') || pattern.endsWith('$')) { | ||
if (pattern.endsWith('$')) { | ||
pattern = pattern.slice(0, -1); | ||
} | ||
// wildcards are ignored in specificity | ||
const specificityString = pattern.replace(/\*/g, ''); | ||
// wildcards are ignored in specificity | ||
const specificityString = pattern.replace(/\*/g, ''); | ||
pattern = pattern | ||
.split(/\*+/) | ||
.map(escapeRegExp) | ||
.join('(?:.*)'); | ||
pattern = pattern | ||
.split(/\*+/) | ||
.map(escapeRegExp) | ||
.join('(?:.*)'); | ||
pattern = '^' + pattern; | ||
if (matchEnd) { | ||
pattern += '$'; | ||
} | ||
pattern = '^' + pattern; | ||
if (matchEnd) { | ||
pattern += '$'; | ||
} | ||
const regexp = new RegExp(pattern); | ||
const regexp = new RegExp(pattern); | ||
/** | ||
* @param {string} path | ||
* @returns {boolean} | ||
*/ | ||
function test (path) { | ||
return regexp.test(path); | ||
return { | ||
specificity: specificityString.length, | ||
test: path => regexp.test(path) | ||
}; | ||
} else { | ||
return { | ||
specificity: pattern.length, | ||
test: path => path.startsWith(pattern) | ||
}; | ||
} | ||
return { | ||
specificity: specificityString.length, | ||
test: test | ||
}; | ||
}; | ||
@@ -66,0 +66,0 @@ |
{ | ||
"name": "robots-txt-guard", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Validate urls against robots.txt rules.", | ||
@@ -5,0 +5,0 @@ "main": "lib/guard.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25852
674