node-readfiles
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -26,16 +26,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
const filter = filters.shift(); | ||
filterArray.push('\\/?' + | ||
filter | ||
.replace(/\./g, '\\.') | ||
.replace(/(\*?)(\*)(?!\*)/g, function (match, prefix) { | ||
if (prefix == '*') { | ||
return match; | ||
} | ||
return '[^\\/]*'; | ||
}) | ||
.replace(/\?/g, '[^\\/]?') | ||
.replace(/\*\*/g, '.*') | ||
.replace(/([\-\+\|])/g, '\\$1')); | ||
filterArray.push(`\\/?${filter | ||
.replace(/([./\\])/g, '\\$1') | ||
.replace(/(\*?)(\*)(?!\*)/g, (match, prefix) => { | ||
if (prefix === '*') { | ||
return match; | ||
} | ||
return '[^\\/]*'; | ||
}) | ||
.replace(/\?/g, '[^\\/]?') | ||
.replace(/\*\*/g, '.*') | ||
.replace(/([\-\+\|])/g, '\\$1')}`); | ||
} | ||
return new RegExp('^' + filterArray.join('|') + '$', 'i'); | ||
return new RegExp(`^${filterArray.join('|')}$`, 'i'); | ||
}; | ||
@@ -48,2 +47,6 @@ exports.buildFilter = buildFilter; | ||
describe('buildFilter', () => { | ||
it('creates a filter RegExp given a filter string', () => { | ||
const result = (0, build_filter_1.buildFilter)('.'); | ||
expect(result).toEqual(/^\/?\.$/i); | ||
}); | ||
it('creates a filter RegExp given a wildcard filter string', () => { | ||
@@ -92,3 +95,4 @@ const result = (0, build_filter_1.buildFilter)('*'); | ||
const traverseDir = (dirPath, done) => { | ||
fs.readdir(dirPath, (err, fileList) => { | ||
fs.readdir(dirPath, (err, fileListProp) => { | ||
let fileList = fileListProp; | ||
if (err) { | ||
@@ -136,3 +140,3 @@ if (options.rejectOnError !== false) { | ||
else if (stat.isFile()) { | ||
if (filterRegExp && !filterRegExp.test('/' + relFilename)) { | ||
if (filterRegExp && !filterRegExp.test(`/${relFilename}`)) { | ||
return next(); | ||
@@ -448,3 +452,3 @@ } | ||
it("callback returns the relative path of the files when 'filenameFormat' is 'readfiles.RELATIVE'", done => { | ||
let count = 0; | ||
const count = 0; | ||
const expectFiles = [ | ||
@@ -477,3 +481,3 @@ 'abc.txt', | ||
it("callback returns only the filename of the file when 'filenameFormat' is 'readfiles.FILENAME'", done => { | ||
let count = 0; | ||
const count = 0; | ||
const expectFiles = [ | ||
@@ -480,0 +484,0 @@ 'abc.txt', |
{ | ||
"name": "node-readfiles", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A lightweight Node.js module to recursively read files in a directory using ES6 Promises", | ||
@@ -5,0 +5,0 @@ "main": "lib/readfiles.js", |
@@ -11,3 +11,3 @@ export const buildFilter = (filtersParam: string | string[]) => { | ||
`\\/?${filter | ||
.replace(/\./g, '\\.') | ||
.replace(/([./\\])/g, '\\$1') | ||
.replace(/(\*?)(\*)(?!\*)/g, (match, prefix) => { | ||
@@ -14,0 +14,0 @@ if (prefix === '*') { |
import { buildFilter } from './build-filter'; | ||
describe('buildFilter', () => { | ||
it('creates a filter RegExp given a filter string', () => { | ||
const result = buildFilter('.'); | ||
expect(result).toEqual(/^\/?\.$/i); | ||
}); | ||
it('creates a filter RegExp given a wildcard filter string', () => { | ||
@@ -5,0 +11,0 @@ const result = buildFilter('*'); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
73392
1711
0