{"id":28443532,"url":"https://github.com/substrate-system/esm","last_synced_at":"2025-08-20T23:05:49.879Z","repository":{"id":293138117,"uuid":"983029295","full_name":"substrate-system/esm","owner":"substrate-system","description":"Feature detection for modules","archived":false,"fork":false,"pushed_at":"2025-07-27T00:18:47.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-08T22:50:37.881Z","etag":null,"topics":["esm","progressive-enhancement"],"latest_commit_sha":null,"homepage":"https://substrate-system.github.io/esm/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/substrate-system.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-13T19:09:34.000Z","updated_at":"2025-07-27T00:18:51.000Z","dependencies_parsed_at":"2025-07-27T02:08:38.785Z","dependency_job_id":null,"html_url":"https://github.com/substrate-system/esm","commit_stats":null,"previous_names":["substrate-system/esm"],"tags_count":5,"template":false,"template_full_name":"nichoth/template-ts-browser","purl":"pkg:github/substrate-system/esm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/substrate-system%2Fesm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/substrate-system%2Fesm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/substrate-system%2Fesm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/substrate-system%2Fesm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/substrate-system","download_url":"https://codeload.github.com/substrate-system/esm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/substrate-system%2Fesm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271400259,"owners_count":24752830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esm","progressive-enhancement"],"created_at":"2025-06-06T08:07:24.948Z","updated_at":"2025-08-20T23:05:49.874Z","avatar_url":"https://github.com/substrate-system.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esm\n[![GitHub Pages deploy](https://img.shields.io/github/actions/workflow/status/substrate-system/esm/gh-pages.yml?style=flat-square)](https://github.com/substrate-system/esm/actions/workflows/gh-pages.yml)\n[![semantic versioning](https://img.shields.io/badge/semver-2.0.0-blue?logo=semver\u0026style=flat-square)](https://semver.org/)\n[![types](https://img.shields.io/npm/types/@substrate-system/esm?style=flat-square)](README.md)\n[![module](https://img.shields.io/badge/module-ESM%2FCJS-blue?style=flat-square)](README.md)\n[![Common Changelog](https://nichoth.github.io/badge/common-changelog.svg)](./CHANGELOG.md)\n[![GZip size](https://img.shields.io/bundlephobia/minzip/@substrate-system/esm?style=flat-square\u0026color=brightgreen)](https://bundlephobia.com/package/@substrate-system/esm)\n[![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/esm)](https://packagephobia.com/result?p=@substrate-system/esm)\n[![dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg?style=flat-square)](package.json)\n[![license](https://img.shields.io/badge/license-Big_Time-blue?style=flat-square)](LICENSE)\n\n\nFeature detection for modules (ESM) + dynamic imports.\n\n\u003cdetails\u003e\u003csummary\u003e\u003ch2\u003eContents\u003c/h2\u003e\u003c/summary\u003e\n\n\u003c!-- toc --\u003e\n\n- [Install](#install)\n- [API](#api)\n  * [`ES Modules`](#es-modules)\n  * [`importMap`](#importmap)\n  * [`umd(...files:string[])`](#umdfilesstring)\n- [Use](#use)\n  * [ESM + Bundler](#esm--bundler)\n  * [Common JS](#common-js)\n  * [pre-built JS](#pre-built-js)\n  * [CSP](#csp)\n- [Example](#example)\n- [Build](#build)\n  * [Application code](#application-code)\n  * [Dependencies](#dependencies)\n- [develop](#develop)\n\n\u003c!-- tocstop --\u003e\n\n\u003c/details\u003e\n\n## Install\n\n```sh\nnpm i -S @substrate-system/esm\n```\n\n## API\n\n### `ES Modules`\nDynamic imports?\n\n```ts\nfunction esm ():boolean\n```\n\n### `importMap`\nIs `importmap` supported?\n\n```ts\nfunction importMap ():boolean\n```\n\n### `umd(...files:string[])`\nCreate script tags in the document, and wait for them to load.\n\n```ts\nasync function umd (...files:string[]):Promise\u003cvoid\u003e\n```\n\n## Use\n\n### ESM + Bundler\n```js\nimport {\n    importMap,\n    esm,\n    umd\n} from '@substrate-system/esm'\n```\n\n### Common JS\n```js\nrequire('@substrate-system/esm')\n```\n\n### pre-built JS\nCopy the minified files to a location that is accessible to your web server,\nthen link to them in HTML.\n\n#### copy\n```sh\ncp ./node_modules/@substrate-system/esm/dist/index.min.js ./public/esm.min.js\n```\n\n#### HTML\n```html\n\u003cscript type=\"module\" src=\"./esm.min.js\"\u003e\u003c/script\u003e\n```\n\n### CSP\nYou will need to add `unsafe-eval` to your CSP.\n\n```\nscript-src 'self' 'unsafe-eval';\n```\n\n## Example\n\n\u003e [!NOTE]  \n\u003e This would be for a script built with a \"global name\" of `test`,\n\u003e e.g. `--global-name=test`. The name you access on `globalThis` depends on your\n\u003e build process.\n\n```js\nimport { importMap, esm, umd } from '@substrate-system/esm'\n\nconst importMapOk = importMap()\nconst dynamic = esm()\n\nif (dynamic) {\n  const { hello } = await import('/test.js')\n  hello()\n} else {\n  // load a UMD script\n  await umd('/test.umd.js')\n\n  // now we have a global variable\n  hello = globalThis.test.hello\n  hello()\n}\n```\n\n## Build\nIf you need to support both newer platforms, and also platforms without\nES modules, then build a UMD version in addition to building modules.\n\n### Application code\n\n\u003e [!NOTE]  \n\u003e The argument `--external:\"./test.js\"`\n\nIn your top-level module, build it with the relevant dependencies\nexcluded, not bundled.\n\n```sh\nesbuild ./test/index.ts --external:\"./test.js\" --format=iife --bundle --keep-names \u003e public/bundle.js\n```\n\n### Dependencies\n\n\u003e [!NOTE]  \n\u003e The `--global-name` argument\n\nGiven the example above, you would want to build your dependency module\nas an `IIFE` function, attached to `window` at `.test`, in addition to building\nit as a normal ESM module.\n\n```sh\nesbuild ./src/test.ts --global-name=test --format=iife --bundle --keep-names \u003e public/test.umd.js\n```\n\n## develop\n\nThree commands:\n\nBuild the file, and start a server:\n\n```sh\nnpm start\n```\n\nBuild the files in `iife` format, and start a server:\n\n```sh\nnpm run start:iife\n```\n\nBuild in `2016` compatibility mode:\n\n```sh\nnpm run start:2016\n```\n\nDevelopment is a little bit janky because there is not an easy way to start\nan old version of a browser.\n\nThat's why, in the iife and `2016` versions, we do an extra check, besides\nlooking at `esm()`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubstrate-system%2Fesm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubstrate-system%2Fesm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubstrate-system%2Fesm/lists"}