Skip to content

Commit 8040401

Browse files
committed
Fixing implementation of 'pad' such that 'separator' is not required for it to be applied, fixes #184
1 parent bb0fe7c commit 8040401

12 files changed

+34
-26
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ _*(number)*_ Decimal place, default is `2`
6363
_*(string)*_ Rounding method, can be `round`, `floor`, or `ceil`, default is `round`
6464

6565
### separator
66-
_*(string)*_ Decimal separator character, default is `.`
66+
_*(string)*_ Decimal separator character, default is an empty string.
6767

6868
### spacer
6969
_*(string)*_ Character between the `result` and `symbol`, default is `" "`

dist/filesize.cjs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
55
* @license BSD-3-Clause
6-
* @version 10.1.4
6+
* @version 10.1.5
77
*/
88
'use strict';
99

@@ -171,9 +171,10 @@ function filesize (arg, {
171171
result[0] = result[0].toString().replace(PERIOD, separator);
172172
}
173173

174-
if (pad && Number.isInteger(result[0]) === false && round > 0) {
175-
const x = separator || PERIOD,
176-
tmp = result[0].toString().split(x),
174+
if (pad && round > 0) {
175+
const i = result[0].toString(),
176+
x = separator || (i.match(/(\D)/g)?.pop() ?? PERIOD),
177+
tmp = i.toString().split(x),
177178
s = tmp[1] || EMPTY,
178179
l = s.length,
179180
n = round - l;

dist/filesize.esm.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
55
* @license BSD-3-Clause
6-
* @version 10.1.4
6+
* @version 10.1.5
77
*/
88
const ARRAY = "array";
99
const BIT = "bit";
@@ -167,9 +167,10 @@ const STRINGS = {
167167
result[0] = result[0].toString().replace(PERIOD, separator);
168168
}
169169

170-
if (pad && Number.isInteger(result[0]) === false && round > 0) {
171-
const x = separator || PERIOD,
172-
tmp = result[0].toString().split(x),
170+
if (pad && round > 0) {
171+
const i = result[0].toString(),
172+
x = separator || (i.match(/(\D)/g)?.pop() ?? PERIOD),
173+
tmp = i.toString().split(x),
173174
s = tmp[1] || EMPTY,
174175
l = s.length,
175176
n = round - l;

dist/filesize.esm.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/filesize.esm.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/filesize.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
55
* @license BSD-3-Clause
6-
* @version 10.1.4
6+
* @version 10.1.5
77
*/
88
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.filesize={}));})(this,(function(exports){'use strict';const ARRAY = "array";
99
const BIT = "bit";
@@ -167,9 +167,10 @@ const STRINGS = {
167167
result[0] = result[0].toString().replace(PERIOD, separator);
168168
}
169169

170-
if (pad && Number.isInteger(result[0]) === false && round > 0) {
171-
const x = separator || PERIOD,
172-
tmp = result[0].toString().split(x),
170+
if (pad && round > 0) {
171+
const i = result[0].toString(),
172+
x = separator || (i.match(/(\D)/g)?.pop() ?? PERIOD),
173+
tmp = i.toString().split(x),
173174
s = tmp[1] || EMPTY,
174175
l = s.length,
175176
n = round - l;

dist/filesize.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)