@lizardbyte/shared-web 2024.921.41053 → 2024.921.183734
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(()=>{var e={415:e=>{function r(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return e>=1e6?(e/1e6).toFixed(r)+"M":e>=1e3?(e/1e3).toFixed(r)+"k":e.toString()}"undefined"!=typeof window&&(window.formatNumber=r),e.exports=r}},r={};!function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o](i,i.exports,t),i.exports}(415)})();
|
|
2
|
+
//# sourceMappingURL=format-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-number.js","mappings":"qBAMA,SAASA,EAAaC,GAAwB,IAAnBC,EAAaC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,EACvC,OAAIF,GAAO,KACCA,EAAM,KAASK,QAAQJ,GAAiB,IACzCD,GAAO,KACNA,EAAM,KAAMK,QAAQJ,GAAiB,IAEtCD,EAAIM,UAEnB,CAGsB,oBAAXC,SACPA,OAAOR,aAAeA,GAG1BS,EAAOC,QAAUV,C,GCpBbW,EAA2B,CAAC,GAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBR,IAAjBS,EACH,OAAOA,EAAaJ,QAGrB,IAAID,EAASE,EAAyBE,GAAY,CAGjDH,QAAS,CAAC,GAOX,OAHAK,EAAoBF,GAAUJ,EAAQA,EAAOC,QAASE,GAG/CH,EAAOC,OACf,CCnB0BE,CAAoB,I","sources":["webpack://@lizardbyte/shared-web/./src/js/format-number.js","webpack://@lizardbyte/shared-web/webpack/bootstrap","webpack://@lizardbyte/shared-web/webpack/startup"],"sourcesContent":["/**\n * Format a number to a human-readable string\n * @param num The number to format\n * @param decimalPlaces The number of decimal places to include in the formatted string\n * @returns {string}\n */\nfunction formatNumber(num, decimalPlaces = 1) {\n if (num >= 1000000) {\n return (num / 1000000).toFixed(decimalPlaces) + 'M';\n } else if (num >= 1000) {\n return (num / 1000).toFixed(decimalPlaces) + 'k';\n } else {\n return num.toString()\n }\n}\n\n// Expose to the global scope\nif (typeof window !== 'undefined') {\n window.formatNumber = formatNumber;\n}\n\nmodule.exports = formatNumber;\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(415);\n"],"names":["formatNumber","num","decimalPlaces","arguments","length","undefined","toFixed","toString","window","module","exports","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|
package/package.json
CHANGED
package/src/js/format-number.js
CHANGED
|
@@ -12,8 +12,8 @@ describe('formatNumber function', () => {
|
|
|
12
12
|
[1234567, 2, '1.23M'], // 1.23 million
|
|
13
13
|
[1234, 1, '1.2k'], // 1.2 thousand
|
|
14
14
|
[1234, 2, '1.23k'], // 1.23 thousand
|
|
15
|
-
[123, 1, '123
|
|
16
|
-
[123, 2, '123
|
|
15
|
+
[123, 1, '123'], // 123 with 1 decimal place
|
|
16
|
+
[123, 2, '123'], // 123 with 2 decimal places
|
|
17
17
|
])('formats %i with %i decimal places as %s', (num, decimalPlaces, expected) => {
|
|
18
18
|
expect(formatNumber(num, decimalPlaces)).toBe(expected);
|
|
19
19
|
});
|
|
@@ -21,6 +21,6 @@ describe('formatNumber function', () => {
|
|
|
21
21
|
test('defaults to 1 decimal place if not provided', () => {
|
|
22
22
|
expect(formatNumber(1234567)).toBe('1.2M');
|
|
23
23
|
expect(formatNumber(1234)).toBe('1.2k');
|
|
24
|
-
expect(formatNumber(123)).toBe('123
|
|
24
|
+
expect(formatNumber(123)).toBe('123');
|
|
25
25
|
});
|
|
26
26
|
});
|