alpinejs-money
v1.1.4
Published
Format money through Alpine JS into any language and currency 💸
Downloads
2,346
Maintainers
Readme
Alpine JS Money
Format money through Alpine JS into any language and currency 💸
Install
With a CDN
<script
defer
src="https://unpkg.com/alpinejs-money@latest/dist/money.min.js"
></script>
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
With a Package Manager
npm install -D alpinejs-money
yarn add -D alpinejs-money
import Alpine from 'alpinejs'
import money from 'alpinejs-money'
Alpine.plugin(money)
Alpine.start()
Example
Basic
<div x-data="{ priceInt: 9999, priceDec: 99.99 }">
<p x-money.en-GB.GBP="priceInt"></p>
<p x-money.ja-JP.JPY="priceInt"></p>
<p x-money.en-US.USD="priceInt"></p>
<!-- Decimal -->
<p x-money.en-GB.GBP.decimal="priceDec"></p>
<p x-money.ja-JP.JPY.decimal="priceDec"></p>
<p x-money.en-US.USD.decimal="priceDec"></p>
</div>
With Data Attributes
<div x-data="{ priceInt: 9999, priceDec: 99.99 }">
<p x-money="priceInt" data-locale="en-GB" data-currency="GBP"></p>
<p x-money="priceInt" data-locale="ja-JP" data-currency="JPY"></p>
<p x-money="priceInt" data-locale="en-US" data-currency="USD"></p>
<!-- Decimal -->
<p x-money.decimal="priceDec" data-locale="en-GB" data-currency="GBP"></p>
<p x-money.decimal="priceDec" data-locale="ja-JP" data-currency="JPY"></p>
<p x-money.decimal="priceDec" data-locale="en-US" data-currency="USD"></p>
</div>
With Global
<div x-data="{ priceInt: 9999, priceDec: 99.99 }">
<p x-money.global="priceInt"></p>
<p x-money.global.decimal="priceDec"></p>
</div>
This will look for locale
and currency
which is on the global xMoney
object.
window.xMoney = {
locale: 'en-CA',
currency: 'CAD',
}
With Shopify
<div x-data="{ priceInt: 9999, priceDec: 99.99 }">
<p x-money.shopify="priceInt"></p>
<p x-money.shopify.decimal="priceDec"></p>
</div>
This will look for Shopify.locale
and Shopify.currency.active
which is on
the global Shopify
object.
If this isn't set by default then you can set it like this.
window.Shopify = {
locale: 'en-CA',
currency: {
active: 'CAD',
},
}
Stats