exports-test
Just a silly package that implements a whole lot of different exports
entries in package.json
, along with non-standard but often used root-level fields such as module
, browser
etc.
All the exports expose a single named export: getUsedField()
, which returns a string representing which field was used.
This can be useful if you are authoring or consuming packages and want to understand how your environment (node/deno/bundler/cloud) resolves which file to use.
In addition, there is a second path you can import: exports-test/env
, which exposes a getEnvironmentDetails()
method. This returns an object of the following shape:
{
process: true,
window: false,
global: true,
globalThis: true,
document: false,
require: true,
XMLHttpRequest: false,
EventSource: false,
WebSocket: false,
fetch: true,
setImmediate: true,
URL: true,
URLSearchParams: true,
ReadableStream: true,
WritableStream: true,
Headers: true,
subtleCrypto: true,
processTitle: 'node',
processVersion: 'v18.0.0',
}
The keys represent the API/global we are checking for, and the value represents whether or not the API is available. It does not do any deep checks, however - this is merely a typeof
check - as long as it is not undefined
, it is treated as being present.
Installing
$ npm install exports-test
Usage
import {getUsedField} from 'exports-test'
import {getEnvironmentDetails} from 'exports-test/env'
const {getUsedField} = require('exports-test')
const {getEnvironmentDetails} = require('exports-test/env')
getUsedField()
getEnvironmentDetails()
License
MIT-licensed. See LICENSE.