|
| 1 | +:!sectids: |
| 2 | + |
| 3 | +== Why is this an issue? |
| 4 | + |
| 5 | +Importing an external library for lightweight operations increases overall size of the program. |
| 6 | +Using native methods instead reduces the amount of memory and storage to run and store the application. |
| 7 | +This is especially critical in environments with limited resources, such as on mobile devices or in web applications |
| 8 | +where bandwidth and download times matter. |
| 9 | + |
| 10 | +Smaller programs generally have better runtime performance. |
| 11 | +Reducing the number of unnecessary modules minimizes the amount of code that needs to be interpreted or compiled, |
| 12 | +leading to faster execution and improved overall performance. |
| 13 | + |
| 14 | +== Examples |
| 15 | + |
| 16 | +*Example with the https://numbrojs.com/[numbro] library, when you use `format` method.* |
| 17 | + |
| 18 | +[source,js] |
| 19 | +---- |
| 20 | +// Example with numbro (not compliant) |
| 21 | +import numbro from "numbro"; |
| 22 | +
|
| 23 | +numbro.setLanguage('en-GB'); |
| 24 | +var string = numbro(1000).format({ |
| 25 | + thousandSeparated: true, |
| 26 | +}); // '1,000' |
| 27 | +
|
| 28 | +// Example with numerable (not compliant) |
| 29 | +import { format } from "numerable"; |
| 30 | +format(1000, '0,0'); |
| 31 | +
|
| 32 | +// Example with Intl (compliant) |
| 33 | +new Intl.NumberFormat("en-GB").format(1000); // '1,000' |
| 34 | +---- |
| 35 | + |
| 36 | +== Limitations |
| 37 | + |
| 38 | +As for now, only two libraries are handled by this rule : |
| 39 | + |
| 40 | +- https://numbrojs.com/[numbro] |
| 41 | +- https://numerablejs.com/lander[numerable] |
| 42 | + |
| 43 | + |
| 44 | +Some candidates for the future developments are : |
| 45 | + |
| 46 | +- https://github.com/Mottie/javascript-number-formatter[javascript-number-formatter] |
| 47 | +- https://www.npmjs.com/package/numerable[numeraljs] |
| 48 | +- https://formatjs.github.io/[formatjs] |
| 49 | + |
| 50 | +It’s more likely this rule won’t ever be exhaustive. |
| 51 | + |
| 52 | +== Resources |
| 53 | + |
| 54 | +=== Documentation |
| 55 | + |
| 56 | +- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat[Mozilla Web Technology for Developers] |
0 commit comments