Skip to content

Commit

Permalink
Polyfill for Object.fromEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Czaplinski authored and pastelmind committed Nov 14, 2022
1 parent 33fd2f9 commit 07fdcc8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EngineData,
GroupDivider,
} from "../../interfaces";
import {fromEntries} from "../../utils/object";

export interface LayerRecord {
name: string;
Expand Down Expand Up @@ -90,7 +91,7 @@ export const createLayerProperties = (
additionalLayerInfos,
} = layerRecord;

const additionalLayerProperties = Object.fromEntries(
const additionalLayerProperties = fromEntries(
additionalLayerInfos.map((ali) => [ali.key, ali])
) as AdditionalLayerProperties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
InvalidBlendingModeSignature,
ReadType,
} from "../../utils";
import {fromEntries} from "../../utils/object";
import {readAdditionalLayerInfo} from "./AdditionalLayerInfo";
import {
MaskData,
Expand Down Expand Up @@ -209,7 +210,7 @@ export function readGlobalAdditionalLayerInformation(
);
}

return Object.fromEntries(
return fromEntries(
additionalLayerInfos.map((ali) => [ali.key, ali])
) as AdditionalLayerProperties;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/psd/src/utils/object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @webtoon/psd
// Copyright 2021-present NAVER WEBTOON
// MIT License

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries
// Unforunately not available in Node 14 according to Typescript
export function fromEntries<K extends string | number, V>(
iterable: Iterable<[K, V]>
): Record<K, V> {
const obj = {} as Record<K, V>;
for (const [k, value] of iterable) {
obj[k] = value;
}
return obj;
}

0 comments on commit 07fdcc8

Please sign in to comment.