Skip to content

Commit 81ed214

Browse files
committed
Remove type declaration file and add type guard in caught error
- This should resolve GH-34
1 parent e5cf5c5 commit 81ed214

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

index.d.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/millify.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defaultOptions } from "./options";
1+
import { defaultOptions, MillifyOptions } from "./options";
22
import { parseValue, roundTo } from "./utils";
33

44
// Most commonly used digit grouping base.
@@ -49,8 +49,10 @@ function millify(value: number, options?: Partial<MillifyOptions>): string {
4949
let val: number;
5050
try {
5151
val = parseValue(value);
52-
} catch (e: any) {
53-
console.warn(`WARN: ${e.message} (millify)`);
52+
} catch (e) {
53+
if (e instanceof Error) {
54+
console.warn(`WARN: ${e.message} (millify)`);
55+
}
5456
// Invalid values will be converted to string as per `String()`.
5557
return String(value);
5658
}

lib/options.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/**
2+
* Options used to configure Millify.
3+
*/
4+
export interface MillifyOptions {
5+
/**
6+
* The number of significant figures.
7+
*/
8+
precision: number;
9+
/**
10+
* The type of decimal marker (e.g. period ".").
11+
*/
12+
decimalSeparator: string;
13+
/**
14+
* Convert units to lower case.
15+
*/
16+
lowercase: boolean;
17+
/**
18+
* Add a space between the number and the unit.
19+
*/
20+
space: boolean;
21+
/**
22+
* A list of units to use.
23+
*/
24+
units: string[];
25+
}
26+
127
/**
228
* Default options for Millify.
329
*/

0 commit comments

Comments
 (0)