Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Oct 27, 2019
1 parent fe3a257 commit 6af63e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ By default, `byteSize` converts the input number to a human readable string with
{ value: '1.6', unit: 'kB', long: 'kilobytes' }
```

The object returned by `byteSize` defines a `toString` method therefore can be used directly in string context.
The object returned by `byteSize` defines a `toString` method therefore can be used directly in string context (you can override the default behaviour by setting [`options.toStringFn`](https://github.com/75lb/byte-size#bytesizebytes-options--object-)).

```js
> `Filesize: ${byteSize(12400)}`
Expand Down
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ By default, `byteSize` converts the input number to a human readable string with
{ value: '1.6', unit: 'kB', long: 'kilobytes' }
```

The object returned by `byteSize` defines a `toString` method therefore can be used directly in string context.
The object returned by `byteSize` defines a `toString` method therefore can be used directly in string context (you can override the default behaviour by setting [`options.toStringFn`](https://github.com/75lb/byte-size#bytesizebytes-options--object-)).

```js
> `Filesize: ${byteSize(12400)}`
Expand Down Expand Up @@ -95,20 +95,35 @@ Define custom units by passing an object containing one or more additional conve
<a name="module_byte-size"></a>

## byte-size

* [byte-size](#module_byte-size)
* [byteSize(bytes, [options])](#exp_module_byte-size--byteSize) ⇒ <code>object</code> ⏏
* [.defaultOptions([options])](#module_byte-size--byteSize.defaultOptions)

<a name="exp_module_byte-size--byteSize"></a>

### byteSize(bytes, [options]) ⇒ <code>object</code> ⏏
Returns an object with the spec `{ value: string, unit: string, long: string }`. The returned object defines a `toString` method meaning it can be used in any string context.

**Kind**: Exported function

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| bytes | <code>number</code> | | The bytes value to convert. |
| [options] | <code>object</code> | | Optional config. |
| [options.precision] | <code>number</code> | <code>1</code> | Number of decimal places. |
| [options.units] | <code>string</code> | <code>&quot;metric&quot;</code> | Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`. |
| [options.customUnits] | <code>object</code> | | An object containing one or more custom unit lookup tables. |
| Param | Type | Description |
| --- | --- | --- |
| bytes | <code>number</code> | The bytes value to convert. |
| [options] | <code>object</code> | Optional config. |
| [options.precision] | <code>number</code> | Number of decimal places. Defaults to `1`. |
| [options.units] | <code>string</code> | Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`. Defaults to `metric`. |
| [options.customUnits] | <code>object</code> | An object containing one or more custom unit lookup tables. |
| [options.toStringFn] | <code>function</code> | A `toString` function to override the default. |

<a name="module_byte-size--byteSize.defaultOptions"></a>

#### byteSize.defaultOptions([options])
**Kind**: static method of [<code>byteSize</code>](#exp_module_byte-size--byteSize)

| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>object</code> | Default options. |


## Load anywhere
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,20 @@
* Returns an object with the spec `{ value: string, unit: string, long: string }`. The returned object defines a `toString` method meaning it can be used in any string context.
* @param {number} - The bytes value to convert.
* @param [options] {object} - Optional config.
* @param [options.precision=1] {number} - Number of decimal places.
* @param [options.units=metric] {string} - Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`.
* @param [options.precision] {number} - Number of decimal places. Defaults to `1`.
* @param [options.units] {string} - Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`. Defaults to `metric`.
* @param [options.customUnits] {object} - An object containing one or more custom unit lookup tables.
* @param [options.toStringFn] {function} - A `toString` function to override the default.
* @returns {object}
* @alias module:byte-size
*/
function byteSize (bytes, options) {
return new ByteSize(bytes, options)
}

/**
* @param [options] {object} - Default options.
*/
byteSize.defaultOptions = function (options) {
defaultOptions = options;
};
Expand Down
8 changes: 6 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ class ByteSize {
* Returns an object with the spec `{ value: string, unit: string, long: string }`. The returned object defines a `toString` method meaning it can be used in any string context.
* @param {number} - The bytes value to convert.
* @param [options] {object} - Optional config.
* @param [options.precision=1] {number} - Number of decimal places.
* @param [options.units=metric] {string} - Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`.
* @param [options.precision] {number} - Number of decimal places. Defaults to `1`.
* @param [options.units] {string} - Specify `'metric'`, `'iec'`, `'metric_octet'`, `'iec_octet'` or the name of a property from the custom units table in `options.customUnits`. Defaults to `metric`.
* @param [options.customUnits] {object} - An object containing one or more custom unit lookup tables.
* @param [options.toStringFn] {function} - A `toString` function to override the default.
* @returns {object}
* @alias module:byte-size
*/
function byteSize (bytes, options) {
return new ByteSize(bytes, options)
}

/**
* @param [options] {object} - Default options.
*/
byteSize.defaultOptions = function (options) {
defaultOptions = options
}
Expand Down

0 comments on commit 6af63e7

Please sign in to comment.