@bscotch/utility
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -0,1 +1,7 @@ | ||
export interface ListPathOptions { | ||
/** By default the .git folder is skipped */ | ||
includeDotGit?: boolean; | ||
/** By default the node_modules folder is skipped */ | ||
includeNodeModules?: boolean; | ||
} | ||
/** | ||
@@ -5,7 +11,7 @@ * List all files and folders in a directory. If `dir` is a | ||
*/ | ||
export declare function listPathsSync(dir: string, recursive?: boolean): string[]; | ||
export declare function listPathsSync(dir: string, recursive?: boolean, options?: ListPathOptions): string[]; | ||
/** | ||
* List all folders in a directory. | ||
*/ | ||
export declare function listFoldersSync(dir: string, recursive?: boolean): string[]; | ||
export declare function listFoldersSync(dir: string, recursive?: boolean, options?: ListPathOptions): string[]; | ||
/** | ||
@@ -15,3 +21,3 @@ * List all files in a directory or, if 'dir' is already a file, | ||
*/ | ||
export declare function listFilesSync(dir: string, recursive?: boolean): string[]; | ||
export declare function listFilesSync(dir: string, recursive?: boolean, options?: ListPathOptions): string[]; | ||
/** | ||
@@ -21,3 +27,3 @@ * List all files in a directory or, if 'dir' is already a file, | ||
*/ | ||
export declare function listFilesByExtensionSync(dir: string, extension: string | string[], recursive?: boolean): string[]; | ||
export declare function listFilesByExtensionSync(dir: string, extension: string | string[], recursive?: boolean, options?: ListPathOptions): string[]; | ||
//# sourceMappingURL=files.d.ts.map |
@@ -14,7 +14,15 @@ "use strict"; | ||
*/ | ||
function listPathsSync(dir, recursive = false) { | ||
function listPathsSync(dir, recursive = false, options) { | ||
if (fs_1.default.statSync(dir).isFile()) { | ||
return [dir]; | ||
} | ||
const excludedDirs = []; | ||
if (!(options === null || options === void 0 ? void 0 : options.includeDotGit)) { | ||
excludedDirs.push('.git'); | ||
} | ||
if (!(options === null || options === void 0 ? void 0 : options.includeNodeModules)) { | ||
excludedDirs.push('node_modules'); | ||
} | ||
const paths = fs_1.default.readdirSync(dir) | ||
.filter(aPath => !excludedDirs.includes(aPath)) | ||
.map(aPath => path_1.default.join(dir, aPath)); | ||
@@ -34,4 +42,4 @@ if (recursive) { | ||
*/ | ||
function listFoldersSync(dir, recursive = false) { | ||
return listPathsSync(dir, recursive) | ||
function listFoldersSync(dir, recursive = false, options) { | ||
return listPathsSync(dir, recursive, options) | ||
.filter(pathName => fs_1.default.statSync(pathName).isDirectory()); | ||
@@ -44,7 +52,7 @@ } | ||
*/ | ||
function listFilesSync(dir, recursive = false) { | ||
function listFilesSync(dir, recursive = false, options) { | ||
if (fs_1.default.statSync(dir).isFile()) { | ||
return [dir]; | ||
} | ||
return listPathsSync(dir, recursive) | ||
return listPathsSync(dir, recursive, options) | ||
.filter(filePath => fs_1.default.statSync(filePath).isFile()); | ||
@@ -57,5 +65,5 @@ } | ||
*/ | ||
function listFilesByExtensionSync(dir, extension, recursive = false) { | ||
function listFilesByExtensionSync(dir, extension, recursive = false, options) { | ||
const extensions = Array.isArray(extension) ? extension : [extension]; | ||
return listFilesSync(dir, recursive) | ||
return listFilesSync(dir, recursive, options) | ||
.filter(fileName => { | ||
@@ -62,0 +70,0 @@ const ext = path_1.default.parse(fileName).ext.slice(1); |
@@ -0,1 +1,10 @@ | ||
# [0.3.0](https://github.com/bscotch/node-util/compare/v0.2.1...v0.3.0) (2020-10-08) | ||
### Features | ||
* Have path listing methods ignore .git and node_modules folders by default ([58aead5](https://github.com/bscotch/node-util/commit/58aead5f9afaa596a6569aa68962abf2253daabc)) | ||
## [0.2.1](https://github.com/bscotch/node-util/compare/v0.2.0...v0.2.1) (2020-10-08) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "@bscotch/utility", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Bscotch Utilities: Methods for common Node.js needs.", | ||
@@ -5,0 +5,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
22635
254