UNPKG

1.57 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.walkStream = exports.walkSync = exports.walk = void 0;
4const providers_1 = require("./providers");
5const settings_1 = require("./settings");
6const readers_1 = require("./readers");
7const fs_1 = require("./adapters/fs");
8const fs = new fs_1.FileSystemAdapter();
9function walk(directory, options, callback) {
10 const optionsIsCallback = typeof options === 'function';
11 const callback_ = optionsIsCallback ? options : callback;
12 const settings = optionsIsCallback ? getSettings() : getSettings(options);
13 const reader = new readers_1.AsyncReader(fs, settings);
14 const provider = new providers_1.AsyncProvider(reader);
15 provider.read(directory, callback_);
16}
17exports.walk = walk;
18function walkSync(directory, optionsOrSettings) {
19 const settings = getSettings(optionsOrSettings);
20 const reader = new readers_1.SyncReader(fs, settings);
21 const provider = new providers_1.SyncProvider(reader);
22 return provider.read(directory);
23}
24exports.walkSync = walkSync;
25function walkStream(directory, optionsOrSettings) {
26 const settings = getSettings(optionsOrSettings);
27 const reader = new readers_1.AsyncReader(fs, settings);
28 const provider = new providers_1.StreamProvider(reader);
29 return provider.read(directory);
30}
31exports.walkStream = walkStream;
32function getSettings(settingsOrOptions = {}) {
33 if (settingsOrOptions instanceof settings_1.Settings) {
34 return settingsOrOptions;
35 }
36 return new settings_1.Settings(settingsOrOptions);
37}