bengourley / currency-symbol-map

A function to lookup the currency symbol for a given currency code
BSD 2-Clause "Simplified" License
327 stars 112 forks source link

Not usable via CDN #79

Open kierans opened 2 years ago

kierans commented 2 years ago

I have a Shopify site where I need to dynamically convert from a currency code to a symbol. However being in Shopify I can't use NPM modules.

I'm happy to do a PR for a webpack build so that this library can be used via a CDN.

official-akshayjadhav commented 2 years ago

is there any solution?

kierans commented 2 years ago

@official-akshayjadhav I used my webpack config to create a dist and added it to my Shopify site's assets as a JS file. Adding an include tag in the main template file saw the JS loaded which means I could use the module. However it would be better to have this module in a CDN.

mreinstein commented 2 years ago

you can use skypack, which will transform this nicely for you: https://cdn.skypack.dev/currency-symbol-map

example invocation:

<script type="module">
    import getSymbolFromCurrency from 'https://cdn.skypack.dev/currency-symbol-map'

    const s = getSymbolFromCurrency('USD')
</script>
Daniel-FDS commented 2 years ago

you can use skypack, which will transform this nicely for you: https://cdn.skypack.dev/currency-symbol-map

example invocation:

<script type="module">
    import getSymbolFromCurrency from 'https://cdn.skypack.dev/currency-symbol-map'

    const s = getSymbolFromCurrency('USD')
</script>

Perfect, thank you so much! I was able to get it working with this (although I implemented it a bit differently).

I had made a file called globalModules.js:

import getSymbolFromCurrency from "https://cdn.skypack.dev/currency-symbol-map";

const Get_Currency_Symbol = (code) => {
    return getSymbolFromCurrency(code);
};

export { Get_Currency_Symbol };

I then imported this into another JS file, which was loaded in the HTML with the type="module" attribute:

import { Get_Currency_Symbol } from "./globalModules.js";

Then you directly use the function Get_Currency_Symbol().