tiny-readdir 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  /* IMPORT */
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
+ import { isFunction } from './utils.js';
4
5
  /* MAIN */
5
6
  const readdir = (rootPath, options) => {
6
7
  const followSymlinks = options?.followSymlinks ?? false;
7
8
  const maxDepth = options?.depth ?? Infinity;
8
9
  const maxPaths = options?.limit ?? Infinity;
9
- const isIgnored = options?.ignore ?? (() => false);
10
+ const ignore = options?.ignore ?? (() => false);
11
+ const isIgnored = isFunction(ignore) ? ignore : (targetPath) => ignore.test(targetPath);
10
12
  const signal = options?.signal ?? { aborted: false };
11
13
  const directories = [];
12
14
  const files = [];
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ type Options = {
3
3
  depth?: number;
4
4
  limit?: number;
5
5
  followSymlinks?: boolean;
6
- ignore?: (targetPath: string) => boolean;
6
+ ignore?: ((targetPath: string) => boolean) | RegExp;
7
7
  signal?: {
8
8
  aborted: boolean;
9
9
  };
@@ -0,0 +1,2 @@
1
+ declare const isFunction: (value: unknown) => value is Function;
2
+ export { isFunction };
package/dist/utils.js ADDED
@@ -0,0 +1,6 @@
1
+ /* MAIN */
2
+ const isFunction = (value) => {
3
+ return (typeof value === 'function');
4
+ };
5
+ /* EXPORT */
6
+ export { isFunction };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tiny-readdir",
3
3
  "repository": "github:fabiospampinato/tiny-readdir",
4
4
  "description": "A simple promisified recursive readdir function.",
5
- "version": "2.1.0",
5
+ "version": "2.2.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "exports": "./dist/index.js",
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
+ import {isFunction} from './utils';
6
7
  import type {Promisable, Options, ResultDirectory, ResultDirectories, Result} from './types';
7
8
 
8
9
  /* MAIN */
@@ -12,7 +13,8 @@ const readdir = ( rootPath: string, options?: Options ): Promise<Result> => {
12
13
  const followSymlinks = options?.followSymlinks ?? false;
13
14
  const maxDepth = options?.depth ?? Infinity;
14
15
  const maxPaths = options?.limit ?? Infinity;
15
- const isIgnored = options?.ignore ?? (() => false);
16
+ const ignore = options?.ignore ?? (() => false);
17
+ const isIgnored = isFunction ( ignore ) ? ignore : ( targetPath: string ) => ignore.test ( targetPath );
16
18
  const signal = options?.signal ?? { aborted: false };
17
19
  const directories: string[] = [];
18
20
  const files: string[] = [];
package/src/types.ts CHANGED
@@ -9,7 +9,7 @@ type Options = {
9
9
  depth?: number,
10
10
  limit?: number,
11
11
  followSymlinks?: boolean,
12
- ignore?: ( targetPath: string ) => boolean,
12
+ ignore?: (( targetPath: string ) => boolean) | RegExp,
13
13
  signal?: { aborted: boolean }
14
14
  };
15
15
 
package/src/utils.ts ADDED
@@ -0,0 +1,12 @@
1
+
2
+ /* MAIN */
3
+
4
+ const isFunction = ( value: unknown ): value is Function => {
5
+
6
+ return ( typeof value === 'function' );
7
+
8
+ };
9
+
10
+ /* EXPORT */
11
+
12
+ export {isFunction};