aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@kwsites/file-exists/dist/src
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@kwsites/file-exists/dist/src')
-rw-r--r--node_modules/@kwsites/file-exists/dist/src/index.d.ts19
-rw-r--r--node_modules/@kwsites/file-exists/dist/src/index.js55
-rw-r--r--node_modules/@kwsites/file-exists/dist/src/index.js.map1
3 files changed, 75 insertions, 0 deletions
diff --git a/node_modules/@kwsites/file-exists/dist/src/index.d.ts b/node_modules/@kwsites/file-exists/dist/src/index.d.ts
new file mode 100644
index 0000000..3d234cd
--- /dev/null
+++ b/node_modules/@kwsites/file-exists/dist/src/index.d.ts
@@ -0,0 +1,19 @@
+/**
+ * Synchronous validation of a path existing either as a file or as a directory.
+ *
+ * @param {string} path The path to check
+ * @param {number} type One or both of the exported numeric constants
+ */
+export declare function exists(path: string, type?: number): boolean;
+/**
+ * Constant representing a file
+ */
+export declare const FILE = 1;
+/**
+ * Constant representing a folder
+ */
+export declare const FOLDER = 2;
+/**
+ * Constant representing either a file or a folder
+ */
+export declare const READABLE: number;
diff --git a/node_modules/@kwsites/file-exists/dist/src/index.js b/node_modules/@kwsites/file-exists/dist/src/index.js
new file mode 100644
index 0000000..8a41c70
--- /dev/null
+++ b/node_modules/@kwsites/file-exists/dist/src/index.js
@@ -0,0 +1,55 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const fs_1 = require("fs");
+const debug_1 = __importDefault(require("debug"));
+const log = debug_1.default('@kwsites/file-exists');
+function check(path, isFile, isDirectory) {
+ log(`checking %s`, path);
+ try {
+ const stat = fs_1.statSync(path);
+ if (stat.isFile() && isFile) {
+ log(`[OK] path represents a file`);
+ return true;
+ }
+ if (stat.isDirectory() && isDirectory) {
+ log(`[OK] path represents a directory`);
+ return true;
+ }
+ log(`[FAIL] path represents something other than a file or directory`);
+ return false;
+ }
+ catch (e) {
+ if (e.code === 'ENOENT') {
+ log(`[FAIL] path is not accessible: %o`, e);
+ return false;
+ }
+ log(`[FATAL] %o`, e);
+ throw e;
+ }
+}
+/**
+ * Synchronous validation of a path existing either as a file or as a directory.
+ *
+ * @param {string} path The path to check
+ * @param {number} type One or both of the exported numeric constants
+ */
+function exists(path, type = exports.READABLE) {
+ return check(path, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
+}
+exports.exists = exists;
+/**
+ * Constant representing a file
+ */
+exports.FILE = 1;
+/**
+ * Constant representing a folder
+ */
+exports.FOLDER = 2;
+/**
+ * Constant representing either a file or a folder
+ */
+exports.READABLE = exports.FILE + exports.FOLDER;
+//# sourceMappingURL=index.js.map \ No newline at end of file
diff --git a/node_modules/@kwsites/file-exists/dist/src/index.js.map b/node_modules/@kwsites/file-exists/dist/src/index.js.map
new file mode 100644
index 0000000..68f2b8a
--- /dev/null
+++ b/node_modules/@kwsites/file-exists/dist/src/index.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,2BAA8B;AAC9B,kDAA0B;AAE1B,MAAM,GAAG,GAAG,eAAK,CAAC,sBAAsB,CAAC,CAAC;AAE1C,SAAS,KAAK,CAAC,IAAY,EAAE,MAAe,EAAE,WAAoB;IAC/D,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IAEzB,IAAI;QACD,MAAM,IAAI,GAAG,aAAQ,CAAC,IAAI,CAAC,CAAC;QAE5B,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,MAAM,EAAE;YAC1B,GAAG,CAAC,6BAA6B,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC;SACd;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,WAAW,EAAE;YACpC,GAAG,CAAC,kCAAkC,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;SACd;QAED,GAAG,CAAC,iEAAiE,CAAC,CAAC;QACvE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