LearningSalesForceCommerceC.../storefront-reference-architecture/test/mocks/util/collections.js
2021-12-21 10:57:31 -08:00

49 lines
1.2 KiB
JavaScript

'use strict';
function map() {
var args = Array.from(arguments);
var list = args[0];
var callback = args[1];
if (list && Object.prototype.hasOwnProperty.call(list, 'toArray')) {
list = list.toArray();
}
return list ? list.map(callback) : [];
}
function find() {
var args = Array.from(arguments);
var list = args[0];
var callback = args[1];
if (list && Object.prototype.hasOwnProperty.call(list, 'toArray')) {
list = list.toArray();
}
return list ? list.find(callback) : null;
}
function forEach() {
var args = Array.from(arguments);
var list = args[0];
var callback = args[1];
if (list && Object.prototype.hasOwnProperty.call(list, 'toArray')) {
list = list.toArray();
}
return list ? list.forEach(callback) : null;
}
function every() {
var args = Array.from(arguments);
var list = args[0];
var callback = args[1];
if (list && Object.prototype.hasOwnProperty.call(list, 'toArray')) {
list = list.toArray();
}
return list ? list.every(callback) : null;
}
module.exports = {
find: find,
forEach: forEach,
map: map,
every: every
};