Skip to content

Commit

Permalink
[FIX] Browser files (jsdeliver) (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan authored Apr 29, 2024
1 parent b9973b6 commit ba5b614
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [5.1.6](https://github.com/omrilotan/isbot/compare/v5.1.5...v5.1.6)

- [FIX] Browser files (jsdeliver): UMD is global and ESM is named

## [5.1.5](https://github.com/omrilotan/isbot/compare/v5.1.4...v5.1.5)

- Add substring "watch" to pattern
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ isbot(
); // false
```

Use JSDeliver CDN you can import an iife script
Use JSDeliver CDN you can import to the browser directly

> See specific versions https://www.jsdelivr.com/package/npm/isbot or https://cdn.jsdelivr.net/npm/isbot
> See specific versions and instructions [https://www.jsdelivr.com/package/npm/isbot](https://www.jsdelivr.com/package/npm/isbot)
ESM

```html
<script type="module">
import { isbot } from "https://cdn.jsdelivr.net/npm/isbot@5/+esm";
isbot(navigator.userAgent);
</script>
```

UMD

```html
<script src="https://cdn.jsdelivr.net/npm/isbot@5"></script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "isbot",
"version": "5.1.5",
"version": "5.1.6",
"description": "🤖/👨‍🦰 Recognise bots/crawlers/spiders using the user agent string.",
"keywords": [
"bot",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/procedure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ esbuild src/index.ts --outfile=index.mjs --bundle --platform=neutral --format=es
failures=$((failures + $?))

echo "→ Build browser file (iife)"
esbuild src/browser.ts --outfile=index.iife.js --bundle --platform=neutral --format=iife --global-name=isbot --log-level=warning --target=es2016
esbuild src/browser.ts --outfile=index.iife.js --bundle --platform=neutral --format=iife --log-level=warning --target=es2016
failures=$((failures + $?))

echo "→ Build TypeScript declaration file"
Expand Down
18 changes: 17 additions & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import { isbot } from ".";

export default isbot;
(function () {
if (typeof globalThis === "object") {
globalThis.isbot = isbot;
return;
}
if (typeof window === "object") {
window.isbot = isbot;
return;
}
if (typeof global === "object") {
global.isbot = isbot;
return;
}
if (typeof self === "object") {
self.isbot = isbot;
}
})();

0 comments on commit ba5b614

Please sign in to comment.