moltres-utils
Version:
Utils for Moltres apps
113 lines (84 loc) • 3.08 kB
JavaScript
require("core-js/modules/es6.object.define-property");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.baseIndexOfAtIndex = exports.default = void 0;
require("core-js/modules/es6.array.index-of");
var _curry = _interopRequireDefault(require("../common/curry"));
var _defn = _interopRequireDefault(require("../common/defn"));
var _equals = _interopRequireDefault(require("./equals"));
var _isFunction = _interopRequireDefault(require("../lang/isFunction"));
var _isNaN = _interopRequireDefault(require("../lang/isNaN"));
var _toType = _interopRequireDefault(require("../lang/toType"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var baseIndexOfAtIndex = function baseIndexOfAtIndex(value, index, list) {
var inf;
var item;
var length = list.length; // Array.prototype.indexOf doesn't exist below IE9
if ((0, _isFunction.default)(list.indexOf)) {
switch ((0, _toType.default)(value)) {
case 'Number':
if (value === 0) {
// manually crawl the list to distinguish between +0 and -0
inf = 1 / value;
while (index < length) {
item = list[index];
if (item === 0 && 1 / item === inf) {
return index;
}
index += 1;
}
return -1;
} else if ((0, _isNaN.default)(value)) {
while (index < list.length) {
item = list[index];
if ((0, _isNaN.default)(item)) {
return index;
}
index += 1;
}
return -1;
} // non-zero numbers can utilise Set
return list.indexOf(value, index);
// all these types can utilise Set
case 'String':
case 'Boolean':
case 'Function':
case 'Undefined':
return list.indexOf(value, index);
case 'Null':
// null can utilise Set
return list.indexOf(value, index);
}
} // anything else not covered above, defer to R.equals
while (index < length) {
if ((0, _equals.default)(list[index], value)) {
return index;
}
index += 1;
}
return -1;
};
/**
* Returns the position of the first occurrence of an item in an array, or -1 if the item is not included in the array. [`equals`](#equals) is used to determine equality.
*
* This method automatically upgrades to async if any of the parameters are a Promise
*
* @function
* @since v0.0.18
* @category data
* @param {*} value The value to find.
* @param {Array} list The list to search in.
* @param {number} index The index to start at.
* @return {Number} the index of the value, or -1 if the value is not found.
* @example
*
* indexOfAtIndex(3, 0, [1,2,3,4]) //=> 2
* indexOfAtIndex(3, 3, [1,2,3,4]) //=> -1
*/
exports.baseIndexOfAtIndex = baseIndexOfAtIndex;
var indexOfAtIndex = (0, _curry.default)((0, _defn.default)('indexOfAtIndex', baseIndexOfAtIndex));
var _default = indexOfAtIndex;
exports.default = _default;
//# sourceMappingURL=indexOfAtIndex.js.map
;