
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
ember-short-number
Advanced tools
Short number formatting based on cldr locale data. Particularly useful for statistical data, showing financial numbers in charts, and abbreviating number of ratings.
1234
is converted to 1K
in English101234
is converted to 101K
in English and 101.1K
if need 1 significant digit1234
is converted to 1 mil
in Espanol101234
is converted to 101,1K
in Espanol if need 1 significant digitBased on cldr-numbers-full
Here is the related proposal for Compact Decimal Format.
Currently this only shortens with latin digits 0..9
For your information, known number systems include:
[adlm, ahom, arab, arabext, armn, armnlow, bali, beng, bhks, brah, cakm, cham, cyrl, deva, ethi, fullwide, geor, grek, greklow, gujr, guru, hanidays, hanidec, hans, hansfin, hant, hantfin, hebr, hmng, java, jpan, jpanfin, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, ...]
Lastly, this work will be built into ember-intl in the near future and will use something like shortNumber
notation style defined in ICU message syntax.
ember install ember-short-number
Provide list of language codes applicable to your app in your environment.js
file. See ISO 639-1 for more information.
If not provided, we will include the data for all CLDR number formatting options in your app. IMPORTANT - this adds ~28KB gzipped to your app so be sure to include all the languages you care about.
let ENV = {
'ember-short-number': {
locales: ['en', 'es'],
threshold: 0.5 // default
}
}
Note - the following APIs take the language code as the the second argument based on ISO 639-1
Template Helper
{{short-number 19634 "en"}}
{{short-number 19634 "en" significantDigits=1}}
{{short-number 101K "en" significantDigits=1 useShorterFormat=true}}
Alternatively use the Service API
this.shortNumber.format(19634, 'en');
// 19K
this.shortNumber.format(19634, 'ja');
// 2万
this.shortNumber.format(19634, 'en', { significantDigits: 1, minimumFractionDigits: 1, maximumFractionDigits: 2 });
// 19.6K
this.shortNumber.format(19634, 'es', { significantDigits: 1 });
// 19,6K
this.shortNumber.format(101, 'en', { significantDigits: 1, useShorterFormat: true });
// 0.1M
toLocaleString
.git clone git@github.com:snewcomer/ember-short-number.git
cd ember-short-number
npm install
npm run lint:js
npm run lint:js -- --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versionsember serve
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.
FAQs
Short Number abbreviation
The npm package ember-short-number receives a total of 483 weekly downloads. As such, ember-short-number popularity was classified as not popular.
We found that ember-short-number demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.