1 | export const removeKeyFromObj = (obj, key) => {
|
2 | const { [key]: omit, ...rest } = obj;
|
3 | return rest;
|
4 | };
|
5 | export const updateOrRemoveKeyFromObj = (obj, key, val) => (val === null
|
6 | ? removeKeyFromObj(obj, key)
|
7 | : {
|
8 | ...obj,
|
9 | [key]: val
|
10 | });
|
11 | export 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 | };
|
18 | export 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 | };
|
25 | export const arrContains = (arr, val) => {
|
26 | return arr.indexOf(val) > -1;
|
27 | };
|
28 | export 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 |
|
\ | No newline at end of file |