mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Guess numeric formatting options
Summary: Change NumberParse.parse to return not just the parsed number but also information it gathered along the way about how the input string was formatted. Use this in the new NumberParse.guessOptions to guess the actual widget options based on an array of strings. Use NumberParse.guessOptions in TypeConversion (for when a user explicitly chooses to change type) and in ValueGuesser (for guesses about strings entered into empty columns). Test Plan: Adds unit tests for NumberParse and ValueGuesser and updates the TypeChange2 nbrowser test. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3294
This commit is contained in:
@@ -6,7 +6,7 @@ import * as gristTypes from 'app/common/gristTypes';
|
||||
import {getReferencedTableId, isFullReferencingType} from 'app/common/gristTypes';
|
||||
import * as gutil from 'app/common/gutil';
|
||||
import {safeJsonParse} from 'app/common/gutil';
|
||||
import {getCurrency, NumberFormatOptions} from 'app/common/NumberFormat';
|
||||
import {NumberFormatOptions} from 'app/common/NumberFormat';
|
||||
import NumberParse from 'app/common/NumberParse';
|
||||
import {parseDateStrict, parseDateTime} from 'app/common/parseDate';
|
||||
import {MetaRowRecord, TableData} from 'app/common/TableData';
|
||||
@@ -53,11 +53,11 @@ export class NumericParser extends ValueParser {
|
||||
|
||||
constructor(type: string, options: NumberFormatOptions, docSettings: DocumentSettings) {
|
||||
super(type, options, docSettings);
|
||||
this._parse = new NumberParse(docSettings.locale, getCurrency(options, docSettings));
|
||||
this._parse = NumberParse.fromSettings(docSettings, options);
|
||||
}
|
||||
|
||||
public parse(value: string): number | null {
|
||||
return this._parse.parse(value);
|
||||
return this._parse.parse(value)?.result ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user