mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 05:47:20 +00:00
Polyfill Array.flat
(#9917)
This commit is contained in:
parent
35a81e7f11
commit
0cbac8bb44
@ -23,6 +23,7 @@ import { subscribePanels } from "../data/ws-panels";
|
||||
import { subscribeThemes } from "../data/ws-themes";
|
||||
import { subscribeUser } from "../data/ws-user";
|
||||
import type { ExternalAuth } from "../external_app/external_auth";
|
||||
import "../resources/array.flat.polyfill";
|
||||
import "../resources/safari-14-attachshadow-patch";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { MAIN_WINDOW_NAME } from "../data/main_window";
|
||||
|
26
src/resources/array.flat.polyfill.ts
Normal file
26
src/resources/array.flat.polyfill.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/* eslint-disable no-extend-native */
|
||||
// @ts-expect-error
|
||||
if (!Array.prototype.flat) {
|
||||
Object.defineProperty(Array.prototype, "flat", {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: function (...args) {
|
||||
const depth = typeof args[0] === "undefined" ? 1 : Number(args[0]) || 0;
|
||||
const result = [];
|
||||
const forEach = result.forEach;
|
||||
|
||||
const flatDeep = (arr: Array<any>, dpth: number) => {
|
||||
forEach.call(arr, (val) => {
|
||||
if (dpth > 0 && Array.isArray(val)) {
|
||||
flatDeep(val, dpth - 1);
|
||||
} else {
|
||||
result.push(val);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
flatDeep(this, depth);
|
||||
return result;
|
||||
},
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user