legal-markdown-js 0.1.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/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/browser.d.ts +87 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +157 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli/index.d.ts +34 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +221 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/service.d.ts +128 -0
- package/dist/cli/service.d.ts.map +1 -0
- package/dist/cli/service.js +284 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/constants/index.d.ts +229 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +232 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/exporters/metadata-exporter.d.ts +104 -0
- package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
- package/dist/core/exporters/metadata-exporter.js +201 -0
- package/dist/core/exporters/metadata-exporter.js.map +1 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +56 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parsers/yaml-parser.d.ts +149 -0
- package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
- package/dist/core/parsers/yaml-parser.js +321 -0
- package/dist/core/parsers/yaml-parser.js.map +1 -0
- package/dist/core/processors/clause-processor.d.ts +74 -0
- package/dist/core/processors/clause-processor.d.ts.map +1 -0
- package/dist/core/processors/clause-processor.js +213 -0
- package/dist/core/processors/clause-processor.js.map +1 -0
- package/dist/core/processors/date-processor.d.ts +90 -0
- package/dist/core/processors/date-processor.d.ts.map +1 -0
- package/dist/core/processors/date-processor.js +336 -0
- package/dist/core/processors/date-processor.js.map +1 -0
- package/dist/core/processors/header-processor.d.ts +104 -0
- package/dist/core/processors/header-processor.d.ts.map +1 -0
- package/dist/core/processors/header-processor.js +585 -0
- package/dist/core/processors/header-processor.js.map +1 -0
- package/dist/core/processors/import-processor.d.ts +116 -0
- package/dist/core/processors/import-processor.d.ts.map +1 -0
- package/dist/core/processors/import-processor.js +236 -0
- package/dist/core/processors/import-processor.js.map +1 -0
- package/dist/core/processors/mixin-processor.d.ts +93 -0
- package/dist/core/processors/mixin-processor.d.ts.map +1 -0
- package/dist/core/processors/mixin-processor.js +378 -0
- package/dist/core/processors/mixin-processor.js.map +1 -0
- package/dist/core/processors/reference-processor.d.ts +115 -0
- package/dist/core/processors/reference-processor.d.ts.map +1 -0
- package/dist/core/processors/reference-processor.js +273 -0
- package/dist/core/processors/reference-processor.js.map +1 -0
- package/dist/errors/index.d.ts +234 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +267 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/extensions/batch-processor.d.ts +197 -0
- package/dist/extensions/batch-processor.d.ts.map +1 -0
- package/dist/extensions/batch-processor.js +392 -0
- package/dist/extensions/batch-processor.js.map +1 -0
- package/dist/extensions/formatters/index.d.ts +99 -0
- package/dist/extensions/formatters/index.d.ts.map +1 -0
- package/dist/extensions/formatters/index.js +128 -0
- package/dist/extensions/formatters/index.js.map +1 -0
- package/dist/extensions/index.d.ts +53 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/latex-parser.d.ts +111 -0
- package/dist/extensions/latex-parser.d.ts.map +1 -0
- package/dist/extensions/latex-parser.js +563 -0
- package/dist/extensions/latex-parser.js.map +1 -0
- package/dist/extensions/rst-parser.d.ts +112 -0
- package/dist/extensions/rst-parser.d.ts.map +1 -0
- package/dist/extensions/rst-parser.js +268 -0
- package/dist/extensions/rst-parser.js.map +1 -0
- package/dist/extensions/template-loops.d.ts +61 -0
- package/dist/extensions/template-loops.d.ts.map +1 -0
- package/dist/extensions/template-loops.js +418 -0
- package/dist/extensions/template-loops.js.map +1 -0
- package/dist/extensions/utilities/index.d.ts +114 -0
- package/dist/extensions/utilities/index.d.ts.map +1 -0
- package/dist/extensions/utilities/index.js +137 -0
- package/dist/extensions/utilities/index.js.map +1 -0
- package/dist/extensions/validators/index.d.ts +65 -0
- package/dist/extensions/validators/index.d.ts.map +1 -0
- package/dist/extensions/validators/index.js +88 -0
- package/dist/extensions/validators/index.js.map +1 -0
- package/dist/generators/html-generator.d.ts +184 -0
- package/dist/generators/html-generator.d.ts.map +1 -0
- package/dist/generators/html-generator.js +361 -0
- package/dist/generators/html-generator.js.map +1 -0
- package/dist/generators/pdf-generator.d.ts +165 -0
- package/dist/generators/pdf-generator.d.ts.map +1 -0
- package/dist/generators/pdf-generator.js +275 -0
- package/dist/generators/pdf-generator.js.map +1 -0
- package/dist/helpers/date-helpers.d.ts +216 -0
- package/dist/helpers/date-helpers.d.ts.map +1 -0
- package/dist/helpers/date-helpers.js +402 -0
- package/dist/helpers/date-helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +87 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +149 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/number-helpers.d.ts +269 -0
- package/dist/helpers/number-helpers.d.ts.map +1 -0
- package/dist/helpers/number-helpers.js +406 -0
- package/dist/helpers/number-helpers.js.map +1 -0
- package/dist/helpers/string-helpers.d.ts +391 -0
- package/dist/helpers/string-helpers.d.ts.map +1 -0
- package/dist/helpers/string-helpers.js +549 -0
- package/dist/helpers/string-helpers.js.map +1 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +384 -0
- package/dist/index.js.map +1 -0
- package/dist/legal-markdown.umd.min.js +2 -0
- package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
- package/dist/legal-markdown.umd.min.js.map +1 -0
- package/dist/lib/index.d.ts +150 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +265 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/parsers/content-detector.d.ts +131 -0
- package/dist/parsers/content-detector.d.ts.map +1 -0
- package/dist/parsers/content-detector.js +220 -0
- package/dist/parsers/content-detector.js.map +1 -0
- package/dist/parsers/fallback-parsers.d.ts +14 -0
- package/dist/parsers/fallback-parsers.d.ts.map +1 -0
- package/dist/parsers/fallback-parsers.js +188 -0
- package/dist/parsers/fallback-parsers.js.map +1 -0
- package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
- package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-native.js +63 -0
- package/dist/parsers/implementations/pandoc-native.js.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.js +64 -0
- package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
- package/dist/parsers/pandoc-factory.d.ts +97 -0
- package/dist/parsers/pandoc-factory.d.ts.map +1 -0
- package/dist/parsers/pandoc-factory.js +146 -0
- package/dist/parsers/pandoc-factory.js.map +1 -0
- package/dist/parsers/pandoc-loader.d.ts +24 -0
- package/dist/parsers/pandoc-loader.d.ts.map +1 -0
- package/dist/parsers/pandoc-loader.js +124 -0
- package/dist/parsers/pandoc-loader.js.map +1 -0
- package/dist/parsers/pandoc-parser.d.ts +27 -0
- package/dist/parsers/pandoc-parser.d.ts.map +1 -0
- package/dist/parsers/pandoc-parser.js +3 -0
- package/dist/parsers/pandoc-parser.js.map +1 -0
- package/dist/styles/default.css +125 -0
- package/dist/styles/headers.css +146 -0
- package/dist/styles/highlight.css +171 -0
- package/dist/tracking/field-tracker.d.ts +206 -0
- package/dist/tracking/field-tracker.d.ts.map +1 -0
- package/dist/tracking/field-tracker.js +247 -0
- package/dist/tracking/field-tracker.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +107 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/web/bundle-standalone.js +28 -0
- package/dist/web/bundle.js +17 -0
- package/dist/web/index.html +1465 -0
- package/dist/web/legal-markdown.umd.min.js +2 -0
- package/dist/web/standalone.html +390 -0
- package/dist/web/styles.css +874 -0
- package/package.json +118 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Number Formatting and Conversion Helpers
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive number formatting utilities specifically
|
|
5
|
+
* designed for legal and financial documents. It includes functions for currency
|
|
6
|
+
* formatting, percentage display, number-to-words conversion, and various
|
|
7
|
+
* numerical representations commonly used in legal contexts.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Currency formatting with multiple currency support (EUR, USD, GBP)
|
|
11
|
+
* - Percentage formatting with customizable precision
|
|
12
|
+
* - Number-to-words conversion for legal document amounts
|
|
13
|
+
* - Integer formatting with thousand separators
|
|
14
|
+
* - Flexible number formatting with custom separators
|
|
15
|
+
* - Rounding utilities for precise calculations
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { formatCurrency, formatPercent, numberToWords } from './number-helpers';
|
|
20
|
+
*
|
|
21
|
+
* // Currency formatting
|
|
22
|
+
* const amount = formatCurrency(1234.56, 'USD'); // "$1,234.56"
|
|
23
|
+
*
|
|
24
|
+
* // Percentage formatting
|
|
25
|
+
* const rate = formatPercent(0.155, 2); // "15.50%"
|
|
26
|
+
*
|
|
27
|
+
* // Number to words for legal documents
|
|
28
|
+
* const words = numberToWords(1500); // "one thousand five hundred"
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Formats a number as an integer with thousand separators
|
|
33
|
+
*
|
|
34
|
+
* Converts a number to an integer representation with customizable thousand
|
|
35
|
+
* separators. Useful for displaying whole numbers in legal documents with
|
|
36
|
+
* proper formatting for readability.
|
|
37
|
+
*
|
|
38
|
+
* @param {number | string} value - The number to format
|
|
39
|
+
* @param {string} separator - The thousand separator character (default: ',')
|
|
40
|
+
* @returns {string} The formatted integer string
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Standard formatting
|
|
45
|
+
* formatInteger(1234567); // "1,234,567"
|
|
46
|
+
* formatInteger(1234567.89); // "1,234,567" (decimal part removed)
|
|
47
|
+
*
|
|
48
|
+
* // Custom separator
|
|
49
|
+
* formatInteger(1234567, '.'); // "1.234.567"
|
|
50
|
+
* formatInteger(1234567, ' '); // "1 234 567"
|
|
51
|
+
*
|
|
52
|
+
* // String input
|
|
53
|
+
* formatInteger('1234567'); // "1,234,567"
|
|
54
|
+
*
|
|
55
|
+
* // Invalid input handling
|
|
56
|
+
* formatInteger('not a number'); // "not a number"
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function formatInteger(value: number | string, separator?: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Formats a number as a percentage with customizable precision
|
|
62
|
+
*
|
|
63
|
+
* Converts a number to percentage format with configurable decimal places
|
|
64
|
+
* and optional percentage symbol. Useful for displaying rates, discounts,
|
|
65
|
+
* and other percentage values in legal documents.
|
|
66
|
+
*
|
|
67
|
+
* @param {number | string} value - The number to format as percentage
|
|
68
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
69
|
+
* @param {boolean} symbol - Whether to include the % symbol (default: true)
|
|
70
|
+
* @returns {string} The formatted percentage string
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Standard percentage formatting
|
|
75
|
+
* formatPercent(0.1556); // "15.56%"
|
|
76
|
+
* formatPercent(0.1556, 1); // "15.6%"
|
|
77
|
+
* formatPercent(0.1556, 0); // "16%"
|
|
78
|
+
*
|
|
79
|
+
* // Without percentage symbol
|
|
80
|
+
* formatPercent(0.1556, 2, false); // "15.56"
|
|
81
|
+
*
|
|
82
|
+
* // String input
|
|
83
|
+
* formatPercent('0.25'); // "25.00%"
|
|
84
|
+
*
|
|
85
|
+
* // Whole number input (treated as percentage)
|
|
86
|
+
* formatPercent(25); // "25.00%"
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function formatPercent(value: number | string, decimals?: number, symbol?: boolean): string;
|
|
90
|
+
/**
|
|
91
|
+
* Formats a number as currency with support for multiple currencies
|
|
92
|
+
*
|
|
93
|
+
* Converts a number to currency format with proper symbol placement,
|
|
94
|
+
* thousand separators, and decimal precision. Supports EUR, USD, and GBP
|
|
95
|
+
* with correct formatting conventions for each currency.
|
|
96
|
+
*
|
|
97
|
+
* @param {number | string} value - The number to format as currency
|
|
98
|
+
* @param {'EUR' | 'USD' | 'GBP'} currency - The currency type (default: 'EUR')
|
|
99
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
100
|
+
* @returns {string} The formatted currency string
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Euro formatting (symbol after amount)
|
|
105
|
+
* formatCurrency(1234.56, 'EUR'); // "1,234.56 €"
|
|
106
|
+
* formatCurrency(1234.56, 'EUR', 0); // "1,235 €"
|
|
107
|
+
*
|
|
108
|
+
* // US Dollar formatting (symbol before amount)
|
|
109
|
+
* formatCurrency(1234.56, 'USD'); // "$1,234.56"
|
|
110
|
+
*
|
|
111
|
+
* // British Pound formatting (symbol before amount)
|
|
112
|
+
* formatCurrency(1234.56, 'GBP'); // "£1,234.56"
|
|
113
|
+
*
|
|
114
|
+
* // String input
|
|
115
|
+
* formatCurrency('1234.56', 'USD'); // "$1,234.56"
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function formatCurrency(value: number | string, currency?: 'EUR' | 'USD' | 'GBP', decimals?: number): string;
|
|
119
|
+
/**
|
|
120
|
+
* Formats a number as Euro currency
|
|
121
|
+
*
|
|
122
|
+
* Convenience function for formatting numbers as Euro currency with
|
|
123
|
+
* proper Euro symbol placement and formatting conventions.
|
|
124
|
+
*
|
|
125
|
+
* @param {number | string} value - The number to format as Euro
|
|
126
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
127
|
+
* @returns {string} The formatted Euro currency string
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* formatEuro(1234.56); // "1,234.56 €"
|
|
132
|
+
* formatEuro(1234.56, 0); // "1,235 €"
|
|
133
|
+
* formatEuro('500'); // "500.00 €"
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function formatEuro(value: number | string, decimals?: number): string;
|
|
137
|
+
/**
|
|
138
|
+
* Formats a number as US Dollar currency
|
|
139
|
+
*
|
|
140
|
+
* Convenience function for formatting numbers as US Dollar currency with
|
|
141
|
+
* proper dollar symbol placement and formatting conventions.
|
|
142
|
+
*
|
|
143
|
+
* @param {number | string} value - The number to format as US Dollar
|
|
144
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
145
|
+
* @returns {string} The formatted US Dollar currency string
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* formatDollar(1234.56); // "$1,234.56"
|
|
150
|
+
* formatDollar(1234.56, 0); // "$1,235"
|
|
151
|
+
* formatDollar('500'); // "$500.00"
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function formatDollar(value: number | string, decimals?: number): string;
|
|
155
|
+
/**
|
|
156
|
+
* Formats a number as British Pound currency
|
|
157
|
+
*
|
|
158
|
+
* Convenience function for formatting numbers as British Pound currency with
|
|
159
|
+
* proper pound symbol placement and formatting conventions.
|
|
160
|
+
*
|
|
161
|
+
* @param {number | string} value - The number to format as British Pound
|
|
162
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
163
|
+
* @returns {string} The formatted British Pound currency string
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* formatPound(1234.56); // "£1,234.56"
|
|
168
|
+
* formatPound(1234.56, 0); // "£1,235"
|
|
169
|
+
* formatPound('500'); // "£500.00"
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function formatPound(value: number | string, decimals?: number): string;
|
|
173
|
+
/**
|
|
174
|
+
* Converts a number to its written word representation
|
|
175
|
+
*
|
|
176
|
+
* Transforms numeric values into their English word equivalents, which is
|
|
177
|
+
* particularly useful for legal documents where amounts are often written
|
|
178
|
+
* in both numeric and word form for clarity and legal precision.
|
|
179
|
+
*
|
|
180
|
+
* @param {number | string} num - The number to convert to words
|
|
181
|
+
* @returns {string} The number expressed in words
|
|
182
|
+
*
|
|
183
|
+
* Supported range: Supports numbers from 0 to 999,999,999 with decimal support
|
|
184
|
+
* Decimal handling: Decimal parts are expressed as "and X cents"
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Whole numbers
|
|
189
|
+
* numberToWords(0); // "zero"
|
|
190
|
+
* numberToWords(42); // "forty two"
|
|
191
|
+
* numberToWords(1500); // "one thousand five hundred"
|
|
192
|
+
* numberToWords(1000000); // "one million"
|
|
193
|
+
*
|
|
194
|
+
* // Decimal numbers
|
|
195
|
+
* numberToWords(123.45); // "one hundred twenty three and forty five cents"
|
|
196
|
+
* numberToWords(1000.50); // "one thousand and fifty cents"
|
|
197
|
+
*
|
|
198
|
+
* // String input
|
|
199
|
+
* numberToWords('456'); // "four hundred fifty six"
|
|
200
|
+
*
|
|
201
|
+
* // Negative numbers
|
|
202
|
+
* numberToWords(-100); // "negative one hundred"
|
|
203
|
+
*
|
|
204
|
+
* // Invalid input
|
|
205
|
+
* numberToWords('invalid'); // "invalid"
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function numberToWords(num: number | string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Formats a number with custom decimal and thousand separators
|
|
211
|
+
*
|
|
212
|
+
* Provides flexible number formatting with customizable separators for
|
|
213
|
+
* different locales and formatting requirements. Useful for international
|
|
214
|
+
* legal documents that require specific number formatting conventions.
|
|
215
|
+
*
|
|
216
|
+
* @param {number | string} value - The number to format
|
|
217
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
218
|
+
* @param {string} decimalSeparator - Character for decimal separation (default: '.')
|
|
219
|
+
* @param {string} thousandSeparator - Character for thousand separation (default: ',')
|
|
220
|
+
* @returns {string} The formatted number string
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* // Standard US formatting
|
|
225
|
+
* formatNumber(1234.56); // "1,234.56"
|
|
226
|
+
* formatNumber(1234.56, 3); // "1,234.560"
|
|
227
|
+
*
|
|
228
|
+
* // European formatting (comma as decimal separator)
|
|
229
|
+
* formatNumber(1234.56, 2, ',', ' '); // "1 234,56"
|
|
230
|
+
* formatNumber(1234.56, 2, ',', '.'); // "1.234,56"
|
|
231
|
+
*
|
|
232
|
+
* // Custom formatting
|
|
233
|
+
* formatNumber(1234.56, 1, ':', '|'); // "1|234:6"
|
|
234
|
+
*
|
|
235
|
+
* // String input
|
|
236
|
+
* formatNumber('1234.56'); // "1,234.56"
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export declare function formatNumber(value: number | string, decimals?: number, decimalSeparator?: string, thousandSeparator?: string): string;
|
|
240
|
+
/**
|
|
241
|
+
* Rounds a number to a specified number of decimal places
|
|
242
|
+
*
|
|
243
|
+
* Provides precise rounding functionality for numerical calculations in
|
|
244
|
+
* legal documents. Uses standard mathematical rounding rules (0.5 rounds up).
|
|
245
|
+
*
|
|
246
|
+
* @param {number | string} value - The number to round
|
|
247
|
+
* @param {number} decimals - Number of decimal places to round to (default: 0)
|
|
248
|
+
* @returns {number} The rounded number
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Round to whole numbers
|
|
253
|
+
* round(1234.56); // 1235
|
|
254
|
+
* round(1234.44); // 1234
|
|
255
|
+
*
|
|
256
|
+
* // Round to decimal places
|
|
257
|
+
* round(1234.5678, 2); // 1234.57
|
|
258
|
+
* round(1234.5678, 1); // 1234.6
|
|
259
|
+
* round(1234.5678, 3); // 1234.568
|
|
260
|
+
*
|
|
261
|
+
* // String input
|
|
262
|
+
* round('1234.56', 1); // 1234.6
|
|
263
|
+
*
|
|
264
|
+
* // Invalid input handling
|
|
265
|
+
* round('invalid'); // 0
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export declare function round(value: number | string, decimals?: number): number;
|
|
269
|
+
//# sourceMappingURL=number-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/number-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAOrF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,GAAE,MAAU,EACpB,MAAM,GAAE,OAAc,GACrB,MAAM,CAMR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,GAAE,KAAK,GAAG,KAAK,GAAG,KAAa,EACvC,QAAQ,GAAE,MAAU,GACnB,MAAM,CAmBR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAE/E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAEjF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAEhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAuF1D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,GAAE,MAAU,EACpB,gBAAgB,GAAE,MAAY,EAC9B,iBAAiB,GAAE,MAAY,GAC9B,MAAM,CAQR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAM1E"}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Number Formatting and Conversion Helpers
|
|
4
|
+
*
|
|
5
|
+
* This module provides comprehensive number formatting utilities specifically
|
|
6
|
+
* designed for legal and financial documents. It includes functions for currency
|
|
7
|
+
* formatting, percentage display, number-to-words conversion, and various
|
|
8
|
+
* numerical representations commonly used in legal contexts.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Currency formatting with multiple currency support (EUR, USD, GBP)
|
|
12
|
+
* - Percentage formatting with customizable precision
|
|
13
|
+
* - Number-to-words conversion for legal document amounts
|
|
14
|
+
* - Integer formatting with thousand separators
|
|
15
|
+
* - Flexible number formatting with custom separators
|
|
16
|
+
* - Rounding utilities for precise calculations
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { formatCurrency, formatPercent, numberToWords } from './number-helpers';
|
|
21
|
+
*
|
|
22
|
+
* // Currency formatting
|
|
23
|
+
* const amount = formatCurrency(1234.56, 'USD'); // "$1,234.56"
|
|
24
|
+
*
|
|
25
|
+
* // Percentage formatting
|
|
26
|
+
* const rate = formatPercent(0.155, 2); // "15.50%"
|
|
27
|
+
*
|
|
28
|
+
* // Number to words for legal documents
|
|
29
|
+
* const words = numberToWords(1500); // "one thousand five hundred"
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.formatInteger = formatInteger;
|
|
34
|
+
exports.formatPercent = formatPercent;
|
|
35
|
+
exports.formatCurrency = formatCurrency;
|
|
36
|
+
exports.formatEuro = formatEuro;
|
|
37
|
+
exports.formatDollar = formatDollar;
|
|
38
|
+
exports.formatPound = formatPound;
|
|
39
|
+
exports.numberToWords = numberToWords;
|
|
40
|
+
exports.formatNumber = formatNumber;
|
|
41
|
+
exports.round = round;
|
|
42
|
+
/**
|
|
43
|
+
* Formats a number as an integer with thousand separators
|
|
44
|
+
*
|
|
45
|
+
* Converts a number to an integer representation with customizable thousand
|
|
46
|
+
* separators. Useful for displaying whole numbers in legal documents with
|
|
47
|
+
* proper formatting for readability.
|
|
48
|
+
*
|
|
49
|
+
* @param {number | string} value - The number to format
|
|
50
|
+
* @param {string} separator - The thousand separator character (default: ',')
|
|
51
|
+
* @returns {string} The formatted integer string
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Standard formatting
|
|
56
|
+
* formatInteger(1234567); // "1,234,567"
|
|
57
|
+
* formatInteger(1234567.89); // "1,234,567" (decimal part removed)
|
|
58
|
+
*
|
|
59
|
+
* // Custom separator
|
|
60
|
+
* formatInteger(1234567, '.'); // "1.234.567"
|
|
61
|
+
* formatInteger(1234567, ' '); // "1 234 567"
|
|
62
|
+
*
|
|
63
|
+
* // String input
|
|
64
|
+
* formatInteger('1234567'); // "1,234,567"
|
|
65
|
+
*
|
|
66
|
+
* // Invalid input handling
|
|
67
|
+
* formatInteger('not a number'); // "not a number"
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function formatInteger(value, separator = ',') {
|
|
71
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
72
|
+
if (isNaN(num))
|
|
73
|
+
return String(value);
|
|
74
|
+
return Math.floor(num)
|
|
75
|
+
.toString()
|
|
76
|
+
.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Formats a number as a percentage with customizable precision
|
|
80
|
+
*
|
|
81
|
+
* Converts a number to percentage format with configurable decimal places
|
|
82
|
+
* and optional percentage symbol. Useful for displaying rates, discounts,
|
|
83
|
+
* and other percentage values in legal documents.
|
|
84
|
+
*
|
|
85
|
+
* @param {number | string} value - The number to format as percentage
|
|
86
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
87
|
+
* @param {boolean} symbol - Whether to include the % symbol (default: true)
|
|
88
|
+
* @returns {string} The formatted percentage string
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Standard percentage formatting
|
|
93
|
+
* formatPercent(0.1556); // "15.56%"
|
|
94
|
+
* formatPercent(0.1556, 1); // "15.6%"
|
|
95
|
+
* formatPercent(0.1556, 0); // "16%"
|
|
96
|
+
*
|
|
97
|
+
* // Without percentage symbol
|
|
98
|
+
* formatPercent(0.1556, 2, false); // "15.56"
|
|
99
|
+
*
|
|
100
|
+
* // String input
|
|
101
|
+
* formatPercent('0.25'); // "25.00%"
|
|
102
|
+
*
|
|
103
|
+
* // Whole number input (treated as percentage)
|
|
104
|
+
* formatPercent(25); // "25.00%"
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
function formatPercent(value, decimals = 2, symbol = true) {
|
|
108
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
109
|
+
if (isNaN(num))
|
|
110
|
+
return String(value);
|
|
111
|
+
const formatted = num.toFixed(decimals);
|
|
112
|
+
return symbol ? `${formatted}%` : formatted;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Formats a number as currency with support for multiple currencies
|
|
116
|
+
*
|
|
117
|
+
* Converts a number to currency format with proper symbol placement,
|
|
118
|
+
* thousand separators, and decimal precision. Supports EUR, USD, and GBP
|
|
119
|
+
* with correct formatting conventions for each currency.
|
|
120
|
+
*
|
|
121
|
+
* @param {number | string} value - The number to format as currency
|
|
122
|
+
* @param {'EUR' | 'USD' | 'GBP'} currency - The currency type (default: 'EUR')
|
|
123
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
124
|
+
* @returns {string} The formatted currency string
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Euro formatting (symbol after amount)
|
|
129
|
+
* formatCurrency(1234.56, 'EUR'); // "1,234.56 €"
|
|
130
|
+
* formatCurrency(1234.56, 'EUR', 0); // "1,235 €"
|
|
131
|
+
*
|
|
132
|
+
* // US Dollar formatting (symbol before amount)
|
|
133
|
+
* formatCurrency(1234.56, 'USD'); // "$1,234.56"
|
|
134
|
+
*
|
|
135
|
+
* // British Pound formatting (symbol before amount)
|
|
136
|
+
* formatCurrency(1234.56, 'GBP'); // "£1,234.56"
|
|
137
|
+
*
|
|
138
|
+
* // String input
|
|
139
|
+
* formatCurrency('1234.56', 'USD'); // "$1,234.56"
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
function formatCurrency(value, currency = 'EUR', decimals = 2) {
|
|
143
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
144
|
+
if (isNaN(num))
|
|
145
|
+
return String(value);
|
|
146
|
+
const symbols = {
|
|
147
|
+
EUR: '€',
|
|
148
|
+
USD: '$',
|
|
149
|
+
GBP: '£',
|
|
150
|
+
};
|
|
151
|
+
const formatted = num.toFixed(decimals).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
152
|
+
const symbol = symbols[currency] || currency;
|
|
153
|
+
// Different positioning for different currencies
|
|
154
|
+
if (currency === 'EUR') {
|
|
155
|
+
return `${formatted} ${symbol}`;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return `${symbol}${formatted}`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Formats a number as Euro currency
|
|
163
|
+
*
|
|
164
|
+
* Convenience function for formatting numbers as Euro currency with
|
|
165
|
+
* proper Euro symbol placement and formatting conventions.
|
|
166
|
+
*
|
|
167
|
+
* @param {number | string} value - The number to format as Euro
|
|
168
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
169
|
+
* @returns {string} The formatted Euro currency string
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* formatEuro(1234.56); // "1,234.56 €"
|
|
174
|
+
* formatEuro(1234.56, 0); // "1,235 €"
|
|
175
|
+
* formatEuro('500'); // "500.00 €"
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
function formatEuro(value, decimals = 2) {
|
|
179
|
+
return formatCurrency(value, 'EUR', decimals);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Formats a number as US Dollar currency
|
|
183
|
+
*
|
|
184
|
+
* Convenience function for formatting numbers as US Dollar currency with
|
|
185
|
+
* proper dollar symbol placement and formatting conventions.
|
|
186
|
+
*
|
|
187
|
+
* @param {number | string} value - The number to format as US Dollar
|
|
188
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
189
|
+
* @returns {string} The formatted US Dollar currency string
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* formatDollar(1234.56); // "$1,234.56"
|
|
194
|
+
* formatDollar(1234.56, 0); // "$1,235"
|
|
195
|
+
* formatDollar('500'); // "$500.00"
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
function formatDollar(value, decimals = 2) {
|
|
199
|
+
return formatCurrency(value, 'USD', decimals);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Formats a number as British Pound currency
|
|
203
|
+
*
|
|
204
|
+
* Convenience function for formatting numbers as British Pound currency with
|
|
205
|
+
* proper pound symbol placement and formatting conventions.
|
|
206
|
+
*
|
|
207
|
+
* @param {number | string} value - The number to format as British Pound
|
|
208
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
209
|
+
* @returns {string} The formatted British Pound currency string
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* formatPound(1234.56); // "£1,234.56"
|
|
214
|
+
* formatPound(1234.56, 0); // "£1,235"
|
|
215
|
+
* formatPound('500'); // "£500.00"
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
function formatPound(value, decimals = 2) {
|
|
219
|
+
return formatCurrency(value, 'GBP', decimals);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Converts a number to its written word representation
|
|
223
|
+
*
|
|
224
|
+
* Transforms numeric values into their English word equivalents, which is
|
|
225
|
+
* particularly useful for legal documents where amounts are often written
|
|
226
|
+
* in both numeric and word form for clarity and legal precision.
|
|
227
|
+
*
|
|
228
|
+
* @param {number | string} num - The number to convert to words
|
|
229
|
+
* @returns {string} The number expressed in words
|
|
230
|
+
*
|
|
231
|
+
* Supported range: Supports numbers from 0 to 999,999,999 with decimal support
|
|
232
|
+
* Decimal handling: Decimal parts are expressed as "and X cents"
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Whole numbers
|
|
237
|
+
* numberToWords(0); // "zero"
|
|
238
|
+
* numberToWords(42); // "forty two"
|
|
239
|
+
* numberToWords(1500); // "one thousand five hundred"
|
|
240
|
+
* numberToWords(1000000); // "one million"
|
|
241
|
+
*
|
|
242
|
+
* // Decimal numbers
|
|
243
|
+
* numberToWords(123.45); // "one hundred twenty three and forty five cents"
|
|
244
|
+
* numberToWords(1000.50); // "one thousand and fifty cents"
|
|
245
|
+
*
|
|
246
|
+
* // String input
|
|
247
|
+
* numberToWords('456'); // "four hundred fifty six"
|
|
248
|
+
*
|
|
249
|
+
* // Negative numbers
|
|
250
|
+
* numberToWords(-100); // "negative one hundred"
|
|
251
|
+
*
|
|
252
|
+
* // Invalid input
|
|
253
|
+
* numberToWords('invalid'); // "invalid"
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
function numberToWords(num) {
|
|
257
|
+
const n = typeof num === 'string' ? parseFloat(num) : num;
|
|
258
|
+
if (isNaN(n))
|
|
259
|
+
return String(num);
|
|
260
|
+
if (n === 0)
|
|
261
|
+
return 'zero';
|
|
262
|
+
const ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
|
|
263
|
+
const tens = [
|
|
264
|
+
'',
|
|
265
|
+
'',
|
|
266
|
+
'twenty',
|
|
267
|
+
'thirty',
|
|
268
|
+
'forty',
|
|
269
|
+
'fifty',
|
|
270
|
+
'sixty',
|
|
271
|
+
'seventy',
|
|
272
|
+
'eighty',
|
|
273
|
+
'ninety',
|
|
274
|
+
];
|
|
275
|
+
const teens = [
|
|
276
|
+
'ten',
|
|
277
|
+
'eleven',
|
|
278
|
+
'twelve',
|
|
279
|
+
'thirteen',
|
|
280
|
+
'fourteen',
|
|
281
|
+
'fifteen',
|
|
282
|
+
'sixteen',
|
|
283
|
+
'seventeen',
|
|
284
|
+
'eighteen',
|
|
285
|
+
'nineteen',
|
|
286
|
+
];
|
|
287
|
+
const convertMillions = (num) => {
|
|
288
|
+
if (num >= 1000000) {
|
|
289
|
+
return (convertMillions(Math.floor(num / 1000000)) + ' million ' + convertThousands(num % 1000000));
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
return convertThousands(num);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const convertThousands = (num) => {
|
|
296
|
+
if (num >= 1000) {
|
|
297
|
+
return convertHundreds(Math.floor(num / 1000)) + ' thousand ' + convertHundreds(num % 1000);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return convertHundreds(num);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const convertHundreds = (num) => {
|
|
304
|
+
let str = '';
|
|
305
|
+
if (num > 99) {
|
|
306
|
+
str += ones[Math.floor(num / 100)] + ' hundred ';
|
|
307
|
+
num %= 100;
|
|
308
|
+
}
|
|
309
|
+
if (num > 19) {
|
|
310
|
+
str += tens[Math.floor(num / 10)] + ' ';
|
|
311
|
+
num %= 10;
|
|
312
|
+
}
|
|
313
|
+
else if (num > 9) {
|
|
314
|
+
str += teens[num - 10] + ' ';
|
|
315
|
+
return str.trim();
|
|
316
|
+
}
|
|
317
|
+
if (num > 0) {
|
|
318
|
+
str += ones[num] + ' ';
|
|
319
|
+
}
|
|
320
|
+
return str.trim();
|
|
321
|
+
};
|
|
322
|
+
if (n < 0) {
|
|
323
|
+
return 'negative ' + numberToWords(Math.abs(n));
|
|
324
|
+
}
|
|
325
|
+
const integerPart = Math.floor(n);
|
|
326
|
+
const decimalPart = Math.round((n - integerPart) * 100);
|
|
327
|
+
let result = convertMillions(integerPart);
|
|
328
|
+
if (decimalPart > 0) {
|
|
329
|
+
result += ' and ' + convertHundreds(decimalPart) + ' cents';
|
|
330
|
+
}
|
|
331
|
+
return result.trim();
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Formats a number with custom decimal and thousand separators
|
|
335
|
+
*
|
|
336
|
+
* Provides flexible number formatting with customizable separators for
|
|
337
|
+
* different locales and formatting requirements. Useful for international
|
|
338
|
+
* legal documents that require specific number formatting conventions.
|
|
339
|
+
*
|
|
340
|
+
* @param {number | string} value - The number to format
|
|
341
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
342
|
+
* @param {string} decimalSeparator - Character for decimal separation (default: '.')
|
|
343
|
+
* @param {string} thousandSeparator - Character for thousand separation (default: ',')
|
|
344
|
+
* @returns {string} The formatted number string
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* // Standard US formatting
|
|
349
|
+
* formatNumber(1234.56); // "1,234.56"
|
|
350
|
+
* formatNumber(1234.56, 3); // "1,234.560"
|
|
351
|
+
*
|
|
352
|
+
* // European formatting (comma as decimal separator)
|
|
353
|
+
* formatNumber(1234.56, 2, ',', ' '); // "1 234,56"
|
|
354
|
+
* formatNumber(1234.56, 2, ',', '.'); // "1.234,56"
|
|
355
|
+
*
|
|
356
|
+
* // Custom formatting
|
|
357
|
+
* formatNumber(1234.56, 1, ':', '|'); // "1|234:6"
|
|
358
|
+
*
|
|
359
|
+
* // String input
|
|
360
|
+
* formatNumber('1234.56'); // "1,234.56"
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
function formatNumber(value, decimals = 2, decimalSeparator = '.', thousandSeparator = ',') {
|
|
364
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
365
|
+
if (isNaN(num))
|
|
366
|
+
return String(value);
|
|
367
|
+
const parts = num.toFixed(decimals).split('.');
|
|
368
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
|
|
369
|
+
return parts.join(decimalSeparator);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Rounds a number to a specified number of decimal places
|
|
373
|
+
*
|
|
374
|
+
* Provides precise rounding functionality for numerical calculations in
|
|
375
|
+
* legal documents. Uses standard mathematical rounding rules (0.5 rounds up).
|
|
376
|
+
*
|
|
377
|
+
* @param {number | string} value - The number to round
|
|
378
|
+
* @param {number} decimals - Number of decimal places to round to (default: 0)
|
|
379
|
+
* @returns {number} The rounded number
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* // Round to whole numbers
|
|
384
|
+
* round(1234.56); // 1235
|
|
385
|
+
* round(1234.44); // 1234
|
|
386
|
+
*
|
|
387
|
+
* // Round to decimal places
|
|
388
|
+
* round(1234.5678, 2); // 1234.57
|
|
389
|
+
* round(1234.5678, 1); // 1234.6
|
|
390
|
+
* round(1234.5678, 3); // 1234.568
|
|
391
|
+
*
|
|
392
|
+
* // String input
|
|
393
|
+
* round('1234.56', 1); // 1234.6
|
|
394
|
+
*
|
|
395
|
+
* // Invalid input handling
|
|
396
|
+
* round('invalid'); // 0
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
function round(value, decimals = 0) {
|
|
400
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
401
|
+
if (isNaN(num))
|
|
402
|
+
return 0;
|
|
403
|
+
const factor = Math.pow(10, decimals);
|
|
404
|
+
return Math.round(num * factor) / factor;
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=number-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-helpers.js","sourceRoot":"","sources":["../../src/helpers/number-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;AA8BH,sCAOC;AA+BD,sCAUC;AA8BD,wCAuBC;AAmBD,gCAEC;AAmBD,oCAEC;AAmBD,kCAEC;AAqCD,sCAuFC;AAgCD,oCAaC;AA8BD,sBAMC;AA7YD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,aAAa,CAAC,KAAsB,EAAE,YAAoB,GAAG;IAC3E,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,IAAI,KAAK,CAAC,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAErC,OAAO,IAAI,CA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