twing
Version:
First-class Twig engine for Node.js
63 lines (62 loc) • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.someSynchronously = exports.some = exports.everySynchronously = exports.every = void 0;
exports.isAMapLike = isAMapLike;
const iterator_to_map_1 = require("./iterator-to-map");
function isAMapLike(candidate) {
return candidate !== null &&
candidate !== undefined &&
candidate.delete !== undefined &&
candidate.get !== undefined &&
candidate.has !== undefined &&
candidate.set !== undefined &&
candidate.entries !== undefined;
}
const every = async (iterable, comparator) => {
if (Array.isArray(iterable)) {
iterable = (0, iterator_to_map_1.iteratorToMap)(iterable);
}
for (const [key, value] of iterable) {
if (await comparator(value, key) === false) {
return false;
}
}
return true;
};
exports.every = every;
const everySynchronously = (iterable, comparator) => {
if (Array.isArray(iterable)) {
iterable = (0, iterator_to_map_1.iteratorToMap)(iterable);
}
for (const [key, value] of iterable) {
if (comparator(value, key) === false) {
return false;
}
}
return true;
};
exports.everySynchronously = everySynchronously;
const some = async (iterable, comparator) => {
if (Array.isArray(iterable)) {
iterable = (0, iterator_to_map_1.iteratorToMap)(iterable);
}
for (const [key, value] of iterable) {
if (await comparator(value, key) === true) {
return true;
}
}
return false;
};
exports.some = some;
const someSynchronously = (iterable, comparator) => {
if (Array.isArray(iterable)) {
iterable = (0, iterator_to_map_1.iteratorToMap)(iterable);
}
for (const [key, value] of iterable) {
if (comparator(value, key) === true) {
return true;
}
}
return false;
};
exports.someSynchronously = someSynchronously;