Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate browser as target env of exports #40

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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