1 | 'use strict';
|
2 | import type { NestedArray } from './commonTypes';
|
3 |
|
4 | export function flattenArray<T>(array: NestedArray<T>): T[] {
|
5 | if (!Array.isArray(array)) {
|
6 | return [array];
|
7 | }
|
8 | const resultArr: T[] = [];
|
9 |
|
10 | const _flattenArray = (arr: NestedArray<T>[]): void => {
|
11 | arr.forEach((item) => {
|
12 | if (Array.isArray(item)) {
|
13 | _flattenArray(item);
|
14 | } else {
|
15 | resultArr.push(item);
|
16 | }
|
17 | });
|
18 | };
|
19 | _flattenArray(array);
|
20 | return resultArr;
|
21 | }
|
22 |
|
23 | export const has = <K extends string>(
|
24 | key: K,
|
25 | x: unknown
|
26 | ): x is { [key in K]: unknown } => {
|
27 | if (typeof x === 'function' || typeof x === 'object') {
|
28 | if (x === null || x === undefined) {
|
29 | return false;
|
30 | } else {
|
31 | return key in x;
|
32 | }
|
33 | }
|
34 | return false;
|
35 | };
|