react-smart-copy 1.22.0 → 1.23.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.
Files changed (38) hide show
  1. package/README.md +28 -0
  2. package/dist/chunks/digits-BUEvSVrs.cjs +51 -0
  3. package/dist/chunks/digits-BUEvSVrs.cjs.map +1 -0
  4. package/dist/chunks/digits-DkU-O9_A.js +46 -0
  5. package/dist/chunks/digits-DkU-O9_A.js.map +1 -0
  6. package/dist/chunks/{field-Cdq2LxEO.js → field-BHo5y-t_.js} +3 -31
  7. package/dist/chunks/field-BHo5y-t_.js.map +1 -0
  8. package/dist/chunks/{field-NaDdWy_5.cjs → field-Bytz2WfN.cjs} +3 -31
  9. package/dist/chunks/field-Bytz2WfN.cjs.map +1 -0
  10. package/dist/chunks/{text-field-Ba8W3v4R.cjs → text-field-BEzUVOag.cjs} +26 -5
  11. package/dist/chunks/text-field-BEzUVOag.cjs.map +1 -0
  12. package/dist/chunks/{text-field-DUvrMMaK.js → text-field-D7PF2WlX.js} +21 -6
  13. package/dist/chunks/text-field-D7PF2WlX.js.map +1 -0
  14. package/dist/code.cjs +1 -1
  15. package/dist/code.js +1 -1
  16. package/dist/color.cjs +1 -1
  17. package/dist/color.js +1 -1
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/link.cjs +1 -1
  21. package/dist/link.js +1 -1
  22. package/dist/markdown.cjs +1 -1
  23. package/dist/markdown.js +1 -1
  24. package/dist/number.cjs +442 -0
  25. package/dist/number.cjs.map +1 -0
  26. package/dist/number.d.cts +172 -0
  27. package/dist/number.d.ts +172 -0
  28. package/dist/number.js +436 -0
  29. package/dist/number.js.map +1 -0
  30. package/dist/otp.cjs +1 -1
  31. package/dist/otp.js +1 -1
  32. package/dist/secrets.cjs +1 -1
  33. package/dist/secrets.js +1 -1
  34. package/package.json +37 -3
  35. package/dist/chunks/field-Cdq2LxEO.js.map +0 -1
  36. package/dist/chunks/field-NaDdWy_5.cjs.map +0 -1
  37. package/dist/chunks/text-field-Ba8W3v4R.cjs.map +0 -1
  38. package/dist/chunks/text-field-DUvrMMaK.js.map +0 -1
@@ -0,0 +1,172 @@
1
+
2
+ import { f as TextPayload } from "./chunks/payload-CcwKJ_bU.cjs";
3
+ //#region src/number/currency.d.ts
4
+ /** A currency written next to a number. */
5
+ interface NumberCurrency {
6
+ /** As it was written, normalized: `\u20AC`, `R$`, `kr`, `USD`. */
7
+ readonly symbol: string;
8
+ /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\u00A5`, `kr` and `Rs`. */
9
+ readonly code: string | null;
10
+ }
11
+ //#endregion
12
+ //#region src/number/parse.d.ts
13
+ /** What a number was written as: `12` is a number, `12%` a percentage, `12\u2030` per mille. */
14
+ type NumberKind = 'number' | 'percent' | 'permille';
15
+ /** A number read from text. */
16
+ interface ParsedNumber {
17
+ /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \u20AC)`. */
18
+ readonly value: number;
19
+ /**
20
+ * The same number as an exact decimal string, without rounding: `-1234.50` keeps its
21
+ * trailing zero, and `0.1` is not `0.1000000000000000055\u2026`. Use it for money.
22
+ */
23
+ readonly exact: string;
24
+ /** `'percent'` or `'permille'` when the number was written with `%` or `\u2030`. */
25
+ readonly kind: NumberKind;
26
+ /** The currency written with it, if any. */
27
+ readonly currency: NumberCurrency | null;
28
+ /**
29
+ * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group
30
+ * separator in some locales and a decimal separator in others. `locale` decided which;
31
+ * ask the person when it matters.
32
+ */
33
+ readonly ambiguous: boolean;
34
+ }
35
+ interface ParseNumberOptions {
36
+ /**
37
+ * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping
38
+ * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way
39
+ * is read that way in every locale: `1.234,5` is 1234.5 everywhere.
40
+ */
41
+ readonly locale?: string;
42
+ /** Accept negative numbers. Default `true`. */
43
+ readonly negative?: boolean;
44
+ /** Accept numbers with a fractional part. Default `true`. */
45
+ readonly fraction?: boolean;
46
+ /** Accept a currency symbol or code. Default `true`. */
47
+ readonly currency?: boolean;
48
+ /** Accept `%` and `\u2030`. Default `true`. */
49
+ readonly percent?: boolean;
50
+ }
51
+ /** Longer text holds more than a number: it is not read at all. */
52
+ export declare const NUMBER_MAX_LENGTH = 256;
53
+ /**
54
+ * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice
55
+ * or a web page, in any locale's format. The whole text must be one number, with at most a
56
+ * sign, a currency and a percent sign around it; anything else gives `null`.
57
+ *
58
+ * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of
59
+ * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.
60
+ * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,
61
+ * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.
62
+ * - `-`, `+`, `\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).
63
+ * - Currency symbols and ISO codes, before or after: `$`, `\u20AC`, `R$`, `kr`, `USD`, `CHF`.
64
+ * - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
65
+ * - Digits of any script, full-width characters, and Arabic separators.
66
+ *
67
+ * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one.
68
+ * @example
69
+ * parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
70
+ * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
71
+ */
72
+ export declare function parseNumber(text: string, options?: ParseNumberOptions): ParsedNumber | null;
73
+ //#endregion
74
+ //#region src/number/format.d.ts
75
+ interface FormatNumberOptions {
76
+ /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */
77
+ readonly locale?: string;
78
+ /**
79
+ * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets
80
+ * read ungrouped numbers in every locale, and grouped ones only in their own.
81
+ */
82
+ readonly grouping?: boolean;
83
+ /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */
84
+ readonly fractionDigits?: number;
85
+ }
86
+ /**
87
+ * Writes a number in a locale's format, exactly: no float rounding, whatever its size.
88
+ * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so
89
+ * money read from one locale can be written in another without losing a cent.
90
+ *
91
+ * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is
92
+ * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.
93
+ * @example
94
+ * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // "1.234,50"
95
+ */
96
+ export declare function formatNumber(value: number | string | bigint, options?: FormatNumberOptions): string;
97
+ /**
98
+ * A copy payload for a number, written for the locale it will be pasted in: ungrouped by
99
+ * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.
100
+ *
101
+ * @example
102
+ * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));
103
+ */
104
+ export declare function numberPayload(value: number | string | bigint, options?: FormatNumberOptions): TextPayload;
105
+ //#endregion
106
+ //#region src/number/paste.d.ts
107
+ /** What {@link pasteAsNumber} did. */
108
+ type NumberPasteOutcome =
109
+ /** The paste held a number: it was inserted, written the way the field takes it. */
110
+ 'pasted' |
111
+ /** The paste was not a number (or the field is read-only): nothing was inserted. */
112
+ 'rejected' |
113
+ /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */
114
+ 'ignored';
115
+ interface PasteAsNumberOptions extends ParseNumberOptions {
116
+ /**
117
+ * How to write the number into the field. Default: `exact` for `<input type="number">`,
118
+ * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,
119
+ * ungrouped (`1234,5` in `de-DE`).
120
+ */
121
+ readonly format?: (parsed: ParsedNumber) => string;
122
+ /** Called with the number before it is inserted: show `ambiguous` readings here. */
123
+ readonly onNumber?: (parsed: ParsedNumber) => void;
124
+ /** Called with the pasted text when it was not a number, or the field takes no input. */
125
+ readonly onReject?: (text: string) => void;
126
+ }
127
+ /** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */
128
+ interface NumberPasteEvent {
129
+ readonly clipboardData: {
130
+ getData(format: string): string;
131
+ } | null;
132
+ readonly currentTarget: EventTarget | null;
133
+ readonly target: EventTarget | null;
134
+ readonly defaultPrevented: boolean;
135
+ preventDefault(): void;
136
+ }
137
+ /**
138
+ * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank
139
+ * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either
140
+ * rejects these from `<input type="number">` or keeps the text as it is. This reads the
141
+ * number, inserts it the way the field takes it (with undo intact in text fields), and
142
+ * turns away pastes that are not a number.
143
+ *
144
+ * Works on `<input type="number">`, text `<input>`s (use `inputmode="decimal"`) and
145
+ * `<textarea>`s; other elements are left to the browser.
146
+ *
147
+ * @example
148
+ * <input inputMode="decimal" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />
149
+ */
150
+ export declare function pasteAsNumber(event: NumberPasteEvent, options?: PasteAsNumberOptions): NumberPasteOutcome;
151
+ //#endregion
152
+ //#region src/number/locale.d.ts
153
+ /** How a locale writes numbers, in Latin digits. */
154
+ interface NumberSymbols {
155
+ /** The decimal separator. */
156
+ readonly decimal: '.' | ',';
157
+ /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */
158
+ readonly group: string;
159
+ /** Digits in the last group of the integer part: 3 almost everywhere. */
160
+ readonly primary: number;
161
+ /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */
162
+ readonly secondary: number;
163
+ }
164
+ /**
165
+ * How `locale` writes numbers, from `Intl.NumberFormat`.
166
+ *
167
+ * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.
168
+ */
169
+ export declare function numberSymbols(locale: string): NumberSymbols;
170
+ //#endregion
171
+ export type { FormatNumberOptions, NumberCurrency, NumberKind, NumberPasteEvent, NumberPasteOutcome, NumberSymbols, ParseNumberOptions, ParsedNumber, PasteAsNumberOptions };
172
+ //# sourceMappingURL=number.d.cts.map
@@ -0,0 +1,172 @@
1
+
2
+ import { f as TextPayload } from "./chunks/payload-Cl_8hCI5.js";
3
+ //#region src/number/currency.d.ts
4
+ /** A currency written next to a number. */
5
+ interface NumberCurrency {
6
+ /** As it was written, normalized: `\u20AC`, `R$`, `kr`, `USD`. */
7
+ readonly symbol: string;
8
+ /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\u00A5`, `kr` and `Rs`. */
9
+ readonly code: string | null;
10
+ }
11
+ //#endregion
12
+ //#region src/number/parse.d.ts
13
+ /** What a number was written as: `12` is a number, `12%` a percentage, `12\u2030` per mille. */
14
+ type NumberKind = 'number' | 'percent' | 'permille';
15
+ /** A number read from text. */
16
+ interface ParsedNumber {
17
+ /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \u20AC)`. */
18
+ readonly value: number;
19
+ /**
20
+ * The same number as an exact decimal string, without rounding: `-1234.50` keeps its
21
+ * trailing zero, and `0.1` is not `0.1000000000000000055\u2026`. Use it for money.
22
+ */
23
+ readonly exact: string;
24
+ /** `'percent'` or `'permille'` when the number was written with `%` or `\u2030`. */
25
+ readonly kind: NumberKind;
26
+ /** The currency written with it, if any. */
27
+ readonly currency: NumberCurrency | null;
28
+ /**
29
+ * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group
30
+ * separator in some locales and a decimal separator in others. `locale` decided which;
31
+ * ask the person when it matters.
32
+ */
33
+ readonly ambiguous: boolean;
34
+ }
35
+ interface ParseNumberOptions {
36
+ /**
37
+ * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping
38
+ * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way
39
+ * is read that way in every locale: `1.234,5` is 1234.5 everywhere.
40
+ */
41
+ readonly locale?: string;
42
+ /** Accept negative numbers. Default `true`. */
43
+ readonly negative?: boolean;
44
+ /** Accept numbers with a fractional part. Default `true`. */
45
+ readonly fraction?: boolean;
46
+ /** Accept a currency symbol or code. Default `true`. */
47
+ readonly currency?: boolean;
48
+ /** Accept `%` and `\u2030`. Default `true`. */
49
+ readonly percent?: boolean;
50
+ }
51
+ /** Longer text holds more than a number: it is not read at all. */
52
+ export declare const NUMBER_MAX_LENGTH = 256;
53
+ /**
54
+ * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice
55
+ * or a web page, in any locale's format. The whole text must be one number, with at most a
56
+ * sign, a currency and a percent sign around it; anything else gives `null`.
57
+ *
58
+ * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of
59
+ * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.
60
+ * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,
61
+ * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.
62
+ * - `-`, `+`, `\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).
63
+ * - Currency symbols and ISO codes, before or after: `$`, `\u20AC`, `R$`, `kr`, `USD`, `CHF`.
64
+ * - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
65
+ * - Digits of any script, full-width characters, and Arabic separators.
66
+ *
67
+ * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one.
68
+ * @example
69
+ * parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
70
+ * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
71
+ */
72
+ export declare function parseNumber(text: string, options?: ParseNumberOptions): ParsedNumber | null;
73
+ //#endregion
74
+ //#region src/number/format.d.ts
75
+ interface FormatNumberOptions {
76
+ /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */
77
+ readonly locale?: string;
78
+ /**
79
+ * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets
80
+ * read ungrouped numbers in every locale, and grouped ones only in their own.
81
+ */
82
+ readonly grouping?: boolean;
83
+ /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */
84
+ readonly fractionDigits?: number;
85
+ }
86
+ /**
87
+ * Writes a number in a locale's format, exactly: no float rounding, whatever its size.
88
+ * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so
89
+ * money read from one locale can be written in another without losing a cent.
90
+ *
91
+ * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is
92
+ * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.
93
+ * @example
94
+ * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // "1.234,50"
95
+ */
96
+ export declare function formatNumber(value: number | string | bigint, options?: FormatNumberOptions): string;
97
+ /**
98
+ * A copy payload for a number, written for the locale it will be pasted in: ungrouped by
99
+ * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.
100
+ *
101
+ * @example
102
+ * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));
103
+ */
104
+ export declare function numberPayload(value: number | string | bigint, options?: FormatNumberOptions): TextPayload;
105
+ //#endregion
106
+ //#region src/number/paste.d.ts
107
+ /** What {@link pasteAsNumber} did. */
108
+ type NumberPasteOutcome =
109
+ /** The paste held a number: it was inserted, written the way the field takes it. */
110
+ 'pasted' |
111
+ /** The paste was not a number (or the field is read-only): nothing was inserted. */
112
+ 'rejected' |
113
+ /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */
114
+ 'ignored';
115
+ interface PasteAsNumberOptions extends ParseNumberOptions {
116
+ /**
117
+ * How to write the number into the field. Default: `exact` for `<input type="number">`,
118
+ * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,
119
+ * ungrouped (`1234,5` in `de-DE`).
120
+ */
121
+ readonly format?: (parsed: ParsedNumber) => string;
122
+ /** Called with the number before it is inserted: show `ambiguous` readings here. */
123
+ readonly onNumber?: (parsed: ParsedNumber) => void;
124
+ /** Called with the pasted text when it was not a number, or the field takes no input. */
125
+ readonly onReject?: (text: string) => void;
126
+ }
127
+ /** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */
128
+ interface NumberPasteEvent {
129
+ readonly clipboardData: {
130
+ getData(format: string): string;
131
+ } | null;
132
+ readonly currentTarget: EventTarget | null;
133
+ readonly target: EventTarget | null;
134
+ readonly defaultPrevented: boolean;
135
+ preventDefault(): void;
136
+ }
137
+ /**
138
+ * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank
139
+ * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either
140
+ * rejects these from `<input type="number">` or keeps the text as it is. This reads the
141
+ * number, inserts it the way the field takes it (with undo intact in text fields), and
142
+ * turns away pastes that are not a number.
143
+ *
144
+ * Works on `<input type="number">`, text `<input>`s (use `inputmode="decimal"`) and
145
+ * `<textarea>`s; other elements are left to the browser.
146
+ *
147
+ * @example
148
+ * <input inputMode="decimal" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />
149
+ */
150
+ export declare function pasteAsNumber(event: NumberPasteEvent, options?: PasteAsNumberOptions): NumberPasteOutcome;
151
+ //#endregion
152
+ //#region src/number/locale.d.ts
153
+ /** How a locale writes numbers, in Latin digits. */
154
+ interface NumberSymbols {
155
+ /** The decimal separator. */
156
+ readonly decimal: '.' | ',';
157
+ /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */
158
+ readonly group: string;
159
+ /** Digits in the last group of the integer part: 3 almost everywhere. */
160
+ readonly primary: number;
161
+ /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */
162
+ readonly secondary: number;
163
+ }
164
+ /**
165
+ * How `locale` writes numbers, from `Intl.NumberFormat`.
166
+ *
167
+ * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.
168
+ */
169
+ export declare function numberSymbols(locale: string): NumberSymbols;
170
+ //#endregion
171
+ export type { FormatNumberOptions, NumberCurrency, NumberKind, NumberPasteEvent, NumberPasteOutcome, NumberSymbols, ParseNumberOptions, ParsedNumber, PasteAsNumberOptions };
172
+ //# sourceMappingURL=number.d.ts.map