pretty-bytes
Advanced tools
Comparing version 6.0.0 to 6.1.0
@@ -59,2 +59,3 @@ export interface Options { | ||
@example | ||
``` | ||
@@ -80,2 +81,3 @@ import prettyBytes from 'pretty-bytes'; | ||
@example | ||
``` | ||
@@ -93,2 +95,20 @@ import prettyBytes from 'pretty-bytes'; | ||
readonly maximumFractionDigits?: number; | ||
/** | ||
Put a space between the number and unit. | ||
@default true | ||
@example | ||
``` | ||
import prettyBytes from 'pretty-bytes'; | ||
prettyBytes(1920, {space: false}); | ||
//=> '1.9kB' | ||
prettyBytes(1920); | ||
//=> '1.92 kB' | ||
``` | ||
*/ | ||
readonly space?: boolean; | ||
} | ||
@@ -95,0 +115,0 @@ |
@@ -74,2 +74,3 @@ const BYTE_UNITS = [ | ||
binary: false, | ||
space: true, | ||
...options, | ||
@@ -82,4 +83,6 @@ }; | ||
const separator = options.space ? ' ' : ''; | ||
if (options.signed && number === 0) { | ||
return ` 0 ${UNITS[0]}`; | ||
return ` 0${separator}${UNITS[0]}`; | ||
} | ||
@@ -106,3 +109,3 @@ | ||
const numberString = toLocaleString(number, options.locale, localeOptions); | ||
return prefix + numberString + ' ' + UNITS[0]; | ||
return prefix + numberString + separator + UNITS[0]; | ||
} | ||
@@ -121,3 +124,3 @@ | ||
return prefix + numberString + ' ' + unit; | ||
return prefix + numberString + separator + unit; | ||
} |
{ | ||
"name": "pretty-bytes", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Convert bytes to a human readable string: 1337 → 1.34 kB", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -126,2 +126,19 @@ # pretty-bytes | ||
##### space | ||
Type: `boolean`\ | ||
Default: `true` | ||
Put a space between the number and unit. | ||
```js | ||
import prettyBytes from 'pretty-bytes'; | ||
prettyBytes(1920, {space: false}); | ||
//=> '1.9kB' | ||
prettyBytes(1920); | ||
//=> '1.92 kB' | ||
``` | ||
## Related | ||
@@ -128,0 +145,0 @@ |
11278
205
147