summaryrefslogtreecommitdiff
path: root/includes/external/chvfs/node_modules/node-watch/lib/is.js
diff options
context:
space:
mode:
Diffstat (limited to 'includes/external/chvfs/node_modules/node-watch/lib/is.js')
-rw-r--r--includes/external/chvfs/node_modules/node-watch/lib/is.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/includes/external/chvfs/node_modules/node-watch/lib/is.js b/includes/external/chvfs/node_modules/node-watch/lib/is.js
new file mode 100644
index 0000000..ebe0600
--- /dev/null
+++ b/includes/external/chvfs/node_modules/node-watch/lib/is.js
@@ -0,0 +1,78 @@
+var fs = require('fs');
+var path = require('path');
+var os = require('os');
+
+function matchObject(item, str) {
+ return Object.prototype.toString.call(item)
+ === '[object ' + str + ']';
+}
+
+function checkStat(name, fn) {
+ try {
+ return fn(name);
+ } catch (err) {
+ if (/^(ENOENT|EPERM|EACCES)$/.test(err.code)) {
+ if (err.code !== 'ENOENT') {
+ console.warn('Warning: Cannot access %s', name);
+ }
+ return false;
+ }
+ throw err;
+ }
+}
+
+var is = {
+ nil: function(item) {
+ return item == null;
+ },
+ array: function(item) {
+ return Array.isArray(item);
+ },
+ emptyObject: function(item) {
+ for (var key in item) {
+ return false;
+ }
+ return true;
+ },
+ buffer: function(item) {
+ return Buffer.isBuffer(item);
+ },
+ regExp: function(item) {
+ return matchObject(item, 'RegExp');
+ },
+ string: function(item) {
+ return matchObject(item, 'String');
+ },
+ func: function(item) {
+ return typeof item === 'function';
+ },
+ number: function(item) {
+ return matchObject(item, 'Number');
+ },
+ exists: function(name) {
+ return fs.existsSync(name);
+ },
+ file: function(name) {
+ return checkStat(name, function(n) {
+ return fs.statSync(n).isFile()
+ });
+ },
+ samePath: function(a, b) {
+ return path.resolve(a) === path.resolve(b);
+ },
+ directory: function(name) {
+ return checkStat(name, function(n) {
+ return fs.statSync(n).isDirectory()
+ });
+ },
+ symbolicLink: function(name) {
+ return checkStat(name, function(n) {
+ return fs.lstatSync(n).isSymbolicLink();
+ });
+ },
+ windows: function() {
+ return os.platform() === 'win32';
+ }
+};
+
+module.exports = is;