Sha256: 8a8fd6c94f7fa3eb11eff9da4d8ac60ee105ac8fcfd6d037862e8244b106a618

Contents?: true

Size: 1.2 KB

Versions: 19

Compression:

Stored size: 1.2 KB

Contents

'use strict';

// stdlib
var fs = require('fs');


// provides shortcut to define data property
module.exports.prop = function (obj, name, val) {
  Object.defineProperty(obj, name, {value: val});
};


// helper that stubs `obj` with methods throwing error when they are called
module.exports.stub = function (obj, methods, msg) {
  msg = !!msg ? (': ' + msg) : '';

  methods.forEach(function (func) {
    obj[func] = function () {
      throw new Error('Can\'t call `' + func + '()`' + msg);
    };
  });
};


// wrapper for `fs.statSync`, returns `null` if file does not exist
module.exports.stat = function (pathname) {
  var result = null;
  try {
    result = fs.statSync(pathname);
  } catch (err) {
    if ('ENOENT' !== err.code) {
      throw err;
    }
  }

  return result;
};


// wrapper for `fs.readdirSync` that filters out `.` files and
// `~` swap files. Returns an empty `Array` if the directory does
// not exist.
module.exports.entries = function (pathname) {
  var result = [];
  try {
    result = fs.readdirSync(pathname || '').filter(function (f) {
      return !/^\.|~$|^\#.*\#$/.test(f);
    }).sort();
  } catch (err) {
    if ('ENOENT' !== err.code) {
      throw err;
    }
  }

  return result;
};

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/hike/lib/hike/common.js
ela-4.1.5 node_modules/hike/lib/hike/common.js
ela-4.1.4 node_modules/hike/lib/hike/common.js
ela-4.1.3 node_modules/hike/lib/hike/common.js
ela-4.1.2 node_modules/hike/lib/hike/common.js
ela-4.1.1 node_modules/hike/lib/hike/common.js
ela-4.1.0 node_modules/hike/lib/hike/common.js
ela-4.0.0 node_modules/hike/lib/hike/common.js
ela-3.4.3 node_modules/hike/lib/hike/common.js
ela-3.4.2 node_modules/hike/lib/hike/common.js
ela-3.4.0 node_modules/hike/lib/hike/common.js
ela-3.3.1 node_modules/hike/lib/hike/common.js
ela-3.3.0 node_modules/hike/lib/hike/common.js
ela-3.2.0 node_modules/hike/lib/hike/common.js
ela-3.1.1 node_modules/hike/lib/hike/common.js
ela-3.1.0 node_modules/hike/lib/hike/common.js
ela-3.0.0 node_modules/hike/lib/hike/common.js
ela-2.0.0 node_modules/hike/lib/hike/common.js
ela-1.1.0 node_modules/hike/lib/hike/common.js