diff --git a/app/utils/async-filter.js b/app/utils/async-filter.js new file mode 100644 index 0000000..a6a4e09 --- /dev/null +++ b/app/utils/async-filter.js @@ -0,0 +1,14 @@ +// @flow + +export const asyncFilter = async (array: any[], fn: any => Promise): Promise => { + 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; +}; diff --git a/app/utils/async-map.js b/app/utils/async-map.js new file mode 100644 index 0000000..3de96dd --- /dev/null +++ b/app/utils/async-map.js @@ -0,0 +1,14 @@ +// @flow + +export const asyncMap = async (array: any[], fn: any => Promise): Promise => { + 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; +}; diff --git a/app/utils/is-hex.js b/app/utils/is-hex.js new file mode 100644 index 0000000..a2ba994 --- /dev/null +++ b/app/utils/is-hex.js @@ -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; +};