Skip to content

Commit

Permalink
Fixing implementation of 'pad' such that 'separator' is not required …
Browse files Browse the repository at this point in the history
…for it to be applied, fixes #184
  • Loading branch information
avoidwork committed Sep 3, 2024
1 parent bb0fe7c commit 8040401
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _*(number)*_ Decimal place, default is `2`
_*(string)*_ Rounding method, can be `round`, `floor`, or `ceil`, default is `round`

### separator
_*(string)*_ Decimal separator character, default is `.`
_*(string)*_ Decimal separator character, default is an empty string.

### spacer
_*(string)*_ Character between the `result` and `symbol`, default is `" "`
Expand Down
9 changes: 5 additions & 4 deletions dist/filesize.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 10.1.4
* @version 10.1.5
*/
'use strict';

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

if (pad && Number.isInteger(result[0]) === false && round > 0) {
const x = separator || PERIOD,
tmp = result[0].toString().split(x),
if (pad && round > 0) {
const i = result[0].toString(),
x = separator || (i.match(/(\D)/g)?.pop() ?? PERIOD),
tmp = i.toString().split(x),
s = tmp[1] || EMPTY,
l = s.length,
n = round - l;
Expand Down
9 changes: 5 additions & 4 deletions dist/filesize.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 10.1.4
* @version 10.1.5
*/
const ARRAY = "array";
const BIT = "bit";
Expand Down Expand Up @@ -167,9 +167,10 @@ const STRINGS = {
result[0] = result[0].toString().replace(PERIOD, separator);
}

if (pad && Number.isInteger(result[0]) === false && round > 0) {
const x = separator || PERIOD,
tmp = result[0].toString().split(x),
if (pad && round > 0) {
const i = result[0].toString(),
x = separator || (i.match(/(\D)/g)?.pop() ?? PERIOD),
tmp = i.toString().split(x),
s = tmp[1] || EMPTY,
l = s.length,
n = round - l;
Expand Down
4 changes: 2 additions & 2 deletions dist/filesize.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/filesize.esm.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 10.1.4
* @version 10.1.5
*/
(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";
const BIT = "bit";
Expand Down Expand Up @@ -167,9 +167,10 @@ const STRINGS = {
result[0] = result[0].toString().replace(PERIOD, separator);
}

if (pad && Number.isInteger(result[0]) === false && round > 0) {
const x = separator || PERIOD,
tmp = result[0].toString().split(x),
if (pad && round > 0) {
const i = result[0].toString(),
x = separator || (i.match(/(\D)/g)?.pop() ?? PERIOD),
tmp = i.toString().split(x),
s = tmp[1] || EMPTY,
l = s.length,
n = round - l;
Expand Down
4 changes: 2 additions & 2 deletions dist/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8040401

Please sign in to comment.