react-smart-copy 1.21.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.
- package/README.md +67 -0
- package/dist/chunks/digits-BUEvSVrs.cjs +51 -0
- package/dist/chunks/digits-BUEvSVrs.cjs.map +1 -0
- package/dist/chunks/digits-DkU-O9_A.js +46 -0
- package/dist/chunks/digits-DkU-O9_A.js.map +1 -0
- package/dist/chunks/field-BHo5y-t_.js +535 -0
- package/dist/chunks/field-BHo5y-t_.js.map +1 -0
- package/dist/chunks/field-BTsKTs2M.d.cts +87 -0
- package/dist/chunks/field-BTsKTs2M.d.ts +87 -0
- package/dist/chunks/field-Bytz2WfN.cjs +558 -0
- package/dist/chunks/field-Bytz2WfN.cjs.map +1 -0
- package/dist/chunks/{text-field-Ba8W3v4R.cjs → text-field-BEzUVOag.cjs} +26 -5
- package/dist/chunks/text-field-BEzUVOag.cjs.map +1 -0
- package/dist/chunks/{text-field-DUvrMMaK.js → text-field-D7PF2WlX.js} +21 -6
- package/dist/chunks/text-field-D7PF2WlX.js.map +1 -0
- package/dist/code.cjs +1 -1
- package/dist/code.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/index.cjs +89 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +89 -1
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +1 -1
- package/dist/link.js +1 -1
- package/dist/markdown.cjs +1 -1
- package/dist/markdown.js +1 -1
- package/dist/number.cjs +442 -0
- package/dist/number.cjs.map +1 -0
- package/dist/number.d.cts +172 -0
- package/dist/number.d.ts +172 -0
- package/dist/number.js +436 -0
- package/dist/number.js.map +1 -0
- package/dist/otp.cjs +7 -0
- package/dist/otp.d.cts +54 -0
- package/dist/otp.d.ts +54 -0
- package/dist/otp.js +2 -0
- package/dist/secrets.cjs +1 -1
- package/dist/secrets.js +1 -1
- package/package.json +71 -3
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +0 -1
- package/dist/chunks/text-field-DUvrMMaK.js.map +0 -1
package/README.md
CHANGED
|
@@ -34,6 +34,8 @@ ID PLT-29018 [Copy]
|
|
|
34
34
|
- **`react-smart-copy/image`**: get pasted photos and screenshots ready to upload. It removes GPS location, camera data and hidden thumbnails without touching a pixel, and fits size and byte limits, re-encoding only when it has to
|
|
35
35
|
- **`react-smart-copy/files`**: take pasted and dropped files and whole folders safely. Types come from each file's content, so a program named `invoice.pdf.exe` or a web page named `report.pdf` is turned away with a reason, names are made safe for every operating system, and limits cap count, size and depth
|
|
36
36
|
- **`react-smart-copy/secrets`**: keep API keys, tokens, private keys, passwords, card numbers and IBANs out of pastes and copies. Paste guards for chat boxes and forms, and redaction of what people copy from logs and consoles. Every pattern runs in linear time, and no finding holds the secret
|
|
37
|
+
- **`react-smart-copy/otp`** and **`useOtpField`**: one-time code fields that typing, pasting a whole SMS, SMS autofill and WebOTP fill, with an accessible name on every box, and `extractOtp` to read the code in a message while leaving prices, dates, phone numbers and order numbers alone
|
|
38
|
+
- **`react-smart-copy/number`**: read the numbers and amounts people paste, in any locale's format (`1.234,50 €`, `$1,234.50`, `(1,234.00)`, lakh grouping, any script's digits), exactly, as a decimal string as well as a `number`. Paste them into number fields with `pasteAsNumber`, and write them back for any locale with `formatNumber`
|
|
37
39
|
- **`react-smart-copy/link`**: "Copy link" buttons that paste as a titled link in Slack, Docs and Notion and as the URL in editors, links that scroll to a highlighted passage, tracking parameters removed, and pasting a URL over selected text to make a link
|
|
38
40
|
- **`react-smart-copy/rich`**: copy styled content so it pastes as it looks in Gmail, Outlook, Apple Mail, Google Docs, Word, Notion and Slack: sanitized HTML with inline styles, email-safe colours and absolute links, plus readable plain text. Works for buttons and for Ctrl/⌘+C. And the other way: paste from Docs, Word and mail into a rich-text editor (TipTap, Lexical, `contenteditable`) as clean, semantic HTML
|
|
39
41
|
- **`react-smart-copy/color`**: copy colours in any CSS format (hex to `oklch()` and Display P3) with a swatch for Docs and Slack, paste any format into a colour field, and check WCAG contrast. Wide-gamut colours are mapped the way CSS specifies, never clipped to a wrong hue
|
|
@@ -1019,6 +1021,69 @@ paste with secrets is blocked. Scanning in the browser protects the people using
|
|
|
1019
1021
|
Scan again on your server before you store or forward text, because `scanSecrets` works the
|
|
1020
1022
|
same there.
|
|
1021
1023
|
|
|
1024
|
+
## One-time codes
|
|
1025
|
+
|
|
1026
|
+
`react-smart-copy/otp` handles the one-time codes people copy from an SMS or an e-mail.
|
|
1027
|
+
`extractOtp` finds the code in a message, and leaves prices, dates, times, phone numbers and
|
|
1028
|
+
order numbers alone. `useOtpField` (in the React entry) wires a row of single-character
|
|
1029
|
+
boxes: typing moves on, Backspace goes back, and pasting a whole message into any box fills
|
|
1030
|
+
them all. No dependencies, about 3.6 kB (about 2 kB for `extractOtp` alone).
|
|
1031
|
+
|
|
1032
|
+
```tsx
|
|
1033
|
+
import { useOtpField } from "react-smart-copy";
|
|
1034
|
+
|
|
1035
|
+
const otp = useOtpField({ length: 6, onComplete: verify });
|
|
1036
|
+
|
|
1037
|
+
<div role="group" aria-label="Verification code">
|
|
1038
|
+
{Array.from({ length: 6 }, (_, index) => (
|
|
1039
|
+
<input key={index} {...otp.getInputProps(index)} />
|
|
1040
|
+
))}
|
|
1041
|
+
</div>
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
- **SMS autofill** on iOS and Android (`autocomplete="one-time-code"` on the first box), and
|
|
1045
|
+
the **WebOTP API** with `webOtp: true`, cancelled when the boxes unmount or the code is typed.
|
|
1046
|
+
- **Every box is named** (`Digit 1 of 6`), numeric codes get the numeric keyboard, and the
|
|
1047
|
+
arrow keys, Home, End, Backspace and Delete work as people expect.
|
|
1048
|
+
- **`extractOtp`** reads codes on their own (`482 913`), origin-bound lines
|
|
1049
|
+
(`@example.com #482913`, refused for another `domain`), and numbers next to a word that
|
|
1050
|
+
names them in twenty languages, with digits of any script. Linear time, first 100,000
|
|
1051
|
+
characters.
|
|
1052
|
+
|
|
1053
|
+
```ts
|
|
1054
|
+
import { extractOtp } from "react-smart-copy/otp";
|
|
1055
|
+
|
|
1056
|
+
extractOtp("Your verification code is 482913. It expires in 10 minutes.");
|
|
1057
|
+
// { code: "482913", source: "keyword", confidence: "high", domain: null }
|
|
1058
|
+
extractOtp("Your order 48291 of $1,249.00 ships on 24/10."); // null
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
## Numbers and amounts
|
|
1062
|
+
|
|
1063
|
+
`react-smart-copy/number` reads the numbers people paste: `1.234,50 €` from a bank statement,
|
|
1064
|
+
`$1,234.50` from an invoice, `(1,234.00)` from a spreadsheet, `₹ 12,34,567` in lakh grouping.
|
|
1065
|
+
It gives the number exactly, as a decimal string as well as a `number`, and turns away dates,
|
|
1066
|
+
phone numbers and wrongly grouped text. No dependencies, about 3.5 kB.
|
|
1067
|
+
|
|
1068
|
+
```tsx
|
|
1069
|
+
import { parseNumber, pasteAsNumber } from "react-smart-copy/number";
|
|
1070
|
+
|
|
1071
|
+
parseNumber("1.234,50 €");
|
|
1072
|
+
// { value: 1234.5, exact: "1234.50", kind: "number", currency: { symbol: "€", code: "EUR" }, ambiguous: false }
|
|
1073
|
+
|
|
1074
|
+
<input type="number" step="any" onPaste={(event) => pasteAsNumber(event, { locale: "de-DE" })} />
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
- **Every grouping and decimal style:** `,` `.` `'` and spaces, groups of three and lakh
|
|
1078
|
+
grouping. Text that can be read only one way is read that way everywhere; a lone `1,234` is
|
|
1079
|
+
settled by `locale`, and flagged `ambiguous`.
|
|
1080
|
+
- **Signs, currencies and percent:** `−`, trailing minus, accounting brackets, symbols and ISO
|
|
1081
|
+
codes before or after, `%` and `‰`, scientific notation.
|
|
1082
|
+
- **`pasteAsNumber`** puts `exact` in `<input type="number">` and the locale's format in text
|
|
1083
|
+
fields, with undo intact, and turns away pastes that are not numbers.
|
|
1084
|
+
- **`formatNumber` and `numberPayload`** write a number, bigint or exact string for any locale,
|
|
1085
|
+
grouped or not, rounded to `fractionDigits` without float error.
|
|
1086
|
+
|
|
1022
1087
|
## Copy links
|
|
1023
1088
|
|
|
1024
1089
|
`react-smart-copy/link` is for "Copy link" and "Share" buttons, and for fields people
|
|
@@ -1838,6 +1903,8 @@ embedded webviews. Where a capability is missing you get a typed error, never a
|
|
|
1838
1903
|
- ~~**1.19** `react-smart-copy/rich`, paste side: paste from Word, Google Docs and web pages into rich-text editors as clean, safe HTML~~ shipped
|
|
1839
1904
|
- ~~**1.20** `react-smart-copy/files` — take pasted and dropped files and folders safely: types from content, risky files rejected, safe names, limits~~ shipped
|
|
1840
1905
|
- ~~**1.21** `react-smart-copy/secrets` — find and redact API keys, tokens, private keys, passwords, cards and IBANs in pastes and copies~~ shipped
|
|
1906
|
+
- ~~**1.22** `react-smart-copy/otp` and `useOtpField` — one-time code fields filled by typing, pasting, SMS autofill and WebOTP, and codes read from pasted messages~~ shipped
|
|
1907
|
+
- ~~**1.23** `react-smart-copy/number` — numbers and amounts pasted and copied exactly in any locale's format, with currencies, percent and accounting negatives~~ shipped
|
|
1841
1908
|
|
|
1842
1909
|
Full history: [CHANGELOG.md](./CHANGELOG.md) or the [Releases page](https://suprabhat02.github.io/react-smart-copy/project/releases/).
|
|
1843
1910
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/digits.ts
|
|
3
|
+
/**
|
|
4
|
+
* Digits of other scripts as ASCII, shared by the opt-in entry points that read numbers.
|
|
5
|
+
* Internal: not part of `react-smart-copy/core`'s public API.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Code points of zero in the decimal digit sets people write numbers in: Arabic-Indic,
|
|
9
|
+
* Persian, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,
|
|
10
|
+
* Malayalam, Thai, Lao, Tibetan, Myanmar and Khmer. Full-width digits are handled by NFKC.
|
|
11
|
+
*/
|
|
12
|
+
const ZEROS = [
|
|
13
|
+
1632,
|
|
14
|
+
1776,
|
|
15
|
+
2406,
|
|
16
|
+
2534,
|
|
17
|
+
2662,
|
|
18
|
+
2790,
|
|
19
|
+
2918,
|
|
20
|
+
3046,
|
|
21
|
+
3174,
|
|
22
|
+
3302,
|
|
23
|
+
3430,
|
|
24
|
+
3664,
|
|
25
|
+
3792,
|
|
26
|
+
3872,
|
|
27
|
+
4160,
|
|
28
|
+
6112
|
|
29
|
+
];
|
|
30
|
+
/** `char` as an ASCII digit, when it is a digit of one of {@link ZEROS}' sets. */
|
|
31
|
+
function asciiDigit(char) {
|
|
32
|
+
const code = char.charCodeAt(0);
|
|
33
|
+
for (const zero of ZEROS) if (code >= zero && code <= zero + 9) return String(code - zero);
|
|
34
|
+
return char;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `text` in NFKC (full-width digits, letters and signs as ASCII, no-break spaces as spaces)
|
|
38
|
+
* with the digits of other scripts as ASCII. Other characters are kept.
|
|
39
|
+
*/
|
|
40
|
+
function asciiDigits(text) {
|
|
41
|
+
return text.normalize("NFKC").replace(/[\u0080-\uffff]/g, asciiDigit);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
Object.defineProperty(exports, "asciiDigits", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function() {
|
|
47
|
+
return asciiDigits;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=digits-BUEvSVrs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digits-BUEvSVrs.cjs","names":[],"sources":["../../src/core/digits.ts"],"sourcesContent":["/**\n * Digits of other scripts as ASCII, shared by the opt-in entry points that read numbers.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/**\n * Code points of zero in the decimal digit sets people write numbers in: Arabic-Indic,\n * Persian, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,\n * Malayalam, Thai, Lao, Tibetan, Myanmar and Khmer. Full-width digits are handled by NFKC.\n */\nconst ZEROS: readonly number[] = [\n 0x0660, 0x06f0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0be6, 0x0c66, 0x0ce6, 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0,\n];\n\n/** `char` as an ASCII digit, when it is a digit of one of {@link ZEROS}' sets. */\nfunction asciiDigit(char: string): string {\n const code = char.charCodeAt(0);\n for (const zero of ZEROS) {\n if (code >= zero && code <= zero + 9) return String(code - zero);\n }\n return char;\n}\n\n/**\n * `text` in NFKC (full-width digits, letters and signs as ASCII, no-break spaces as spaces)\n * with the digits of other scripts as ASCII. Other characters are kept.\n */\nexport function asciiDigits(text: string): string {\n return text.normalize('NFKC').replace(/[\\u0080-\\uffff]/g, asciiDigit);\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,QAA2B;CAC/B;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAC1H;;AAGA,SAAS,WAAW,MAAsB;CACxC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,KAAK,MAAM,QAAQ,OACjB,IAAI,QAAQ,QAAQ,QAAQ,OAAO,GAAG,OAAO,OAAO,OAAO,IAAI;CAEjE,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,QAAQ,oBAAoB,UAAU;AACtE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/digits.ts
|
|
3
|
+
/**
|
|
4
|
+
* Digits of other scripts as ASCII, shared by the opt-in entry points that read numbers.
|
|
5
|
+
* Internal: not part of `react-smart-copy/core`'s public API.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Code points of zero in the decimal digit sets people write numbers in: Arabic-Indic,
|
|
9
|
+
* Persian, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,
|
|
10
|
+
* Malayalam, Thai, Lao, Tibetan, Myanmar and Khmer. Full-width digits are handled by NFKC.
|
|
11
|
+
*/
|
|
12
|
+
const ZEROS = [
|
|
13
|
+
1632,
|
|
14
|
+
1776,
|
|
15
|
+
2406,
|
|
16
|
+
2534,
|
|
17
|
+
2662,
|
|
18
|
+
2790,
|
|
19
|
+
2918,
|
|
20
|
+
3046,
|
|
21
|
+
3174,
|
|
22
|
+
3302,
|
|
23
|
+
3430,
|
|
24
|
+
3664,
|
|
25
|
+
3792,
|
|
26
|
+
3872,
|
|
27
|
+
4160,
|
|
28
|
+
6112
|
|
29
|
+
];
|
|
30
|
+
/** `char` as an ASCII digit, when it is a digit of one of {@link ZEROS}' sets. */
|
|
31
|
+
function asciiDigit(char) {
|
|
32
|
+
const code = char.charCodeAt(0);
|
|
33
|
+
for (const zero of ZEROS) if (code >= zero && code <= zero + 9) return String(code - zero);
|
|
34
|
+
return char;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `text` in NFKC (full-width digits, letters and signs as ASCII, no-break spaces as spaces)
|
|
38
|
+
* with the digits of other scripts as ASCII. Other characters are kept.
|
|
39
|
+
*/
|
|
40
|
+
function asciiDigits(text) {
|
|
41
|
+
return text.normalize("NFKC").replace(/[\u0080-\uffff]/g, asciiDigit);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { asciiDigits as t };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=digits-DkU-O9_A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digits-DkU-O9_A.js","names":[],"sources":["../../src/core/digits.ts"],"sourcesContent":["/**\n * Digits of other scripts as ASCII, shared by the opt-in entry points that read numbers.\n * Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/**\n * Code points of zero in the decimal digit sets people write numbers in: Arabic-Indic,\n * Persian, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,\n * Malayalam, Thai, Lao, Tibetan, Myanmar and Khmer. Full-width digits are handled by NFKC.\n */\nconst ZEROS: readonly number[] = [\n 0x0660, 0x06f0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0be6, 0x0c66, 0x0ce6, 0x0d66, 0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0,\n];\n\n/** `char` as an ASCII digit, when it is a digit of one of {@link ZEROS}' sets. */\nfunction asciiDigit(char: string): string {\n const code = char.charCodeAt(0);\n for (const zero of ZEROS) {\n if (code >= zero && code <= zero + 9) return String(code - zero);\n }\n return char;\n}\n\n/**\n * `text` in NFKC (full-width digits, letters and signs as ASCII, no-break spaces as spaces)\n * with the digits of other scripts as ASCII. Other characters are kept.\n */\nexport function asciiDigits(text: string): string {\n return text.normalize('NFKC').replace(/[\\u0080-\\uffff]/g, asciiDigit);\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,QAA2B;CAC/B;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;AAC1H;;AAGA,SAAS,WAAW,MAAsB;CACxC,MAAM,OAAO,KAAK,WAAW,CAAC;CAC9B,KAAK,MAAM,QAAQ,OACjB,IAAI,QAAQ,QAAQ,QAAQ,OAAO,GAAG,OAAO,OAAO,OAAO,IAAI;CAEjE,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,QAAQ,oBAAoB,UAAU;AACtE"}
|