UNPKG

@cute-dw/core

Version:

This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need

59 lines (58 loc) 3.05 kB
/** * This class is based on the following excellent work: *********************************************************************************************** * Javascript-number-formatter * Lightweight & Fast JavaScript Number Formatter * * @preserve IntegraXor Web SCADA - JavaScript Number Formatter (http://www.integraxor.com/) * @author KPL * @maintainer Rob Garrison * @copyright 2019 ecava * @license MIT * @link http://mottie.github.com/javascript-number-formatter/ * @version 2.0.9 ***********************************************************************************************/ import { Locale } from "../Locale"; import { NumberFormat } from "./NumberFormat"; export type DecimalFormatOptions = Omit<Intl.NumberFormatOptions, "style"> & { locales?: string | string[] | Locale; }; /** * Decimal number formatter is a concrete subclass of `NumberFormat` that formats decimal numbers. * It has a variety of features designed to make it possible to parse and format numbers in any locale. It also supports different kinds of * numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and * currency amounts ($123). * * A number display format can have up to four _sections_. Only the first is required. The three other sections determine how the data displays if its value is negative, zero, or _null_. The sections are separated by semi-colons: * `positive-format;negative-format;zero-format;null-format`. For example: #,##0.00;(#,##0.00);-;empty * * You can use special characters: * - \# - A number * - 0 - A required number; a number will display for every 0 in the mask * * Percent signs, decimal points, parentheses, and spaces display as entered in the mask. * * In general, a number display format should include at least one 0. If users enter 0 in a field with the mask ###, the field will appear to be blank if you do not provide a zero-format section. If the mask is ###.##, only the period displays. If you want two decimal places to display even if both are 0, use the mask ##0.00. * * You can use a few _keywords_ also. Enclose display format keywords in square brackets ([]). For example, you can use the keyword [General] or [Default] when you want to determine the localized format for a decimal number. Four other available keywords are * _Decimal_, _Currency_, _Unit_ and _Percent_. All keywords are case insensitive. * @since 0.5.0 * @license MIT, (c) 2022 ALEXANDER STRELKOV, alv.strelkov@gmail.com */ export declare class DecimalFormat extends NumberFormat { private _formatter; private _error; private _pattern; private _subpatterns; private _maskObjects; private _options; constructor(pattern?: string, options?: DecimalFormatOptions); private _getIndex; private _parseDisplayMask; private _processValue; private _addSeparators; /** * @override */ format(value: number | null): string; }