Sha256: b0d2e25b7a3b44f9c2575a4fe8172b7cba07316e8580500af9cb6e0331e72525

Contents?: true

Size: 1.09 KB

Versions: 46

Compression:

Stored size: 1.09 KB

Contents

// Internal method, used by iteration functions.
// Calls a function for each key-value pair found in object
// Optionally takes compareFn to iterate object in specific order

"use strict";

var callable                = require("./valid-callable")
  , value                   = require("./valid-value")
  , bind                    = Function.prototype.bind
  , call                    = Function.prototype.call
  , keys                    = Object.keys
  , objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable;

module.exports = function (method, defVal) {
	return function (obj, cb /*, thisArg, compareFn*/) {
		var list, thisArg = arguments[2], compareFn = arguments[3];
		obj = Object(value(obj));
		callable(cb);

		list = keys(obj);
		if (compareFn) {
			list.sort(typeof compareFn === "function" ? bind.call(compareFn, obj) : undefined);
		}
		if (typeof method !== "function") method = list[method];
		return call.call(method, list, function (key, index) {
			if (!objPropertyIsEnumerable.call(obj, key)) return defVal;
			return call.call(cb, thisArg, obj[key], key, obj, index);
		});
	};
};

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.21.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.20.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.19.1 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.19.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.18.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.17.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.16.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.15.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.14.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.13.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.12.2 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.12.1 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.12.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.11.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.10.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.9.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.8.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.7.0 node_modules/es5-ext/object/_iterate.js
govuk_publishing_components-17.6.1 node_modules/es5-ext/object/_iterate.js