shelfio / text-normalizer

Clone of openai Whisperer text normalization done and tested on Typescript!
MIT License
3 stars 1 forks source link

Browser support? #26

Closed MarketingPip closed 1 month ago

MarketingPip commented 1 month ago

By chance could we get browser support added to this?

vladholubiev commented 1 month ago

Thanks for your question. In my experience, separate browser builds for npm packages are becoming obsolete. Modern build tools like esbuild, webpack, and others can efficiently handle library compilation for browser environments. Did you face a specific challenge when using this package in browser?

MarketingPip commented 1 month ago

@vladholubiev - correct a ESM build would be ideal. Which for that to work we would need a loader etc for (fs) in the browser.

Ideally would like to just be able to grab this from esm.sh etc - but currently get error from esm.sh - due to no FS supported in browser (on their end)

vladholubiev commented 1 month ago

Where do you see that error? I can open https://esm.sh/@shelf/text-normalizer@1.1.0 without any issues. It works fine for me. Also I don't see where we use FS module in the code.

MarketingPip commented 1 month ago

@vladholubiev - file system is being used here.

Error thrown is:

Uncaught Error: [esm.sh] "node:fs" is not supported in browser environment.
    at n (node_fs.js:1:20)
    at Object.V [as readFileSync] (node_fs.js:1:958)
    at new N (english-spelling.js:13:43)
    at new D (english.js:15:33)

To reproduce this issue load a CodePen etc (browser based environment - ESM.sh loads bundles based on device headers....)

import EnglishTextNormalizer from "https://esm.sh/@shelf/text-normalizer"

const normalizer = new EnglishTextNormalizer.EnglishTextNormalizer()

console.log(normalizer.normalize("Let's")); // Output: let us
console.log(normalizer.normalize("he's like")); // Output: he is like

You can resolve this issue by simply just using a import statement directly to the file and support ESM.

vladholubiev commented 1 month ago

Works in v2.0.0

2024-10-07T20 42 22-eMQ8FMt1@2x

import {EnglishTextNormalizer} from "https://esm.sh/@shelf/text-normalizer"

const normalizer = new EnglishTextNormalizer()

console.log(normalizer.normalize("Let's ")); // Output: let us
console.log(normalizer.normalize("he's like!")); // Output: he is like
vladholubiev commented 1 month ago

https://github.com/shelfio/text-normalizer/releases/tag/v2.0.1

MarketingPip commented 1 month ago

@vladholubiev - awesome little gift pretty well to me (and everyone else obviously lol). Thank you very much! :D