feat(utils): add helpers
This commit is contained in:
parent
7409264b15
commit
cb8749d6be
|
@ -0,0 +1,14 @@
|
|||
// @flow
|
||||
|
||||
export const asyncFilter = async (array: any[], fn: any => Promise<boolean>): Promise<any[]> => {
|
||||
const result = [];
|
||||
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
for (const cur of array) {
|
||||
if (await fn(cur)) result.push(cur);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
// @flow
|
||||
|
||||
export const asyncMap = async (array: any[], fn: any => Promise<any>): Promise<any[]> => {
|
||||
const result = [];
|
||||
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
for (const cur of array) {
|
||||
result.push(await fn(cur));
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
|
@ -0,0 +1,8 @@
|
|||
// @flow
|
||||
const HEX_REGEX = /([0-9]|[a-f])/gim;
|
||||
|
||||
export const isHex = (input: ?string) => {
|
||||
if (!input) return false;
|
||||
|
||||
return (input.match(HEX_REGEX) || []).length === input.length;
|
||||
};
|
Loading…
Reference in New Issue