Skip to content

Commit 1133aac

Browse files
committed
fix: regression when setting raw value to empty string
1 parent 75b67f4 commit 1133aac

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ Retrieves the options on the input
107107

108108
##### rawValue
109109
Retrieves the raw value of the input (numerical)
110-
>>>>>>> 16f3800... feat: update README to reflect various changes to API and development workflows
111110

112111
#### value
113112
Retrieves the formatted value of the input (string)

src/helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,15 @@ export const allowedZero = (val: string, char: string, caretPos: number, options
144144
}
145145
};
146146

147-
export const formattedToRaw = (formattedValue: string, options: IOptions): number => {
147+
export const formattedToRaw = (formattedValue: string, options: IOptions): number | undefined => {
148148
if (is.not.string(formattedValue)) {
149149
return NaN;
150150
}
151151

152+
if (!formattedValue.length) {
153+
return undefined;
154+
}
155+
152156
// Number(...) accepts thousands ',' or '' and decimal '.' so we must:
153157

154158
// 1. Remove thousands delimiter to cover case it is not ','
@@ -202,7 +206,7 @@ export const parseString = (str: string, options: IOptions): string => {
202206
// Need to ensure that delimiter is a '.' before parsing to number
203207
const normalisedNumber = formattedToRaw(parsed, options);
204208
// Then swap it back in
205-
const adjusted = rawToFormatted(normalisedNumber * multiplier, options);
209+
const adjusted = rawToFormatted((normalisedNumber || 0) * multiplier, options);
206210
const tooLarge = adjusted.indexOf("e") !== -1;
207211

208212
if (tooLarge) {

0 commit comments

Comments
 (0)