reslib 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/auth/errors.js +2 -2
- package/build/auth/index.js +2 -2
- package/build/currency/index.d.ts +155 -27
- package/build/currency/index.js +2 -2
- package/build/exception/index.js +2 -2
- package/build/inputFormatter/index.js +2 -2
- package/build/resources/index.js +3 -3
- package/build/utils/index.js +3 -3
- package/build/utils/numbers.js +2 -2
- package/build/validator/index.js +3 -3
- package/build/validator/rules/array.js +2 -2
- package/build/validator/rules/boolean.js +2 -2
- package/build/validator/rules/date.js +2 -2
- package/build/validator/rules/default.js +2 -2
- package/build/validator/rules/enum.js +2 -2
- package/build/validator/rules/file.js +2 -2
- package/build/validator/rules/format.js +3 -3
- package/build/validator/rules/ifRule.js +2 -2
- package/build/validator/rules/index.js +3 -3
- package/build/validator/rules/multiRules.js +2 -2
- package/build/validator/rules/numeric.js +2 -2
- package/build/validator/rules/object.js +2 -2
- package/build/validator/rules/string.js +2 -2
- package/build/validator/rules/target.js +2 -2
- package/build/validator/validator.js +2 -2
- package/package.json +1 -1
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { Currency, CurrencySymbol } from './types';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* Extends the default options with the provided Currency object to initialize default values.
|
|
6
|
-
it sets up default values for currency formatting, merging them with any user-provided options. This ensures that all necessary settings are available for the formatting process.
|
|
7
|
-
*
|
|
8
|
-
* @param options The Currency object to merge with the default options.
|
|
9
|
-
* @returns The merged Currency object with default values.
|
|
10
|
-
*/
|
|
11
|
-
declare function prepareOptions(options?: Currency): Currency;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @description
|
|
15
|
-
* Description of the format for displaying numeric values.
|
|
16
|
-
*
|
|
17
|
-
* The format is a string consisting of the letters %v and %s, where:
|
|
18
|
-
* - %v represents the value of the amount,
|
|
19
|
-
* - %s represents the currency.
|
|
20
|
-
* For example, %s%v => $10 and %v %s => 10 $.
|
|
21
|
-
*
|
|
22
|
-
* To define the decimal places, use the pattern [.][#{0,n}], for example:
|
|
23
|
-
* - .### for display with 3 decimal places,
|
|
24
|
-
* - . for no decimal places in the display.
|
|
25
|
-
* For example, the format %v %s .## returns: 12.35 $ for the value 12.357777 converted to dollars.
|
|
26
|
-
*/
|
|
27
3
|
export declare const CurrencyFormatter: {
|
|
28
|
-
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Takes a string or array of strings, removes all formatting/cruft, and returns the raw float value.
|
|
7
|
+
The unformat function takes a formatted currency string and converts it back to a raw number. This is useful when you need to perform calculations on currency values that may have been stored or input as formatted strings.
|
|
8
|
+
*
|
|
9
|
+
* Alias: `accounting.unformat(string)`
|
|
10
|
+
*
|
|
11
|
+
* Decimal must be included in the regular expression to match floats (default options to
|
|
12
|
+
* accounting.settings.number.decimalSeparator), so if the number uses a non-standard decimalSeparator
|
|
13
|
+
* separator, provide it as the second argument.
|
|
14
|
+
*
|
|
15
|
+
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
|
|
16
|
+
*
|
|
17
|
+
* Doesn't throw any errors (`NaN`s become 0) but this may change in future
|
|
18
|
+
*
|
|
19
|
+
* @param {string | string[]} value The string or array of strings to unformat.
|
|
20
|
+
* @param {string} [decimalSeparator] The decimal separator to use (defaults to accounting.settings.number.decimalSeparator).
|
|
21
|
+
* @returns {number} The unformatted float value.
|
|
22
|
+
*/
|
|
23
|
+
unformat: (value: any, decimalSeparator?: string) => number;
|
|
29
24
|
session: {
|
|
30
25
|
getFormat: (force?: boolean) => string;
|
|
31
26
|
setFormat: (format: string) => void | Promise<void>;
|
|
@@ -33,19 +28,152 @@ export declare const CurrencyFormatter: {
|
|
|
33
28
|
getCurrency: () => Currency;
|
|
34
29
|
defaultCurrencyFormat: string;
|
|
35
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* Format a number into currency.
|
|
34
|
+
*
|
|
35
|
+
* The symbol can be an object, in which case the other properties can be null.
|
|
36
|
+
* Usage: accounting.formatMoney(number, symbol, decimalDigits, thousandsSep, decimalSep, format)
|
|
37
|
+
* prepareOptions: (0, "$", 2, ",", ".", "%s%v")
|
|
38
|
+
*
|
|
39
|
+
* Localise by overriding the symbol, decimalDigits, thousandSeparator / decimalSeparator separators and format
|
|
40
|
+
* Second param can be an object matching `settings.currency` which is the easiest way.
|
|
41
|
+
*
|
|
42
|
+
* To do: tidy up the parameters
|
|
43
|
+
*
|
|
44
|
+
* @param {number} [number] The number to format.
|
|
45
|
+
* @param {Currency | CurrencySymbol} [symbol] The symbol or options object.
|
|
46
|
+
* @param {number} [decimalDigits] The decimal digits to use.
|
|
47
|
+
* @param {string} [thousandSeparator] The thousand separator to use.
|
|
48
|
+
* @param {string} [decimalSeparator] The decimal separator to use.
|
|
49
|
+
* @param {string} [format] The format to use.
|
|
50
|
+
* @returns {string} The formatted number as a string.
|
|
51
|
+
*/
|
|
36
52
|
formatMoney: (number?: number, symbol?: Currency | CurrencySymbol, decimalDigits?: number, thousandSeparator?: string, decimalSeparator?: string, format?: string) => string;
|
|
37
53
|
currencies: import("./types").Currencies;
|
|
38
54
|
isCurrency: (obj: unknown) => obj is Currency;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* Format a number, with comma-separated thousands and custom decimalDigits/decimalSeparator places.
|
|
58
|
+
* The formatNumber function takes a number and formats it with the appropriate thousand separators and decimal places, based on the provided options.
|
|
59
|
+
*
|
|
60
|
+
* Alias: `accounting.format()`
|
|
61
|
+
*
|
|
62
|
+
* Localise by overriding the decimalDigits and thousandSeparator / decimalSeparator separators
|
|
63
|
+
* 2nd parameter `decimalDigits` can be an object matching `settings.number`
|
|
64
|
+
*
|
|
65
|
+
* @param {number} number The number to format.
|
|
66
|
+
* @param {Currency | number} [optionsOrDecimalDigits] The options object or decimal digits to use.
|
|
67
|
+
* @param {string} [thousandSeparator] The thousand separator to use.
|
|
68
|
+
* @param {string} [decimalSeparator] The decimal separator to use.
|
|
69
|
+
* @returns {string} The formatted number as a string.
|
|
70
|
+
*/
|
|
39
71
|
formatNumber: (number: number, optionsOrDecimalDigits?: Currency | number, thousandSeparator?: string, decimalSeparator?: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* Format a number into currency.
|
|
75
|
+
* The formatMoney and formatMoneyAsObject functions are the main workhorses of the module. They take a number and format it as a currency string, applying the appropriate symbol, decimal places, and formatting style. The formatMoneyAsObject version provides more detailed information about the formatting process.
|
|
76
|
+
*
|
|
77
|
+
* The symbol can be an object, in which case the other properties can be null.
|
|
78
|
+
* Usage: accounting.formatMoney(number, symbol, decimalDigits, thousandsSep, decimalSep, format)
|
|
79
|
+
* prepareOptions: (0, "$", 2, ",", ".", "%s%v")
|
|
80
|
+
*
|
|
81
|
+
* Localise by overriding the symbol, decimalDigits, thousandSeparator / decimalSeparator separators and format
|
|
82
|
+
* Second param can be an object matching `settings.currency` which is the easiest way.
|
|
83
|
+
*
|
|
84
|
+
* To do: tidy up the parameters
|
|
85
|
+
*
|
|
86
|
+
* @param {number} [number] The number to format.
|
|
87
|
+
* @param {Currency | CurrencySymbol} [symbol] The symbol or options object.
|
|
88
|
+
* @param {number} [decimalDigits] The decimal digits to use.
|
|
89
|
+
* @param {string} [thousandSeparator] The thousand separator to use.
|
|
90
|
+
* @param {string} [decimalSeparator] The decimal separator to use.
|
|
91
|
+
* @param {string} [format] The format to use.
|
|
92
|
+
* @returns {Currency & {
|
|
93
|
+
* formattedValue: string,
|
|
94
|
+
* formattedNumber: string,
|
|
95
|
+
* usedFormat: string,
|
|
96
|
+
* result: string,
|
|
97
|
+
* }}
|
|
98
|
+
*/
|
|
40
99
|
formatMoneyAsObject: (number?: number, symbol?: Currency | CurrencySymbol, decimalDigits?: number, thousandSeparator?: string, decimalSeparator?: string, format?: string) => Currency & {
|
|
41
100
|
formattedValue: string;
|
|
42
101
|
formattedNumber: string;
|
|
43
102
|
usedFormat: string;
|
|
44
103
|
result: string;
|
|
45
104
|
};
|
|
46
|
-
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* Implementation of toFixed() that treats floats more like decimals.
|
|
108
|
+
The toFixed function addresses issues with floating-point precision in JavaScript, ensuring that decimal places are rounded correctly for currency display.
|
|
109
|
+
*
|
|
110
|
+
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
|
|
111
|
+
* problems for accounting- and finance-related software.
|
|
112
|
+
*
|
|
113
|
+
* @param {number} value The number to format.
|
|
114
|
+
* @param {number} [decimalDigits] The number of decimal digits to round to (defaults to accounting.settings.decimalDigits).
|
|
115
|
+
* @returns {string} The formatted number as a string.
|
|
116
|
+
*/
|
|
47
117
|
toFixed: (value: number, decimalDigits?: number) => string;
|
|
48
|
-
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
* Extends the default options with the provided Currency object to initialize default values.
|
|
121
|
+
it sets up default values for currency formatting, merging them with any user-provided options. This ensures that all necessary settings are available for the formatting process.
|
|
122
|
+
*
|
|
123
|
+
* @param options The Currency object to merge with the default options.
|
|
124
|
+
* @returns The merged Currency object with default values.
|
|
125
|
+
*/
|
|
126
|
+
prepareOptions: (options?: Currency) => Currency;
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* Parse the currency format and return an object containing the parsed format and decimal digits.
|
|
130
|
+
* The parseFormat function helps interpret custom format strings, allowing users to specify how they want their currency displayed (e.g., where the symbol should appear, how many decimal places to show).
|
|
131
|
+
*
|
|
132
|
+
* @param {string} [format] The currency format, a string combining the characters %s, %v, and .#{0,n}, where:
|
|
133
|
+
* - %s represents the currency symbol,
|
|
134
|
+
* - %v represents the value to be formatted,
|
|
135
|
+
* - .#{0,n} represents the number of decimal digits to use, with n being the number of decimal digits.
|
|
136
|
+
* For example, the format %v %s .### formats the number 12555.6893300244 as $12555.689, with 3 decimal digits.
|
|
137
|
+
* If no decimal digits are desired, simply omit the # characters after the dot (e.g., %s %v .).
|
|
138
|
+
*
|
|
139
|
+
* @returns {Currency} An object containing the parsed format and decimal digits.
|
|
140
|
+
*/
|
|
49
141
|
parseFormat: (format?: string) => Currency;
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* Parses a format string or object and returns a format object for use in rendering.
|
|
145
|
+
*
|
|
146
|
+
* @param {string | { pos: string, neg?: string, zero?: string } | (() => string | { pos: string, neg?: string, zero?: string })} format
|
|
147
|
+
* Either a string with the default (positive) format, or an object containing `pos` (required), `neg` and `zero` values (or a function returning either a string or object)
|
|
148
|
+
* @returns {{ pos: string, neg: string, zero: string }} A format object containing positive, negative, and zero formats.
|
|
149
|
+
*/
|
|
150
|
+
checkCurrencyFormat: (format: string | {
|
|
151
|
+
pos: string;
|
|
152
|
+
neg?: string;
|
|
153
|
+
zero?: string;
|
|
154
|
+
} | (() => string | {
|
|
155
|
+
pos: string;
|
|
156
|
+
neg?: string;
|
|
157
|
+
zero?: string;
|
|
158
|
+
})) => {
|
|
159
|
+
pos: string;
|
|
160
|
+
neg: string;
|
|
161
|
+
zero: string;
|
|
162
|
+
};
|
|
50
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* @description
|
|
167
|
+
* Description of the format for displaying numeric values.
|
|
168
|
+
*
|
|
169
|
+
* The format is a string consisting of the letters %v and %s, where:
|
|
170
|
+
* - %v represents the value of the amount,
|
|
171
|
+
* - %s represents the currency.
|
|
172
|
+
* For example, %s%v => $10 and %v %s => 10 $.
|
|
173
|
+
*
|
|
174
|
+
* To define the decimal places, use the pattern [.][#{0,n}], for example:
|
|
175
|
+
* - .### for display with 3 decimal places,
|
|
176
|
+
* - . for no decimal places in the display.
|
|
177
|
+
* For example, the format %v %s .## returns: 12.35 $ for the value 12.357777 converted to dollars.
|
|
178
|
+
*/
|
|
51
179
|
export * from './types';
|