Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pygy/unpkgify
Takes JS source code, and turns raw ES module specifiers into unpkg urls
https://github.com/pygy/unpkgify
Last synced: 25 days ago
JSON representation
Takes JS source code, and turns raw ES module specifiers into unpkg urls
- Host: GitHub
- URL: https://github.com/pygy/unpkgify
- Owner: pygy
- License: isc
- Created: 2024-02-04T13:09:57.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-04T15:15:45.000Z (9 months ago)
- Last Synced: 2024-04-13T19:23:42.184Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esm-unpkgify
## usage
```JS
import {unpkgify} from "esm-unpkgify"console.log(unpkgify(`
import {foo, ffoo as feefoo} from "foo"
import * as bar /*annoying comment*/ from "bar"
import {wont, be, changed} from "https://fully.qualified.url/some-file"function getBaz(){return import("baz")}
ignoreStrings(\`import * as x from "leftAlone"\`)
`))
```prints
```JS
import {foo, ffoo as feefoo} from "https://unpkg.com/foo?module"
import * as bar /*annoying comment*/ from "https://unpkg.com/bar?module"
import {wont, be, changed} from "https://fully.qualified.url/some-file"function getBaz(){return import("https://unpkg.com/baz?module")}
ignoreStrings(`import * as x from "leftAlone"`)
```
## Limitations:
This uses a degenerate parser which doesn't understant regexps, but is otherwise robust (provided valid JS is passed in).
So `const r = /import * as star from "star"/` will be turned into `const r = /import * as star from "https://unpkg.com/star?module"/`. Provided that RegExps of that form are very unlikely to happen in real code (unlike `/import \* as star .../` which is not affected), this is deemed an acceptable tradeof.