Skip to content

Commit

Permalink
Simplifying the assignment of base & standard, adding an si ali…
Browse files Browse the repository at this point in the history
…as to correct implementations, fixing tests for the standards, adding tests for `si` standard, updating types, updating README.md

Version bump
  • Loading branch information
avoidwork committed Oct 3, 2023
1 parent 6b4b108 commit 720c032
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 144 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ _*(string)*_ Decimal separator character, default is `.`
_*(string)*_ Character between the `result` and `symbol`, default is `" "`

### standard
_*(string)*_ Standard unit of measure, can be `iec` or `jedec`, default is `iec`; can be overruled by `base`
_*(string)*_ Standard unit of measure, can be `iec`, `jedec`, or `si`. Default is `si` (base 10). The `si` option is an alias of `jedec`, such that it is not valid for other configuration options.

### symbols
_*(object)*_ Dictionary of IEC/JEDEC symbols to replace for localization, defaults to english if no match is found
_*(object)*_ Dictionary of IEC/JEDEC symbols to replace for localization, defaults to english if no match is found; SI is handled automatically with JEDEC values.

## Examples

Expand Down Expand Up @@ -103,7 +103,7 @@ in lexical scope.

```javascript
import {partial} from "filesize";
const size = partial({base: 2, standard: "jedec"});
const size = partial({standard: "jedec"});

size(265318); // "259.1 KB"
```
Expand Down
16 changes: 9 additions & 7 deletions dist/filesize.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2023 Jason Mulligan <[email protected]>
* @license BSD-3-Clause
* @version 10.0.13
* @version 10.1.0
*/
'use strict';

Expand All @@ -23,6 +23,7 @@ const OBJECT = "object";
const PERIOD = ".";
const ROUND = "round";
const S = "s";
const SI = "si";
const SI_KBIT = "kbit";
const SI_KBYTE = "kB";
const SPACE = " ";
Expand Down Expand Up @@ -70,15 +71,16 @@ function filesize (arg, {
u = EMPTY;

// Sync base & standard
if (base === -1 && standard.length === 0) {
if (standard === SI) {
base = 10;
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else if (standard === IEC || standard === JEDEC) {
base = 2;
} else if (base === 2) {
standard = IEC;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? JEDEC : standard === JEDEC ? JEDEC : IEC;
base = 10;
standard = JEDEC;
}

const ceil = base === 10 ? 1000 : 1024,
Expand Down
16 changes: 9 additions & 7 deletions dist/filesize.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2023 Jason Mulligan <[email protected]>
* @license BSD-3-Clause
* @version 10.0.13
* @version 10.1.0
*/
const ARRAY = "array";
const BIT = "bit";
Expand All @@ -21,6 +21,7 @@ const OBJECT = "object";
const PERIOD = ".";
const ROUND = "round";
const S = "s";
const SI = "si";
const SI_KBIT = "kbit";
const SI_KBYTE = "kB";
const SPACE = " ";
Expand Down Expand Up @@ -66,15 +67,16 @@ const STRINGS = {
u = EMPTY;

// Sync base & standard
if (base === -1 && standard.length === 0) {
if (standard === SI) {
base = 10;
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else if (standard === IEC || standard === JEDEC) {
base = 2;
} else if (base === 2) {
standard = IEC;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? JEDEC : standard === JEDEC ? JEDEC : IEC;
base = 10;
standard = JEDEC;
}

const ceil = base === 10 ? 1000 : 1024,
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.

16 changes: 9 additions & 7 deletions dist/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2023 Jason Mulligan <[email protected]>
* @license BSD-3-Clause
* @version 10.0.13
* @version 10.1.0
*/
(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 All @@ -21,6 +21,7 @@ const OBJECT = "object";
const PERIOD = ".";
const ROUND = "round";
const S = "s";
const SI = "si";
const SI_KBIT = "kbit";
const SI_KBYTE = "kB";
const SPACE = " ";
Expand Down Expand Up @@ -66,15 +67,16 @@ const STRINGS = {
u = EMPTY;

// Sync base & standard
if (base === -1 && standard.length === 0) {
if (standard === SI) {
base = 10;
standard = JEDEC;
} else if (base === -1 && standard.length > 0) {
standard = standard === IEC ? IEC : JEDEC;
base = standard === IEC ? 2 : 10;
} else if (standard === IEC || standard === JEDEC) {
base = 2;
} else if (base === 2) {
standard = IEC;
} else {
base = base === 2 ? 2 : 10;
standard = base === 10 ? JEDEC : standard === JEDEC ? JEDEC : IEC;
base = 10;
standard = JEDEC;
}

const ceil = base === 10 ? 1000 : 1024,
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 720c032

Please sign in to comment.