browser-extension-utils 0.1.10 → 0.1.12

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
168
+ export function createHTML(html: string): string
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ export const win = window
5
5
  export const uniq = (array) => [...new Set(array)]
6
6
 
7
7
  export const toCamelCase = function (text) {
8
- return text.replace(/^([A-Z])|[\s-_](\w)/g, function (match, p1, p2) {
8
+ return text.replaceAll(/^([A-Z])|[\s-_](\w)/g, function (match, p1, p2) {
9
9
  if (p2) return p2.toUpperCase()
10
10
  return p1.toLowerCase()
11
11
  })
@@ -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) {
@@ -202,7 +204,8 @@ export const toStyleMap = (styleText) => {
202
204
  return map
203
205
  }
204
206
 
205
- export const noStyleSpace = (text) => text.replace(/\s*([^\w-+%!])\s*/gm, "$1")
207
+ export const noStyleSpace = (text) =>
208
+ text.replaceAll(/\s*([^\w-+%!])\s*/gm, "$1")
206
209
 
207
210
  export const createSetStyle = (styleText) => {
208
211
  const styleMap = toStyleMap(styleText)
@@ -420,3 +423,15 @@ export const isVisible = (element) => {
420
423
  }
421
424
 
422
425
  export const isTouchScreen = () => "ontouchstart" in win
426
+
427
+ const escapeHTMLPolicy =
428
+ typeof trustedTypes !== "undefined" &&
429
+ typeof trustedTypes.createPolicy === "function"
430
+ ? trustedTypes.createPolicy("beuEscapePolicy", {
431
+ createHTML: (string) => string,
432
+ })
433
+ : undefined
434
+
435
+ export const createHTML = (html) => {
436
+ return escapeHTMLPolicy ? escapeHTMLPolicy.createHTML(html) : html
437
+ }
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.12",
4
4
  "description": "Utilities for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -30,7 +30,7 @@
30
30
  "homepage": "https://github.com/PipecraftNet/browser-extension-utils#readme",
31
31
  "devDependencies": {
32
32
  "prettier": "^2.8.8",
33
- "xo": "^0.54.2"
33
+ "xo": "^0.55.0"
34
34
  },
35
35
  "files": [
36
36
  "lib/",
@@ -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",