@st-lib/ui-number-element
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Custom element for declarative formatting of numbers.

See Intl.NumberFormat.

Intl.NumberFormatOptions#style renamed as type attribute

UINumberElement#innerHTML is used as a fallback if the value cannot be formatted.

// client.js
import UINumberElement from '@st-lib/ui-number-element'

window.customElements.define('ui-number', UINumberElement)

CDN links:

  • https://unpkg.com/@st-lib/ui-number-element/dist/index.js
     <script crossorigin src="https://unpkg.com/@st-lib/ui-number-element/dist/index.js"></script>
  • https://unpkg.com/@st-lib/ui-number-element/dist/index.min.js
     <script crossorigin src="https://unpkg.com/@st-lib/ui-number-element/dist/index.min.js"></script>
<!-- default formatting -->
<ui-number value="123123.123456" maximumFractionDigits="6">
	123 123,123456
</ui-number>
<!-- currency support -->
<ui-number value="3449.64" type="currency" currency="usd">
	3 449,64 $
</ui-number>
<!-- percent support -->
<ui-number value=".27" type="percent">
	27%
</ui-number>
<!-- unit support, see browser compatibility -->
<ui-number value="367" type="unit" unit="day">
	367 days
</ui-number>
<!-- specify another language -->
<ui-number value="367" type="unit" unit="day" unitDisplay="long" lang="ru">
	367 дней
</ui-number>
<!-- invalid value is ignored -->
<ui-number value="the_****_is_lie">
	cake
</ui-number>

Package Sidebar

Install

npm i @st-lib/ui-number-element

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

39.1 kB

Total Files

7

Last publish

Collaborators

  • st-lib