smartfile/dist/smartfile.checks.js

40 lines
3.6 KiB
JavaScript
Raw Normal View History

2016-03-14 02:50:14 +00:00
"use strict";
require("typings-global");
2016-03-14 02:50:14 +00:00
var plugins = require("./smartfile.plugins");
/**
*
* @param filePath
* @returns {boolean}
*/
exports.fileExistsSync = function (filePath) {
var fileExistsBool = false;
try {
plugins.fs.readFileSync(filePath);
fileExistsBool = true;
}
catch (err) {
fileExistsBool = false;
}
return fileExistsBool;
};
/**
*
* @param filePath
* @returns {any}
*/
exports.fileExists = function (filePath) {
var done = plugins.q.defer();
plugins.fs.access(filePath, plugins.fs.R_OK, function (err) {
err ? done.reject() : done.resolve();
});
return done.promise;
};
2016-03-20 23:28:29 +00:00
exports.isDirectory = function (pathArg) {
return plugins.fs.statSync(pathArg).isDirectory();
};
exports.isFile = function (pathArg) {
return plugins.fs.statSync(pathArg).isFile();
};
2016-03-14 02:50:14 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZmlsZS5jaGVja3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFPLE9BQU8sV0FBVyxxQkFBcUIsQ0FBQyxDQUFDO0FBRWhEOzs7O0dBSUc7QUFDUSxzQkFBYyxHQUFHLFVBQVMsUUFBUTtJQUN6QyxJQUFJLGNBQWMsR0FBVyxLQUFLLENBQUM7SUFDbkMsSUFBSSxDQUFDO1FBQ0QsT0FBTyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsUUFBUSxDQUFDLENBQUM7UUFDbEMsY0FBYyxHQUFHLElBQUksQ0FBQTtJQUN6QixDQUNBO0lBQUEsS0FBSyxDQUFBLENBQUMsR0FBRyxDQUFDLENBQUEsQ0FBQztRQUNQLGNBQWMsR0FBRyxLQUFLLENBQUM7SUFDM0IsQ0FBQztJQUNELE1BQU0sQ0FBQyxjQU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