How to use the util.isArray 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 Azure / azure-sdk-for-java / AutoRest / Generators / NodeJS / NodeJS.Tests / Expected / AcceptanceTests / Url / operations / queries.js View on Github external
Queries.prototype.arrayStringSsvValid = function (arrayQuery, options, callback) {
  var client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (util.isArray(arrayQuery)) {
      for (var i = 0; i < arrayQuery.length; i++) {
        if (arrayQuery[i] !== null && arrayQuery[i] !== undefined && typeof arrayQuery[i].valueOf() !== 'string') {
          throw new Error('arrayQuery[i] must be of type string.');
        }
      }
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  var requestUrl = this.client.baseUri +
                   '//queries/array/ssv/string/valid';
  var queryParameters = [];
  if (arrayQuery !== null && arrayQuery !== undefined) {
    queryParameters.push('arrayQuery=' + encodeURIComponent(arrayQuery.join(' ')));
github traverson / traverson / lib / transforms / resolve_uri_template.js View on Github external
module.exports = function resolveUriTemplate(t) {
  if (t.step.url) {
    // next link found in last response, might be a URI template
    var templateParams = t.templateParameters;
    if (util.isArray(templateParams)) {
      // if template params were given as an array, only use the array element
      // for the current index for URI template resolving.
      templateParams = templateParams[t.step.index];
    }
    templateParams = templateParams || {};

    if (_s.contains(t.step.url, '{')) {
      log.debug('resolving URI template');
      var template = uriTemplate.parse(t.step.url);
      var resolved = template.expand(templateParams);
      log.debug('resolved to', resolved);
      t.step.url = resolved;
    }
  }
  return true;
};
github mixpanel / mixpanel-node / lib / profile_helpers.js View on Github external
_union({identifiers, data, modifiers, callback}) {
        let $union = {};

        if (typeof(data) !== 'object' || util.isArray(data)) {
            if (this.config.debug) {
                console.error("Invalid value passed to #union - data must be an object with scalar or array values");
            }
            return;
        }

        for (const [key, val] of Object.entries(data)) {
            if (util.isArray(val)) {
                var merge_values = val.filter(function(v) {
                    return typeof(v) === 'string' || typeof(v) === 'number';
                });
                if (merge_values.length > 0) {
                    $union[key] = merge_values;
                }
            } else if (typeof(val) === 'string' || typeof(val) === 'number') {
                $union[key] = [val];
            } else {
                if (this.config.debug) {
                    console.error("Invalid argument passed to #union - values must be a scalar value or array");
                    console.error("Passed " + key + ':', val);
                }
            }
        }
github pierrec / node-atok / src / subrule.js View on Github external
function toRanges (list) {
  return typeof list === 'string'
    ? (list.length === 1
        ? stringCode(list)
        : list.split('').map(stringCode)
      )
    : isArray(list)
      ? list.map(stringCode)
      : typeof list === 'number'
        ? list
        //TODO only strings and numbers supported
        : ''
}
github node-inspector / node-inspector / lib / config.js View on Github external
function serializeOption(key, value, parent) {
  parent = parent ? parent + '.' : '';
  var prefix = (key.length > 1 || parent ? '--' : '-') + parent;
  if (value === undefined) return '';
  if (value === true) {
    return prefix + key;
  } else if (value === false) {
    return prefix + key + '=false';
  } else if (util.isArray(value)) {
    if (!value.length) return '';
    return value.map(function(_value) {
      if (util.isRegExp(_value)) _value = _value.source;
      return prefix + key + '=' + _value;
    });
  } else if (value instanceof Object) {
    return Object.keys(value).map(function(_key) {
      return serializeOption(_key, value[_key], parent + key);
    }).join(' ');
  } else {
    return prefix + key + '=' + value;
  }
}
github Automattic / mongoose / lib / model.js View on Github external
Model.aggregate = function aggregate() {
  var args = [].slice.call(arguments),
      aggregate,
      callback;

  if (typeof args[args.length - 1] === 'function') {
    callback = args.pop();
  }

  if (args.length === 1 && util.isArray(args[0])) {
    aggregate = new Aggregate(args[0]);
  } else {
    aggregate = new Aggregate(args);
  }

  aggregate.model(this);

  if (typeof callback === 'undefined') {
    return aggregate;
  }

  if (callback) {
    callback = this.$wrapCallback(callback);
  }

  aggregate.exec(callback);
github Azure / autorest / src / client / NodeJS / ms-rest / lib / serialization.js View on Github external
jpath.push(util.format('[\'%s\']', item));
        });
        //deserialize the property if it is present in the provided responseBody instance
        var propertyInstance;
        try {
          /*jslint evil: true */
          propertyInstance = eval(jpath.join(''));
        } catch (err) {
          continue;
        }
        var propertyObjectName = objectName;
        if (modelProps[key].serializedName !== '') propertyObjectName = objectName + '.' + modelProps[key].serializedName;
        var propertyMapper = modelProps[key];
        var serializedValue;
        //paging
        if (util.isArray(responseBody[key]) && modelProps[key].serializedName === '') {
          propertyInstance = responseBody[key];
          instance = exports.deserialize.call(this, propertyMapper, propertyInstance, propertyObjectName);
        } else if (propertyInstance !== null && propertyInstance !== undefined) {
          serializedValue = exports.deserialize.call(this, propertyMapper, propertyInstance, propertyObjectName);
          instance[key] = serializedValue;
        }
      }
    }
    return instance;
  }
  return responseBody;
}
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / editor / theme.js View on Github external
function serveFilesFromTheme(themeValue, themeApp, directory) {
    var result = [];
    if (themeValue) {
        var array = themeValue;
        if (!util.isArray(array)) {
            array = [array];
        }

        for (var i=0;i
github Tabcorp / require-lint / lib / index.js View on Github external
var listify = function(obj) {
  if (util.isArray(obj)) return obj;
  if (!obj) return [];
  return [obj];
};
github Paxa / postbird / node_modules / pg / lib / native / index.js View on Github external
//support passing everything in via a config object
  if(typeof config == 'object') {
    query.text = config.text;
    query.values = config.values;
    query.name = config.name;
    query.callback = config.callback;
    query._arrayMode = config.rowMode == 'array';
  }

  //support query({...}, function() {}) style calls
  //& support query(..., ['values'], ...) style calls
  if(typeof values == 'function') {
    query.callback = values;
  }
  else if(util.isArray(values)) {
    query.values = values;
  }
  if(typeof callback == 'function') {
    query.callback = callback;
  }

  this._queryQueue.push(query);
  this._pulseQueryQueue();
  return query;
};