UNPKG

993 BJavaScriptView Raw
1export const removeKeyFromObj = (obj, key) => {
2 const { [key]: omit, ...rest } = obj; // eslint-disable-line
3 return rest;
4};
5export const updateOrRemoveKeyFromObj = (obj, key, val) => (val === null
6 ? removeKeyFromObj(obj, key)
7 : {
8 ...obj,
9 [key]: val
10 });
11export const mapObj = (obj, fn) => {
12 const newObj = {};
13 Object.entries(obj).forEach(([key, value]) => {
14 newObj[key] = fn(value, key);
15 });
16 return newObj;
17};
18export const mapObjAsync = async (obj, fn) => {
19 const newObj = {};
20 await Promise.all(Object.entries(obj).map(async ([key, value]) => {
21 newObj[key] = await fn(value, key);
22 }));
23 return newObj;
24};
25export const arrContains = (arr, val) => {
26 return arr.indexOf(val) > -1;
27};
28export const asyncWaterfall = async (val, operations) => {
29 let acc = val;
30 for (let i = 0; i < operations.length; i++) {
31 acc = await operations[i](acc);
32 }
33 return acc;
34};
35//# sourceMappingURL=util.js.map
\No newline at end of file