HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api-management/node_modules/alce/lib/ast/array.js
var Collection = require('./collection'),
    util = require('util');

module.exports = ArrayCollection;

function ArrayCollection(node, src, options) {
  Collection.apply(this, arguments);

  this.isArray = true;

  Object.defineProperty(this, 'length', {
    enumerable: true,
    get: function() {
      return this.children.length;
    },
    set: function(value) {
      this.children.length = value;
    }
  });
}

util.inherits(ArrayCollection, Collection);

ArrayCollection.prototype.splice = function(index, howMany /* value ... */) {
  var values = [].slice.call(arguments, 2),
      blanks = new Array(values.length);
  blanks.unshift(index, howMany);

  var ret = this.children.splice.apply(this.children, blanks);

  for (var i = 0; i < values.length; i++) {
    this.set(index + i, values[i]);
  }

  return ret.map(function(value) {
    return value.toObject();
  });
};

ArrayCollection.prototype.push = function(/* value ... */) {
  for (var i = 0; i < arguments.length; i++) {
    this.set(this.length, arguments[i]);
  }
  return this.length;
};
ArrayCollection.prototype.pop = function() {
  var ret = this.children.pop();
  if (ret) {
    return ret.toObject();
  }
};
ArrayCollection.prototype.unshift = function(/* value ... */) {
  for (var i = 0; i < arguments.length; i++) {
    this.children.unshift(undefined);
  }
  for (var i = 0; i < arguments.length; i++) {
    this.set(i, arguments[i]);
  }
  return this.length;
};
ArrayCollection.prototype.shift = function() {
  var ret = this.children.shift();
  if (ret) {
    return ret.toObject();
  }
};

ArrayCollection.prototype.open = '[';
ArrayCollection.prototype.close = ']';

ArrayCollection.prototype.toObject = function() {
  return this.children.map(function(child) { return child.toObject(); });
};

ArrayCollection.prototype._getChild = function(id) {
  return this.children[id];
};

ArrayCollection.prototype.set = function(id, value) {
  // Require here to break circular dependency
  var ast = require('./index');
  var original = this.children[id],
      node = ast.fromValue(value, original, this, this.options);

  if (!original) {
    if (this.options && this.options.insertFormatter) {
      this.options.insertFormatter(this, node);
    } else if (this.children.length) {
      node.preamble = ',';
    }
  }

  this.children[id] = node;
  if (node instanceof ast.Array || node instanceof ast.Object) {
    return node;
  } else {
    return node.toObject();
  }
};

ArrayCollection.fromArray = function(value, parent, options) {
  var node = new ArrayCollection(undefined, undefined, options);

  options.seedIndent && options.seedIndent(parent, node);
  options.objectFormatter && options.objectFormatter(parent, node);

  value.forEach(function(value, index) {
    node.set(index, value);
  });
  return node;
};