isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
81 lines (80 loc) • 2.25 kB
JavaScript
;
/**
* These are a collection of functions for non-TypeScript users so that they can access some of
* useful methods offered on the `Array` class in the JavaScript standard library.
*
* If you are a TypeScript user, you should never use these functions, and instead use the more
* idiomatic object-oriented approach.
*
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.every = every;
exports.filter = filter;
exports.find = find;
exports.forEach = forEach;
exports.join = join;
exports.map = map;
exports.some = some;
/**
* Helper function for non-TypeScript users to check if every element in the array is equal to a
* condition.
*
* Internally, this just calls `Array.every`.
*/
function every(array, func) {
return array.every(func);
}
/**
* Helper function for non-TypeScript users to filter the elements in an array. Returns the filtered
* array.
*
* Internally, this just calls `Array.filter`.
*/
function filter(array, func) {
return array.filter(func);
}
/**
* Helper function for non-TypeScript users to find an element in an array.
*
* Internally, this just calls `Array.find`.
*/
function find(array, func) {
return array.find(func);
}
/**
* Helper function for non-TypeScript users to iterate over an array.
*
* Internally, this just calls `Array.forEach`.
*/
function forEach(array, func) {
array.forEach(func); // eslint-disable-line unicorn/no-array-for-each
}
// `includes` is not included since there is a normal array helper function of that name.
/**
* Helper function for non-TypeScript users to convert an array to a string with the specified
* separator.
*
* Internally, this just calls `Array.join`.
*/
function join(array, separator) {
return array.join(separator);
}
/**
* Helper function for non-TypeScript users to convert all of the elements in an array to something
* else.
*
* Internally, this just calls `Array.map`.
*/
function map(array, func) {
return array.map(func);
}
/**
* Helper function for non-TypeScript users to check if one or more elements in the array is equal
* to a condition.
*
* Internally, this just calls `Array.some`.
*/
function some(array, func) {
return array.some(func);
}