Skip to content

Commit

Permalink
Integrate browser as target env of exports
Browse files Browse the repository at this point in the history
Refs #38
  • Loading branch information
char0n committed Jul 25, 2021
1 parent b843b90 commit 53f67a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
16 changes: 0 additions & 16 deletions browser.js

This file was deleted.

24 changes: 24 additions & 0 deletions lib/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable no-undef, no-restricted-globals */

type Name = "FormData" | "Blob" | "File";
type Exports = typeof FormData | typeof Blob | typeof File;
type AccessValue = (name: Name) => Exports;

const accessValue: AccessValue = name => {
// new standardized access to the global object
if (typeof globalThis !== "undefined") {
return globalThis[name]
}
// WebWorker specific access
if (typeof self !== "undefined") {
return self[name]
}

return window[name]
}

const formData = accessValue("FormData")
const blob = accessValue("Blob")
const file = accessValue("File")

export {formData as FormData, blob as Blob, file as File}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
"browser": "./browser.js",
"types": "./@type/index.d.ts",
"exports": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
"node": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"browser": {
"import": "./lib/esm/browser.js",
"require": "./lib/cjs/browser.js"
},
"default": "./lib/esm/index.js"
},
"engines": {
"node": ">= 12.4"
Expand Down

0 comments on commit 53f67a2

Please sign in to comment.