@xlink-network/xlink-sdk
Version:
140 lines (139 loc) • 3.64 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/arrayHelpers.ts
var arrayHelpers_exports = {};
__export(arrayHelpers_exports, {
concat: () => concat,
first: () => first,
hasAny: () => hasAny,
hasLength: () => hasLength,
last: () => last,
mapFind: () => mapFind,
mapFindP: () => mapFindP,
oneOf: () => oneOf,
range: () => range,
reduce: () => reduce,
reverse: () => reverse,
sortBy: () => sortBy,
uniq: () => uniq
});
module.exports = __toCommonJS(arrayHelpers_exports);
function hasAny(ary) {
return ary.length > 0;
}
function hasLength(input, length) {
return input.length === length;
}
function first(ary) {
return ary[0];
}
function last(ary) {
return ary[ary.length - 1];
}
var _concat = [].concat;
function concat(...inputArrays) {
return _concat.apply([], inputArrays);
}
var _reduce = [].reduce;
function reduce(fn, initialValue, inputArray) {
return _reduce.call(inputArray, fn, initialValue);
}
function range(start, end) {
return Array.from({ length: end - start }, (_, i) => i + start);
}
function reverse(ary) {
const newAry = [...ary];
newAry.reverse();
return newAry;
}
function uniq(ary, iteratee = (item) => item) {
const seen = /* @__PURE__ */ new Set();
return ary.filter((item) => {
const key = iteratee(item);
if (seen.has(key)) {
return false;
}
seen.add(key);
return true;
});
}
function oneOf(...coll) {
return (input) => coll.includes(input);
}
function sortBy(iteratee, ary) {
const _iteratee = Array.isArray(iteratee) ? iteratee : [iteratee];
return ary.map((value, index, ary2) => ({
value,
index,
criteria: _iteratee.map((f) => f(value, index, ary2))
})).sort((left, right) => compareMultiple(left, right)).map((v) => v.value);
}
function compareMultiple(obj, oth) {
const objCriteria = obj.criteria;
const othCriteria = oth.criteria;
const length = objCriteria.length;
let index = -1;
while (++index < length) {
const objCri = objCriteria[index];
const othCri = othCriteria[index];
let result = 0;
if (typeof objCri === typeof othCri) {
result = Number(objCri - othCri);
} else {
result = Number(objCri) - Number(othCri);
}
if (result) return result;
}
return obj.index - oth.index;
}
var mapFind = (fn, input) => {
for (const item of input) {
const result = fn(item);
if (result != null) {
return result;
}
}
return void 0;
};
var mapFindP = async (fn, input) => {
for (const item of input) {
const result = await fn(item);
if (result != null) {
return result;
}
}
return void 0;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
concat,
first,
hasAny,
hasLength,
last,
mapFind,
mapFindP,
oneOf,
range,
reduce,
reverse,
sortBy,
uniq
});
//# sourceMappingURL=arrayHelpers.js.map