omrilotan / isbot

🤖/👨‍🦰 Detect bots/crawlers/spiders using the user agent string
https://isbot.js.org/
The Unlicense
905 stars 74 forks source link

need umd version #204

Closed Augensternhx closed 1 year ago

Augensternhx commented 1 year ago

Steps to reproduce

Expected behaviour

Actual behaviour

Additional details

omrilotan commented 1 year ago

Hey, @Augensternhx , thanks for reaching out. What is the UMD version used for? This package exports both CommonJS and ES module, what is the use case you need here?

https://github.com/omrilotan/isbot/blob/main/package.json#L24-L41

Augensternhx commented 1 year ago

When I use this in my browser

https://cdn.jsdelivr.net/npm/isbot@3.6.6/index.min.js

I will get tips like this

Uncaught ReferenceError: module is not defined

It looks like there is a lack of UMD version, here is the introduction about UMD

http://jargon.js.org/_glossary/UMD.md

If you use rollup, this is a simple example

{
    input: './demo.js',
    output: {
      file: './demo.min.js',
      format: 'umd',
    }
 }
omrilotan commented 1 year ago

if I understand correctly, you want "isbot" to be made available as a global variable once you include this script tag in your page. I'm not the one publishing to jsdeliver network, but you can use this script from their CDN as a module:

<!doctype html>
<html>
  <body>
    <div></div>
    <script type="module">
      import isbot from "https://cdn.jsdelivr.net/npm/isbot@3.6.6/index.min.mjs";
      const is = isbot(navigator.userAgent);
      document.querySelector("div").innerText = `User agent: "${navigator.userAgent}" is ${is ? "" : "not "}a bot`;
    </script>
  </body>
</html>

https://jsfiddle.net/omrilotan/geud63of/

Is this satisfactory?

Augensternhx commented 1 year ago

type="module" This only works with modern browsers,This is not an effective solution

omrilotan commented 1 year ago

I did not create a global variable entry, but I'm open to pull requests if you are very interested. At the moment, I assume most users will bundle the package when building their project, and global variable entries are not usually needed.

omrilotan commented 1 year ago

Let me know what you think of this resolution: https://github.com/omrilotan/isbot/pull/205

3.7.0