From 62209c3d08560f7ed4fb7d437fec0e1590b6c38f Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Tue, 6 Apr 2021 08:32:38 -0400 Subject: [PATCH] 2.0.1 Switched from es-shim Object.fromEntries polyfill to local TC39 proposal polyfill --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 36 ++++++++++++++++++++++++++++-------- versions.json | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/manifest.json b/manifest.json index 26b2077..23d2b2c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-admonition", "name": "Admonition", - "version": "2.0.0", + "version": "2.0.1", "minAppVersion": "0.11.0", "description": "Admonition block-styled content for Obsidian.md", "author": "Jeremy Valentine", diff --git a/package.json b/package.json index 21e80c8..e5e1017 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-admonition", - "version": "2.0.0", + "version": "2.0.1", "description": "Admonition block-styled content for Obsidian.md", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index da4e24e..85b4fe3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,13 +6,34 @@ import { Plugin } from "obsidian"; -import fromEntries from "object.fromentries/index"; -if (!Object.fromEntries) { - //incorrect @types definition - //I tested that this correctly shims without error - //@ts-expect-error - fromEntries.shim(); -} +Object.fromEntries = + Object.fromEntries || + /** Polyfill taken from https://github.com/tc39/proposal-object-from-entries/blob/master/polyfill.js */ + function ( + entries: Iterable + ): { [k: string]: T } { + const obj = {}; + + for (const pair of entries) { + if (Object(pair) !== pair) { + throw new TypeError( + "iterable for fromEntries should yield objects" + ); + } + // Consistency with Map: contract is that entry has "0" and "1" keys, not + // that it is an array or iterable. + const { "0": key, "1": val } = pair; + + Object.defineProperty(obj, key, { + configurable: true, + enumerable: true, + writable: true, + value: val + }); + } + + return obj; + }; import "./main.css"; @@ -58,7 +79,6 @@ export default class ObsidianAdmonition extends Plugin { this.postprocessor.bind(this, type) ) ); - } postprocessor( type: string, diff --git a/versions.json b/versions.json index 1ad0dee..0bb9099 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,5 @@ { "0.2.3": "0.11.0", "1.0.1": "0.11.0", - "2.0.0": "0.11.0" + "2.0.1": "0.11.0" }