browser-extension-utils 0.3.3 → 0.3.4

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.
Files changed (2) hide show
  1. package/lib/index.ts +4 -2
  2. package/package.json +1 -1
package/lib/index.ts CHANGED
@@ -22,7 +22,9 @@ export const uniq = <T>(array: T[]): T[] => [...new Set(array)]
22
22
  export const $ = (
23
23
  selector: string,
24
24
  context: Element | Document = doc
25
- ): HTMLElement | null => context.querySelector(selector)!
25
+ ): HTMLElement | undefined =>
26
+ (context ? context.querySelector<HTMLElement>(selector) : undefined) ||
27
+ undefined
26
28
 
27
29
  export const $$ = (
28
30
  selector: string,
@@ -30,7 +32,7 @@ export const $$ = (
30
32
  ): HTMLElement[] =>
31
33
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
34
  // @ts-ignore
33
- [...context.querySelectorAll(selector)] as HTMLElement[]
35
+ [...(context ? context.querySelectorAll(selector) : [])] as HTMLElement[]
34
36
 
35
37
  export const addStyle = (
36
38
  style: string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-utils",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Utilities for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.ts",