Skip to content

Commit 2e0da29

Browse files
committed
Change default precision to 1
1 parent 84e6294 commit 2e0da29

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Changed
1212
- Returns the original number if no unit is available.
13+
- Default precision to 1 instead of 2. (**BREAKING CHANGE**)
14+
- `Options` interface name to `MillifyOptions`. (**BREAKING CHANGE**)
1315

1416
### Removed
1517
- `base` from options. We only intend to support the common grouping base (1000). (**BREAKING CHANGE**)

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ npm install millify
2222
### Command line
2323

2424
```bash
25-
millify 10000
26-
# 10K
25+
$ millify 12345
26+
12.3K
2727
```
28+
2829
See `millify --help` for options.
2930

3031
### Programmatically
3132

32-
#### `millify(number, options)`
33+
#### `millify(value: number, options: MillifyOptions)`
3334

3435
```js
35-
import millify from 'millify';
36+
import millify from "millify";
3637

37-
// For CommonJS: `const { millify } = require('millify');`
38+
// For CommonJS: `const { millify } = require("millify");`
3839

3940
millify(2500); // 2.5K
4041

@@ -46,12 +47,12 @@ millify(1024000, {
4647

4748
millify(39500, {
4849
precision: 2,
49-
decimalSeparator: ','
50+
decimalSeparator: ","
5051
});
5152
// 3,95K
5253

5354
millify(1440000, {
54-
units: ['B', 'KB', 'MB', 'GB'],
55+
units: ["B", "KB", "MB", "GB", "TB"],
5556
space: true,
5657
});
5758
// 1.44 MB
@@ -61,7 +62,7 @@ millify(1440000, {
6162

6263
Name | Type | Default | Description
6364
--- | --- | --- | ---
64-
`precision` | `number` | `2` | Number of significant figures to use
65+
`precision` | `number` | `1` | Number of decimal places to use
6566
`decimalSeparator` | `string` | `'.'` | Desired decimal separator (e.g. decimal point or comma)
6667
`lowercase` | `boolean` | `false` | Use lowercase abbreviations
6768
`space` | `boolean` | `false` | Add a space between number and abbreviation

bin/millify

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ require("yargs").command(
1212
type: "number",
1313
})
1414
.option("precision", {
15-
describe: "Decimal places",
15+
describe: "Number of decimal places",
1616
alias: "p",
1717
type: "number",
18-
default: 2,
18+
default: 1,
1919
})
2020
.option("decimal", {
2121
describe: "Decimal separator (mark)",

lib/millify.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Options, defaultOptions } from "./options";
1+
import { MillifyOptions, defaultOptions } from "./options";
22
import { parseValue, roundTo } from "./utils";
33

44
// Most commonly used digit grouping base.
@@ -34,9 +34,9 @@ function* divider(value: number): IterableIterator<number> {
3434
/**
3535
* millify converts long numbers to human-readable strings.
3636
*/
37-
function millify(value: number, options?: Partial<Options>): string {
37+
function millify(value: number, options?: Partial<MillifyOptions>): string {
3838
// Override default options with options supplied by user.
39-
const opts: Options = options
39+
const opts: MillifyOptions = options
4040
? { ...defaultOptions, ...options }
4141
: defaultOptions;
4242

lib/options.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Options used to configure Millify.
33
*/
4-
export interface Options {
4+
export interface MillifyOptions {
55
/**
66
* The number of significant figures.
77
*/
@@ -27,10 +27,10 @@ export interface Options {
2727
/**
2828
* Default options for Millify.
2929
*/
30-
export const defaultOptions: Options = {
30+
export const defaultOptions: MillifyOptions = {
3131
decimalSeparator: ".",
3232
lowercase: false,
33-
precision: 2,
33+
precision: 1,
3434
space: false,
3535
units: [
3636
"",

0 commit comments

Comments
 (0)