browser-extension-utils 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -76,6 +76,8 @@ export function setAttribute(
76
76
  value: string
77
77
  ): void
78
78
 
79
+ export function removeAttribute(element: HTMLElement, name: string): void
80
+
79
81
  export function setAttributes(
80
82
  element: HTMLElement,
81
83
  attributes: Record<string, unknown>
@@ -161,3 +163,6 @@ export function parseInt10(
161
163
  number: string | undefined,
162
164
  defaultValue?: number
163
165
  ): number
166
+
167
+ // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-redundant-type-constituents
168
+ export function createHTML(html: string): TrustedHTML | string
package/lib/index.js CHANGED
@@ -87,6 +87,8 @@ export const getAttribute = (element, name) =>
87
87
  element ? element.getAttribute(name) : null
88
88
  export const setAttribute = (element, name, value) =>
89
89
  element ? element.setAttribute(name, value) : undefined
90
+ export const removeAttribute = (element, name) =>
91
+ element ? element.removeAttribute(name) : undefined
90
92
 
91
93
  export const setAttributes = (element, attributes) => {
92
94
  if (element && attributes) {
@@ -420,3 +422,15 @@ export const isVisible = (element) => {
420
422
  }
421
423
 
422
424
  export const isTouchScreen = () => "ontouchstart" in win
425
+
426
+ const escapeHTMLPolicy =
427
+ typeof trustedTypes !== "undefined" &&
428
+ typeof trustedTypes.createPolicy === "function"
429
+ ? trustedTypes.createPolicy("beuEscapePolicy", {
430
+ createHTML: (string) => string,
431
+ })
432
+ : undefined
433
+
434
+ export const createHTML = (html) => {
435
+ return escapeHTMLPolicy ? escapeHTMLPolicy.createHTML(html) : html
436
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-utils",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Utilities for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -48,6 +48,7 @@
48
48
  "GM_addElement",
49
49
  "GM_addStyle",
50
50
  "GM_registerMenuCommand",
51
+ "trustedTypes",
51
52
  "MutationObserver",
52
53
  "history",
53
54
  "window",