How to use the util.isFunction function in util

To help you get started, we’ve selected a few util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kessler / node-digital-tree / index.js View on Github external
_isValidKey(key) {
		// const rightType = Array.isArray(key) || isString(key)
		// return rightType && key.length > 0
		return isFunction(key[Symbol.iterator])
	}
github codius-deprecated / codius-nacl-node / src / js / dns.js View on Github external
function makeAsync(callback) {
  if (!util.isFunction(callback)) {
    return callback;
  }
  return function asyncCallback() {
    if (asyncCallback.immediately) {
      // The API already returned, we can invoke the callback immediately.
      callback.apply(null, arguments);
    } else {
      var args = arguments;
      process.nextTick(function() {
        callback.apply(null, args);
      });
    }
  };
}
github EvaEngine / EvaEngine.js / src / middlewares / view_cache.js View on Github external
export const requestToCacheKey = (req, hashStrategy) => {
  const {
    method,
    originalUrl,
    query: originQuery,
    route,
    uid = null //Custom rule
  } = req;
  const query = { ...originQuery };
  delete query.flush;
  if (hashStrategy && !util.isFunction(hashStrategy)) {
    throw new RuntimeException(`View cache hash strategy must be a function for ${originalUrl}`);
  }
  if (!route) {
    throw new RuntimeException(`View cache middleware require route for ${originalUrl}`);
  }
  if (method.toLowerCase() !== 'get') {
    throw new RuntimeException(`View cache middleware only support GET method of http request for ${originalUrl}`);
  }
  const { host = 'unknown' } = req.headers;
  const [urlPath = ''] = originalUrl.split('?');
  const key = [method, `/${host}`, urlPath].join('').replace(/:/g, '_').toLowerCase();
  const strategy = hashStrategy || defaultHashStrategy;
  const hash = crypto
    .createHash('md5')
    .update(JSON
      .stringify(strategy({
github nodekit-io / nodekit-darwin / src / nodekit / NKCore / lib-core / node / _stream_writable.js View on Github external
Writable.prototype.write = function(chunk, encoding, cb) {
  var state = this._writableState;
  var ret = false;

  if (util.isFunction(encoding)) {
    cb = encoding;
    encoding = null;
  }

  if (util.isBuffer(chunk))
    encoding = 'buffer';
  else if (!encoding)
    encoding = state.defaultEncoding;

  if (!util.isFunction(cb))
    cb = function() {};

  if (state.ended)
    writeAfterEnd(this, state, cb);
  else if (validChunk(this, state, chunk, cb)) {
    state.pendingcb++;
github yodaos-project / ShadowNode / src / js / spi.js View on Github external
function afterCallback(err, buffer) {
      for (var i = 0; i < rxLength; i++) {
        rxBuffer[i] = buffer[i];
      }

      util.isFunction(callback) && callback.call(self, err);
    }
github Jxck / events / events.js View on Github external
EventEmitter.listenerCount = function(emitter, type) {
  var ret;
  if (!emitter._events || !emitter._events[type])
    ret = 0;
  else if (util.isFunction(emitter._events[type]))
    ret = 1;
  else
    ret = emitter._events[type].length;
  return ret;
};
github anchengjian / anchengjian.github.io / config / list.js View on Github external
dirList.forEach((fileName) => {
    if (filter && util.isArray(filter) && filter.indexOf(fileName) >= 0) return;
    let curPath = filePath + (filePath.substr(-1) === '/' ? '' : '/') + fileName;
    let file = fs.statSync(curPath);
    if (file.isFile()) {
      let data = callback && util.isFunction(callback) && callback(curPath, filePath, fileName);
      res.push(data || { path: curPath, name: fileName });
    } else if (file.isDirectory()) {
      res = res.concat(walk(curPath, filter, callback));
    }
  });
  return res;
github criteo / loop / lib / watcher.js View on Github external
exports.watch = function(task, watchFiles) {
  if(util.isFunction(watchFiles)) {
    return watchFiles
  }
  else {
    let patterns = (
      (watchFiles ? (util.isArray(watchFiles) ? watchFiles : [watchFiles]) : []).map(x => x.toString())
    )
    return (filename) => {
      for(let i=0; i
github ShieldBattery / ShieldBattery / node_modules / browserify-middleware / node_modules / browserify / node_modules / insert-module-globals / buffer.js View on Github external
function replacer(key, value) {
  if (util.isUndefined(value)) {
    return '' + value;
  }
  if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
    return value.toString();
  }
  if (util.isFunction(value) || util.isRegExp(value)) {
    return value.toString();
  }
  return value;
}
github nodekit-io / nodekit-darwin / src / nodekit / NKCore / lib-core / node / stream.js View on Github external
function onclose() {
    if (didOnEnd) return;
    didOnEnd = true;

    if (util.isFunction(dest.destroy)) dest.destroy();
  }