react-smart-copy 1.24.0 → 1.25.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 +132 -1834
- package/dist/capture.cjs +3 -3
- package/dist/capture.d.cts +1 -1
- package/dist/capture.d.ts +1 -1
- package/dist/capture.js +3 -3
- package/dist/chunks/{clipboard-adapter-CtH4VELE.d.cts → clipboard-adapter-CfaIbZpv.d.cts} +2 -2
- package/dist/chunks/{clipboard-adapter-Ds0irroN.d.ts → clipboard-adapter-Chm6zq60.d.ts} +2 -2
- package/dist/chunks/{clipboard-adapter-DEXkXxwV.js → clipboard-adapter-CmKDTFdO.js} +3 -3
- package/dist/chunks/{clipboard-adapter-DEXkXxwV.js.map → clipboard-adapter-CmKDTFdO.js.map} +1 -1
- package/dist/chunks/{clipboard-adapter-Cfz-rzw3.cjs → clipboard-adapter-UIFc_Qso.cjs} +3 -3
- package/dist/chunks/{clipboard-adapter-Cfz-rzw3.cjs.map → clipboard-adapter-UIFc_Qso.cjs.map} +1 -1
- package/dist/chunks/{contrast-C6CVklEI.cjs → contrast-C9d8QuaF.cjs} +2 -2
- package/dist/chunks/{contrast-C6CVklEI.cjs.map → contrast-C9d8QuaF.cjs.map} +1 -1
- package/dist/chunks/{contrast-DpK2JIVu.js → contrast-DUaZq5SA.js} +2 -2
- package/dist/chunks/{contrast-DpK2JIVu.js.map → contrast-DUaZq5SA.js.map} +1 -1
- package/dist/chunks/{copy-interceptor-CZWzGOkL.d.cts → copy-interceptor-BClcHS_P.d.cts} +2 -2
- package/dist/chunks/{copy-interceptor-C6NABy1l.d.ts → copy-interceptor-D8c9EDnO.d.ts} +2 -2
- package/dist/chunks/{core-Cp2HSpaz.js → core-BH2uIumi.js} +5 -5
- package/dist/chunks/{core-Cp2HSpaz.js.map → core-BH2uIumi.js.map} +1 -1
- package/dist/chunks/{core-DYf_Lhbe.cjs → core-DmncxMt3.cjs} +5 -5
- package/dist/chunks/{core-DYf_Lhbe.cjs.map → core-DmncxMt3.cjs.map} +1 -1
- package/dist/chunks/{deadline-C29AlS_Q.js → deadline-CbwnZ3Oq.js} +2 -2
- package/dist/chunks/{deadline-C29AlS_Q.js.map → deadline-CbwnZ3Oq.js.map} +1 -1
- package/dist/chunks/{deadline-DkiB8ZHE.cjs → deadline-j2hD7JKz.cjs} +2 -2
- package/dist/chunks/{deadline-DkiB8ZHE.cjs.map → deadline-j2hD7JKz.cjs.map} +1 -1
- package/dist/chunks/{errors-9h8sdFFX.js → errors-CT-FfUtU.js} +2 -2
- package/dist/chunks/errors-CT-FfUtU.js.map +1 -0
- package/dist/chunks/{errors-BwOF6T_M.cjs → errors-DFmEAC4E.cjs} +2 -2
- package/dist/chunks/errors-DFmEAC4E.cjs.map +1 -0
- package/dist/chunks/{field-Bytz2WfN.cjs → field-B6SRWRbI.cjs} +59 -19
- package/dist/chunks/field-B6SRWRbI.cjs.map +1 -0
- package/dist/chunks/{field-BHo5y-t_.js → field-DsRKkbav.js} +54 -20
- package/dist/chunks/field-DsRKkbav.js.map +1 -0
- package/dist/chunks/{index-vz0iW5V2.d.cts → index-CqYzvxSN.d.cts} +4 -4
- package/dist/chunks/{index-mr7sSAgP.d.ts → index-Q_QeSwGr.d.ts} +4 -4
- package/dist/chunks/limits-9wi1f6xT.cjs +23 -0
- package/dist/chunks/limits-9wi1f6xT.cjs.map +1 -0
- package/dist/chunks/limits-BP9R5wnr.js +18 -0
- package/dist/chunks/limits-BP9R5wnr.js.map +1 -0
- package/dist/chunks/{paste-adapter--SPL4PRE.d.cts → paste-adapter-B6eucH3E.d.cts} +2 -2
- package/dist/chunks/{paste-adapter-uahXnTYk.d.ts → paste-adapter-CfIDT3mp.d.ts} +2 -2
- package/dist/chunks/{paste-reader-Bo01IMC_.cjs → paste-reader-BWQaYNaV.cjs} +2 -2
- package/dist/chunks/paste-reader-BWQaYNaV.cjs.map +1 -0
- package/dist/chunks/{paste-reader-D9i7yMXF.js → paste-reader-D6uOTDBM.js} +2 -2
- package/dist/chunks/paste-reader-D6uOTDBM.js.map +1 -0
- package/dist/chunks/{payload-DI5AorDz.js → payload-BWQ6sPtS.js} +3 -3
- package/dist/chunks/{payload-DI5AorDz.js.map → payload-BWQ6sPtS.js.map} +1 -1
- package/dist/chunks/{payload-DGw-JOo7.js → payload-BrQWGwyx.js} +2 -2
- package/dist/chunks/{payload-DGw-JOo7.js.map → payload-BrQWGwyx.js.map} +1 -1
- package/dist/chunks/{payload-Cl_8hCI5.d.ts → payload-CcvSx_Hq.d.ts} +4 -2
- package/dist/chunks/{payload-CcwKJ_bU.d.cts → payload-qkAWVXWA.d.cts} +4 -2
- package/dist/chunks/{payload-CUymxwim.cjs → payload-sBxkG7jH.cjs} +2 -2
- package/dist/chunks/{payload-CUymxwim.cjs.map → payload-sBxkG7jH.cjs.map} +1 -1
- package/dist/chunks/{payload-J6GjHuh3.cjs → payload-tTK6REua.cjs} +3 -3
- package/dist/chunks/{payload-J6GjHuh3.cjs.map → payload-tTK6REua.cjs.map} +1 -1
- package/dist/chunks/{share-Bop47Znn.js → share-CU91L4EK.js} +6 -6
- package/dist/chunks/{share-Bop47Znn.js.map → share-CU91L4EK.js.map} +1 -1
- package/dist/chunks/{share-e7FenIr2.d.ts → share-DVR_DhHc.d.ts} +3 -3
- package/dist/chunks/{share-C0esXvRK.d.cts → share-hIwth7Dh.d.cts} +3 -3
- package/dist/chunks/{share-ayDz974N.cjs → share-nx7M4Z0t.cjs} +6 -6
- package/dist/chunks/{share-ayDz974N.cjs.map → share-nx7M4Z0t.cjs.map} +1 -1
- package/dist/chunks/{url-D4PGsRm8.cjs → url-BrhVUwn7.cjs} +2 -2
- package/dist/chunks/{url-D4PGsRm8.cjs.map → url-BrhVUwn7.cjs.map} +1 -1
- package/dist/chunks/{url-BcMYVCXQ.js → url-COID0BLY.js} +2 -2
- package/dist/chunks/{url-BcMYVCXQ.js.map → url-COID0BLY.js.map} +1 -1
- package/dist/code.cjs +4 -8
- package/dist/code.cjs.map +1 -1
- package/dist/code.d.cts +1 -1
- package/dist/code.d.ts +1 -1
- package/dist/code.js +2 -6
- package/dist/code.js.map +1 -1
- package/dist/color.cjs +2 -2
- package/dist/color.d.cts +1 -1
- package/dist/color.d.ts +1 -1
- package/dist/color.js +2 -2
- package/dist/core.cjs +5 -5
- package/dist/core.d.cts +5 -5
- package/dist/core.d.ts +5 -5
- package/dist/core.js +5 -5
- package/dist/email.cjs +12 -8
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +9 -5
- package/dist/email.d.ts +9 -5
- package/dist/email.js +12 -9
- package/dist/email.js.map +1 -1
- package/dist/files.cjs +1 -1
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts +3 -59
- package/dist/files.d.ts +3 -59
- package/dist/files.js +1 -1
- package/dist/files.js.map +1 -1
- package/dist/image.cjs +2 -2
- package/dist/image.cjs.map +1 -1
- package/dist/image.js +2 -2
- package/dist/image.js.map +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -19
- package/dist/index.d.ts +43 -19
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +3 -3
- package/dist/link.d.cts +1 -1
- package/dist/link.d.ts +1 -1
- package/dist/link.js +3 -3
- package/dist/markdown.cjs +1 -1
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/number.cjs +9 -4
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.cts +9 -4
- package/dist/number.d.ts +9 -4
- package/dist/number.js +9 -5
- package/dist/number.js.map +1 -1
- package/dist/otp.cjs +2 -1
- package/dist/otp.d.cts +8 -3
- package/dist/otp.d.ts +8 -3
- package/dist/otp.js +1 -1
- package/dist/rich.cjs +3 -3
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +2 -2
- package/dist/rich.d.ts +2 -2
- package/dist/rich.js +3 -3
- package/dist/rich.js.map +1 -1
- package/dist/secrets.cjs +1 -1
- package/dist/secrets.cjs.map +1 -1
- package/dist/secrets.d.cts +1 -1
- package/dist/secrets.d.ts +1 -1
- package/dist/secrets.js +1 -1
- package/dist/secrets.js.map +1 -1
- package/dist/share.cjs +1 -1
- package/dist/share.d.cts +1 -1
- package/dist/share.d.ts +1 -1
- package/dist/share.js +1 -1
- package/dist/structured.cjs +2 -2
- package/dist/structured.cjs.map +1 -1
- package/dist/structured.js +2 -2
- package/dist/structured.js.map +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +1 -1
- package/dist/table.d.ts +1 -1
- package/dist/table.js +1 -1
- package/dist/table.js.map +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +3 -3
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +2 -2
- package/package.json +10 -4
- package/dist/chunks/errors-9h8sdFFX.js.map +0 -1
- package/dist/chunks/errors-BwOF6T_M.cjs.map +0 -1
- package/dist/chunks/field-BHo5y-t_.js.map +0 -1
- package/dist/chunks/field-Bytz2WfN.cjs.map +0 -1
- package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +0 -1
- package/dist/chunks/paste-reader-D9i7yMXF.js.map +0 -1
package/dist/number.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.cjs","names":["copyFailure","asciiDigits","copyFailure","asTextField","insertText","replaceFieldValue"],"sources":["../src/number/currency.ts","../src/number/locale.ts","../src/number/parse.ts","../src/number/format.ts","../src/number/paste.ts"],"sourcesContent":["/** A currency written next to a number. */\nexport interface NumberCurrency {\n /** As it was written, normalized: `\\u20AC`, `R$`, `kr`, `USD`. */\n readonly symbol: string;\n /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\\u00A5`, `kr` and `Rs`. */\n readonly code: string | null;\n}\n\n/**\n * Currency symbols, after NFKC (so `\\uFF04` is `$` and `\\u20A8` is `Rs`). Symbols that several\n * currencies share have no code: the text alone can't tell a dollar from another.\n */\nconst SYMBOLS: readonly (readonly [string, string | null])[] = [\n ['US$', 'USD'], ['CA$', 'CAD'], ['C$', 'CAD'], ['AU$', 'AUD'], ['A$', 'AUD'], ['NZ$', 'NZD'], ['HK$', 'HKD'],\n ['S$', 'SGD'], ['R$', 'BRL'], ['MX$', 'MXN'], ['NT$', 'TWD'], ['$', null],\n ['\\u20AC', 'EUR'], ['\\u00A3', 'GBP'], ['JP\\u00A5', 'JPY'], ['CN\\u00A5', 'CNY'], ['\\u00A5', null],\n ['\\u20B9', 'INR'], ['Rs.', null], ['Rs', null], ['\\u20A9', 'KRW'], ['\\u20BD', 'RUB'], ['\\u20BA', 'TRY'],\n ['\\u20AA', 'ILS'], ['\\u20AB', 'VND'], ['\\u20B1', 'PHP'], ['\\u0E3F', 'THB'], ['\\u20B4', 'UAH'], ['\\u20A6', 'NGN'],\n ['\\u20B8', 'KZT'], ['\\u09F3', 'BDT'], ['z\\u0142', 'PLN'], ['K\\u010D', 'CZK'], ['kr.', null], ['kr', null], ['Fr.', 'CHF'],\n];\n\n/** Longest first, so `US$` is read before `$` and `Rs.` before `Rs`. */\nconst BY_LENGTH = [...SYMBOLS].sort((a, b) => b[0].length - a[0].length).map(([symbol, code]) => [symbol, symbol.toLowerCase(), code] as const);\n\nlet codes: ReadonlySet<string> | null | undefined;\n\n/** Whether `code` (upper case) is an ISO 4217 code the runtime knows; any three letters where it can't say. */\nexport function isCurrencyCode(code: string): boolean {\n if (codes === undefined) {\n const supported = (Intl as { supportedValuesOf?: (key: 'currency') => string[] }).supportedValuesOf;\n codes = typeof supported === 'function' ? new Set(supported('currency')) : null;\n }\n return /^[A-Z]{3}$/.test(code) && (codes === null || codes.has(code));\n}\n\n/** For tests: forget the runtime's codes, so they are read again. */\nexport function resetCurrencyCodes(): void {\n codes = undefined;\n}\n\nconst LETTER = /\\p{L}/u;\n\n/**\n * The currency at the start of `text`, and how many characters it takes. A symbol or code\n * made of letters must end there: `Rs` is not read from `Rsx`, nor `USD` from `USDT`.\n */\nexport function readCurrency(text: string): { readonly currency: NumberCurrency; readonly length: number } | null {\n const lower = text.toLowerCase();\n for (const [symbol, key, code] of BY_LENGTH) {\n if (lower.startsWith(key) && !(LETTER.test(symbol.slice(-1)) && LETTER.test(text.charAt(key.length)))) {\n return { currency: { symbol, code }, length: key.length };\n }\n }\n const word = /^\\p{L}+/u.exec(text)?.[0] ?? '';\n const code = word.toUpperCase();\n return word.length === 3 && isCurrencyCode(code) ? { currency: { symbol: code, code }, length: 3 } : null;\n}\n","import { copyFailure } from '../core/errors';\n\n/** How a locale writes numbers, in Latin digits. */\nexport interface NumberSymbols {\n /** The decimal separator. */\n readonly decimal: '.' | ',';\n /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */\n readonly group: string;\n /** Digits in the last group of the integer part: 3 almost everywhere. */\n readonly primary: number;\n /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */\n readonly secondary: number;\n}\n\nconst cache = new Map<string, NumberSymbols>();\nconst CACHE_SIZE = 32;\n\n/**\n * How `locale` writes numbers, from `Intl.NumberFormat`.\n *\n * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.\n */\nexport function numberSymbols(locale: string): NumberSymbols {\n const cached = cache.get(locale);\n if (cached !== undefined) return cached;\n let parts: Intl.NumberFormatPart[];\n try {\n parts = new Intl.NumberFormat(locale, { numberingSystem: 'latn' }).formatToParts(123456789012.5);\n } catch (cause) {\n throw copyFailure('invalid-payload', `\"${locale}\" is not a locale.`, cause);\n }\n // 123,456,789,012 in most locales; 1,23,45,67,89,012 in India's.\n const integers = parts.filter((part) => part.type === 'integer').map((part) => part.value.length);\n const symbols: NumberSymbols = {\n decimal: parts.some((part) => part.type === 'decimal' && part.value === ',') ? ',' : '.',\n // A locale that writes no group separator has none to add.\n group: parts.find((part) => part.type === 'group')?.value ?? '',\n primary: Number(integers[integers.length - 1]),\n secondary: Number(integers[Math.max(0, integers.length - 2)]),\n };\n // A small cache: locales come from settings, but a hostile caller could pass many.\n if (cache.size >= CACHE_SIZE) cache.clear();\n cache.set(locale, symbols);\n return symbols;\n}\n","import { asciiDigits } from '../core/digits';\nimport { readCurrency, type NumberCurrency } from './currency';\nimport { numberSymbols } from './locale';\n\n/** What a number was written as: `12` is a number, `12%` a percentage, `12\\u2030` per mille. */\nexport type NumberKind = 'number' | 'percent' | 'permille';\n\n/** A number read from text. */\nexport interface ParsedNumber {\n /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \\u20AC)`. */\n readonly value: number;\n /**\n * The same number as an exact decimal string, without rounding: `-1234.50` keeps its\n * trailing zero, and `0.1` is not `0.1000000000000000055\\u2026`. Use it for money.\n */\n readonly exact: string;\n /** `'percent'` or `'permille'` when the number was written with `%` or `\\u2030`. */\n readonly kind: NumberKind;\n /** The currency written with it, if any. */\n readonly currency: NumberCurrency | null;\n /**\n * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group\n * separator in some locales and a decimal separator in others. `locale` decided which;\n * ask the person when it matters.\n */\n readonly ambiguous: boolean;\n}\n\nexport interface ParseNumberOptions {\n /**\n * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping\n * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way\n * is read that way in every locale: `1.234,5` is 1234.5 everywhere.\n */\n readonly locale?: string;\n /** Accept negative numbers. Default `true`. */\n readonly negative?: boolean;\n /** Accept numbers with a fractional part. Default `true`. */\n readonly fraction?: boolean;\n /** Accept a currency symbol or code. Default `true`. */\n readonly currency?: boolean;\n /** Accept `%` and `\\u2030`. Default `true`. */\n readonly percent?: boolean;\n}\n\n/** Longer text holds more than a number: it is not read at all. */\nexport const NUMBER_MAX_LENGTH = 256;\n\n/** Group separators that are never decimal separators: spaces and apostrophes. */\nconst GROUP_ONLY = new Set([' ', \"'\"]);\n/** The largest exponent read from scientific notation, past which no number is finite. */\nconst MAX_EXPONENT = 400;\n\ninterface Adornments {\n sign: '' | '-' | '+';\n /** An opening bracket before the number, and a closing one after it: accounting's minus. */\n open: boolean;\n close: boolean;\n currency: NumberCurrency | null;\n kind: NumberKind;\n}\n\n/**\n * Reads the signs, brackets, currency and percent on one side of the number. Returns\n * `false` when something else is there, or when one of them appears twice.\n */\nfunction readAdornments(text: string, into: Adornments, side: 'prefix' | 'suffix'): boolean {\n let rest = text;\n for (;;) {\n rest = rest.trimStart();\n if (rest === '') return true;\n const char = rest.charAt(0);\n let length = 1;\n if (char === '(' && side === 'prefix' && !into.open) into.open = true;\n else if (char === ')' && side === 'suffix' && !into.close) into.close = true;\n // A minus after the number is a trailing minus (`1234-`), as some accounting systems write it.\n else if ((char === '-' || (char === '+' && side === 'prefix')) && into.sign === '') into.sign = char;\n else if ((char === '%' || char === '\\u2030') && into.kind === 'number') into.kind = char === '%' ? 'percent' : 'permille';\n else {\n const read = into.currency === null ? readCurrency(rest) : null;\n if (read === null) return false;\n into.currency = read.currency;\n length = read.length;\n }\n rest = rest.slice(length);\n }\n}\n\n/** The text in a form the reader understands: ASCII digits, one minus, one apostrophe, plain spaces. */\nfunction normalize(text: string): string {\n return (\n asciiDigits(text)\n // Minus signs and dashes used as one.\n .replace(/[\\u2212\\u2012\\u2013]/g, '-')\n // Arabic percent sign; Arabic decimal and thousands separators come next.\n .replace(/\\u066A/g, '%')\n .replace(/[\\u2019\\u02BC\\u066C]/g, \"'\")\n .replace(/\\s/g, ' ')\n );\n}\n\n/** Whether `groups` (the integer part, split at its group separator) are grouped the way locales group. */\nfunction validGroups(groups: readonly string[]): boolean {\n const [first, ...rest] = groups;\n if (first === undefined || first === '' || first.length > 3 || rest.length === 0) return false;\n if (rest.every((group) => group.length === 3)) return true;\n // Lakh and crore: 12,34,567. The last group has 3 digits and the others 2.\n return first.length <= 2 && rest.slice(0, -1).every((group) => group.length === 2) && rest[rest.length - 1]?.length === 3;\n}\n\ninterface Mantissa {\n readonly integer: string;\n readonly fraction: string;\n readonly ambiguous: boolean;\n}\n\n/** The integer and fractional digits of `text` (digits and separators only), or `null`. */\nfunction readMantissa(text: string, decimalOfLocale: '.' | ',', arabicDecimal: boolean): Mantissa | null {\n const separators = text.replace(/\\d/g, '');\n if (separators === '') return { integer: text, fraction: '', ambiguous: false };\n // The decimal separator can only be the last separator, appearing once: `1,234,567.8`,\n // `1.234,5`. An Arabic decimal separator is one wherever it is.\n const candidate = arabicDecimal ? '.' : separators.charAt(separators.length - 1);\n const once = separators.split(candidate).length === 2;\n if (arabicDecimal && !once) return null;\n let decimal: string | null = null;\n let ambiguous = false;\n if (once && !GROUP_ONLY.has(candidate)) {\n const at = text.lastIndexOf(candidate);\n const before = text.slice(0, at);\n // A lone separator is a decimal unless it could also start a group of three.\n if (arabicDecimal || separators.length > 1 || text.length - at - 1 !== 3 || before === '' || before.length > 3 || before.startsWith('0')) decimal = candidate;\n else {\n ambiguous = true;\n decimal = candidate === decimalOfLocale ? candidate : null;\n }\n }\n const at = decimal === null ? text.length : text.lastIndexOf(decimal);\n const integerPart = text.slice(0, at);\n const fraction = text.slice(at + 1);\n if (!/^\\d*$/.test(fraction)) return null;\n const groupSeparators = integerPart.replace(/\\d/g, '');\n if (groupSeparators === '') return { integer: integerPart, fraction, ambiguous };\n const group = groupSeparators.charAt(0);\n if (groupSeparators !== group.repeat(groupSeparators.length) || !validGroups(integerPart.split(group))) return null;\n return { integer: integerPart.split(group).join(''), fraction, ambiguous };\n}\n\n/** `integer.fraction` times ten to the `exponent`, as an exact decimal string without a sign. */\nfunction shift(integer: string, fraction: string, exponent: number): string {\n const digits = integer + fraction;\n const point = integer.length + exponent;\n let whole: string;\n let decimals: string;\n if (exponent === 0) [whole, decimals] = [integer, fraction];\n else if (point <= 0) [whole, decimals] = ['0', '0'.repeat(-point) + digits];\n else if (point >= digits.length) [whole, decimals] = [digits + '0'.repeat(point - digits.length), ''];\n else [whole, decimals] = [digits.slice(0, point), digits.slice(point)];\n // Scientific notation's own trailing zeros say nothing about precision: they go.\n if (exponent !== 0) decimals = decimals.replace(/0+$/, '');\n whole = whole.replace(/^0+(?=\\d)/, '');\n return decimals === '' ? whole : `${whole}.${decimals}`;\n}\n\n/**\n * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice\n * or a web page, in any locale's format. The whole text must be one number, with at most a\n * sign, a currency and a percent sign around it; anything else gives `null`.\n *\n * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of\n * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.\n * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,\n * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.\n * - `-`, `+`, `\\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).\n * - Currency symbols and ISO codes, before or after: `$`, `\\u20AC`, `R$`, `kr`, `USD`, `CHF`.\n * - `%` and `\\u2030`, before or after; scientific notation (`1.5E-7`).\n * - Digits of any script, full-width characters, and Arabic separators.\n *\n * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one.\n * @example\n * parseNumber('1.234,50 \\u20AC', { locale: 'de-DE' });\n * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\\u20AC', code: 'EUR' }, ambiguous: false }\n */\nexport function parseNumber(text: string, options: ParseNumberOptions = {}): ParsedNumber | null {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n if (text.length > NUMBER_MAX_LENGTH) return null;\n const arabicDecimal = text.includes('\\u066B');\n const normalized = normalize(text.replace(/\\u066B/g, '.'));\n // The number: from its first digit (or a separator right before it, as in `.5`) to its last\n // digit. Not a dot that ends a word (`Rs.5` is 5 rupees).\n let start = normalized.search(/\\d/);\n if (start === -1) return null;\n if (/[.,]/.test(normalized.charAt(start - 1)) && !/\\p{L}/u.test(normalized.charAt(start - 2))) start -= 1;\n let end = normalized.length;\n while (!/\\d/.test(normalized.charAt(end - 1))) end -= 1;\n const adornments: Adornments = { sign: '', open: false, close: false, currency: null, kind: 'number' };\n if (!readAdornments(normalized.slice(0, start), adornments, 'prefix') || !readAdornments(normalized.slice(end), adornments, 'suffix')) return null;\n // Brackets come in pairs, and mean the minus: `-(5)` is a typo, not a number.\n if (adornments.open !== adornments.close || (adornments.open && adornments.sign !== '')) return null;\n\n const core = normalized.slice(start, end);\n // Scientific notation, as spreadsheets copy it: one decimal separator, never grouped.\n const scientific = /^(\\d*)(?:[.,](\\d*))?[eE]([+-]?\\d{1,3})$/.exec(core);\n let mantissa: Mantissa | null;\n if (scientific === null) mantissa = /^[\\d.,' ]+$/.test(core) ? readMantissa(core, symbols.decimal, arabicDecimal) : null;\n else mantissa = { integer: String(scientific[1]), fraction: scientific[2] ?? '', ambiguous: false };\n if (mantissa === null) return null;\n const exponent = scientific === null ? 0 : Number(scientific[3]);\n if (Math.abs(exponent) > MAX_EXPONENT) return null;\n\n const digits = shift(mantissa.integer === '' ? '0' : mantissa.integer, mantissa.fraction, exponent);\n const zero = /^0(?:\\.0*)?$/.test(digits);\n const negative = (adornments.sign === '-' || adornments.open) && !zero;\n const exact = negative ? `-${digits}` : digits;\n const value = Number(exact);\n if (!Number.isFinite(value)) return null;\n\n if (options.negative === false && negative) return null;\n if (options.fraction === false && /\\.\\d*[1-9]/.test(digits)) return null;\n if (options.currency === false && adornments.currency !== null) return null;\n if (options.percent === false && adornments.kind !== 'number') return null;\n if (adornments.currency !== null && adornments.kind !== 'number') return null;\n return { value, exact, kind: adornments.kind, currency: adornments.currency, ambiguous: mantissa.ambiguous };\n}\n","import { copyFailure } from '../core/errors';\nimport type { TextPayload } from '../core/payload';\nimport { numberSymbols } from './locale';\n\nexport interface FormatNumberOptions {\n /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */\n readonly locale?: string;\n /**\n * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets\n * read ungrouped numbers in every locale, and grouped ones only in their own.\n */\n readonly grouping?: boolean;\n /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */\n readonly fractionDigits?: number;\n}\n\n/** Plain decimal notation, as `parseNumber` gives in `exact`: `-1234.50`, `0.00000015`. */\nconst EXACT = /^(-?)(\\d+)(?:\\.(\\d+))?$/;\nconst NUMBER = /^(-?)(\\d+)(?:\\.(\\d+))?(?:e([+-]\\d+))?$/;\n\n/** `value` as sign, integer digits and fraction digits, exactly. */\nfunction decompose(value: number | string | bigint): readonly [boolean, string, string] {\n if (typeof value === 'bigint') {\n const text = value.toString();\n return text.startsWith('-') ? [true, text.slice(1), ''] : [false, text, ''];\n }\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw copyFailure('invalid-payload', `${String(value)} is not a finite number.`);\n // `String` gives the shortest text that reads back as the same number: 0.1 is `0.1`.\n const match = NUMBER.exec(String(value)) as RegExpExecArray;\n const sign = String(match[1]);\n const integer = String(match[2]);\n const fraction = match[3] ?? '';\n const shiftBy = Number(match[4] ?? '0');\n const digits = integer + fraction;\n const point = integer.length + shiftBy;\n if (point <= 0) return [sign === '-', '0', '0'.repeat(-point) + digits];\n if (point >= digits.length) return [sign === '-', digits + '0'.repeat(point - digits.length), ''];\n return [sign === '-', digits.slice(0, point), digits.slice(point)];\n }\n const match = EXACT.exec(value);\n if (match === null) throw copyFailure('invalid-payload', `\"${value.slice(0, 40)}\" is not a decimal number such as \"-1234.5\".`);\n return [match[1] === '-', String(match[2]), match[3] ?? ''];\n}\n\n/** `digits` plus one, carrying: `\"199\"` gives `\"200\"`, `\"99\"` gives `\"100\"`. */\nfunction increment(digits: string): string {\n let out = '';\n let carry = true;\n for (let index = digits.length - 1; index >= 0; index -= 1) {\n const digit: number = Number(digits.charAt(index)) + (carry ? 1 : 0);\n carry = digit === 10;\n out = String(digit % 10) + out;\n }\n return carry ? `1${out}` : out;\n}\n\n/** Groups `integer` from the right: the last group of `primary` digits, the others of `secondary`. */\nfunction group(integer: string, separator: string, primary: number, secondary: number): string {\n if (integer.length <= primary) return integer;\n const groups = [integer.slice(-primary)];\n let rest = integer.slice(0, -primary);\n while (rest.length > secondary) {\n groups.unshift(rest.slice(-secondary));\n rest = rest.slice(0, -secondary);\n }\n groups.unshift(rest);\n return groups.join(separator);\n}\n\n/**\n * Writes a number in a locale's format, exactly: no float rounding, whatever its size.\n * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so\n * money read from one locale can be written in another without losing a cent.\n *\n * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is\n * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.\n * @example\n * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // \"1.234,50\"\n */\nexport function formatNumber(value: number | string | bigint, options: FormatNumberOptions = {}): string {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n const digits = options.fractionDigits;\n if (digits !== undefined && !(Number.isInteger(digits) && digits >= 0 && digits <= 100)) {\n throw copyFailure('invalid-payload', `fractionDigits must be a whole number from 0 to 100, not ${String(digits)}.`);\n }\n const [negative, rawInteger, rawFraction] = decompose(value);\n let integer = rawInteger.replace(/^0+(?=\\d)/, '');\n let fraction = rawFraction;\n if (digits !== undefined) {\n if (fraction.length > digits) {\n const roundUp = fraction.charAt(digits) >= '5';\n fraction = fraction.slice(0, digits);\n if (roundUp) {\n const rounded = increment(integer + fraction);\n integer = rounded.slice(0, rounded.length - digits);\n fraction = rounded.slice(rounded.length - digits);\n }\n } else fraction = fraction.padEnd(digits, '0');\n }\n const zero = /^0*$/.test(integer + fraction);\n const whole = options.grouping === true ? group(integer, symbols.group, symbols.primary, symbols.secondary) : integer;\n return `${negative && !zero ? '-' : ''}${whole}${fraction === '' ? '' : symbols.decimal + fraction}`;\n}\n\n/**\n * A copy payload for a number, written for the locale it will be pasted in: ungrouped by\n * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.\n *\n * @example\n * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));\n */\nexport function numberPayload(value: number | string | bigint, options: FormatNumberOptions = {}): TextPayload {\n return { kind: 'text', value: formatNumber(value, options) };\n}\n","import { asTextField, insertText, replaceFieldValue, type TextField } from '../core/text-field';\nimport { formatNumber } from './format';\nimport { parseNumber, type ParsedNumber, type ParseNumberOptions } from './parse';\n\n/** What {@link pasteAsNumber} did. */\nexport type NumberPasteOutcome =\n /** The paste held a number: it was inserted, written the way the field takes it. */\n | 'pasted'\n /** The paste was not a number (or the field is read-only): nothing was inserted. */\n | 'rejected'\n /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */\n | 'ignored';\n\nexport interface PasteAsNumberOptions extends ParseNumberOptions {\n /**\n * How to write the number into the field. Default: `exact` for `<input type=\"number\">`,\n * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,\n * ungrouped (`1234,5` in `de-DE`).\n */\n readonly format?: (parsed: ParsedNumber) => string;\n /** Called with the number before it is inserted: show `ambiguous` readings here. */\n readonly onNumber?: (parsed: ParsedNumber) => void;\n /** Called with the pasted text when it was not a number, or the field takes no input. */\n readonly onReject?: (text: string) => void;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface NumberPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nfunction asNumberInput(target: EventTarget | null): HTMLInputElement | null {\n const element = target as (Partial<Element> & { type?: unknown }) | null;\n return element?.nodeName === 'INPUT' && element.type === 'number' ? (target as HTMLInputElement) : null;\n}\n\n/**\n * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank\n * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either\n * rejects these from `<input type=\"number\">` or keeps the text as it is. This reads the\n * number, inserts it the way the field takes it (with undo intact in text fields), and\n * turns away pastes that are not a number.\n *\n * Works on `<input type=\"number\">`, text `<input>`s (use `inputmode=\"decimal\"`) and\n * `<textarea>`s; other elements are left to the browser.\n *\n * @example\n * <input inputMode=\"decimal\" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />\n */\nexport function pasteAsNumber(event: NumberPasteEvent, options: PasteAsNumberOptions = {}): NumberPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'ignored';\n const numberInput = asNumberInput(event.currentTarget) ?? asNumberInput(event.target);\n const field: TextField | null = numberInput ?? asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null) return 'ignored';\n const text = event.clipboardData.getData('text/plain');\n if (text === '') return 'ignored';\n event.preventDefault();\n const parsed = parseNumber(text.trim(), options);\n if (parsed !== null && !field.disabled && !field.readOnly) {\n options.onNumber?.(parsed);\n const value = options.format?.(parsed) ?? (numberInput === null ? formatNumber(parsed.exact, options) : parsed.exact);\n if (numberInput === null ? insertText(field, value) : replaceFieldValue(numberInput, value)) return 'pasted';\n }\n options.onReject?.(text);\n return 'rejected';\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,YAAY,CAAC,GAAG;CATpB,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAC3G,CAAC,MAAM,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,KAAK,IAAI;CACxE,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,OAAY,KAAK;CAAG,CAAC,OAAY,KAAK;CAAG,CAAC,KAAU,IAAI;CAC/F,CAAC,KAAU,KAAK;CAAG,CAAC,OAAO,IAAI;CAAG,CAAC,MAAM,IAAI;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CACtG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,K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O;EAAE,MAAM;EAAQ,OAAO,aAAa,OAAO,OAAO;CAAE;AAC7D;;;AC/EA,SAAS,cAAc,QAAqD;CAC1E,MAAM,UAAU;CAChB,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,WAAY,SAA8B;AACrG;;;;;;;;;;;;;;AAeA,SAAgB,cAAc,OAAyB,UAAgC,CAAC,GAAuB;CAC7G,IAAI,MAAM,oBAAoB,MAAM,kBAAkB,MAAM,OAAO;CACnE,MAAM,cAAc,cAAc,MAAM,aAAa,KAAK,cAAc,MAAM,MAAM;CACpF,MAAM,QAA0B,eAAeC,mBAAAA,YAAY,MAAM,aAAa,KAAKA,mBAAAA,YAAY,MAAM,MAAM;CAC3G,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,OAAO,MAAM,cAAc,QAAQ,YAAY;CACrD,IAAI,SAAS,IAAI,OAAO;CACxB,MAAM,eAAe;CACrB,MAAM,SAAS,YAAY,KAAK,KAAK,GAAG,OAAO;CAC/C,IAAI,WAAW,QAAQ,CAAC,MAAM,YAAY,CAAC,MAAM,UAAU;EACzD,QAAQ,WAAW,MAAM;EACzB,MAAM,QAAQ,QAAQ,SAAS,MAAM,MAAM,gBAAgB,OAAO,aAAa,OAAO,OAAO,OAAO,IAAI,OAAO;EAC/G,IAAI,gBAAgB,OAAOC,mBAAAA,WAAW,OAAO,KAAK,IAAIC,mBAAAA,kBAAkB,aAAa,KAAK,GAAG,OAAO;CACtG;CACA,QAAQ,WAAW,IAAI;CACvB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"number.cjs","names":["copyFailure","asciiDigits","positiveLimit","copyFailure","asTextField","insertText","replaceFieldValue"],"sources":["../src/number/currency.ts","../src/number/locale.ts","../src/number/parse.ts","../src/number/format.ts","../src/number/paste.ts"],"sourcesContent":["/** A currency written next to a number. */\nexport interface NumberCurrency {\n /** As it was written, normalized: `\\u20AC`, `R$`, `kr`, `USD`. */\n readonly symbol: string;\n /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\\u00A5`, `kr` and `Rs`. */\n readonly code: string | null;\n}\n\n/**\n * Currency symbols, after NFKC (so `\\uFF04` is `$` and `\\u20A8` is `Rs`). Symbols that several\n * currencies share have no code: the text alone can't tell a dollar from another.\n */\nconst SYMBOLS: readonly (readonly [string, string | null])[] = [\n ['US$', 'USD'], ['CA$', 'CAD'], ['C$', 'CAD'], ['AU$', 'AUD'], ['A$', 'AUD'], ['NZ$', 'NZD'], ['HK$', 'HKD'],\n ['S$', 'SGD'], ['R$', 'BRL'], ['MX$', 'MXN'], ['NT$', 'TWD'], ['$', null],\n ['\\u20AC', 'EUR'], ['\\u00A3', 'GBP'], ['JP\\u00A5', 'JPY'], ['CN\\u00A5', 'CNY'], ['\\u00A5', null],\n ['\\u20B9', 'INR'], ['Rs.', null], ['Rs', null], ['\\u20A9', 'KRW'], ['\\u20BD', 'RUB'], ['\\u20BA', 'TRY'],\n ['\\u20AA', 'ILS'], ['\\u20AB', 'VND'], ['\\u20B1', 'PHP'], ['\\u0E3F', 'THB'], ['\\u20B4', 'UAH'], ['\\u20A6', 'NGN'],\n ['\\u20B8', 'KZT'], ['\\u09F3', 'BDT'], ['z\\u0142', 'PLN'], ['K\\u010D', 'CZK'], ['kr.', null], ['kr', null], ['Fr.', 'CHF'],\n];\n\n/** Longest first, so `US$` is read before `$` and `Rs.` before `Rs`. */\nconst BY_LENGTH = [...SYMBOLS].sort((a, b) => b[0].length - a[0].length).map(([symbol, code]) => [symbol, symbol.toLowerCase(), code] as const);\n\nlet codes: ReadonlySet<string> | null | undefined;\n\n/** Whether `code` (upper case) is an ISO 4217 code the runtime knows; any three letters where it can't say. */\nexport function isCurrencyCode(code: string): boolean {\n if (codes === undefined) {\n const supported = (Intl as { supportedValuesOf?: (key: 'currency') => string[] }).supportedValuesOf;\n codes = typeof supported === 'function' ? new Set(supported('currency')) : null;\n }\n return /^[A-Z]{3}$/.test(code) && (codes === null || codes.has(code));\n}\n\n/** For tests: forget the runtime's codes, so they are read again. */\nexport function resetCurrencyCodes(): void {\n codes = undefined;\n}\n\nconst LETTER = /\\p{L}/u;\n\n/**\n * The currency at the start of `text`, and how many characters it takes. A symbol or code\n * made of letters must end there: `Rs` is not read from `Rsx`, nor `USD` from `USDT`.\n */\nexport function readCurrency(text: string): { readonly currency: NumberCurrency; readonly length: number } | null {\n const lower = text.toLowerCase();\n for (const [symbol, key, code] of BY_LENGTH) {\n if (lower.startsWith(key) && !(LETTER.test(symbol.slice(-1)) && LETTER.test(text.charAt(key.length)))) {\n return { currency: { symbol, code }, length: key.length };\n }\n }\n const word = /^\\p{L}+/u.exec(text)?.[0] ?? '';\n const code = word.toUpperCase();\n return word.length === 3 && isCurrencyCode(code) ? { currency: { symbol: code, code }, length: 3 } : null;\n}\n","import { copyFailure } from '../core/errors';\n\n/** How a locale writes numbers, in Latin digits. */\nexport interface NumberSymbols {\n /** The decimal separator. */\n readonly decimal: '.' | ',';\n /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */\n readonly group: string;\n /** Digits in the last group of the integer part: 3 almost everywhere. */\n readonly primary: number;\n /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */\n readonly secondary: number;\n}\n\nconst cache = new Map<string, NumberSymbols>();\nconst CACHE_SIZE = 32;\n\n/**\n * How `locale` writes numbers, from `Intl.NumberFormat`.\n *\n * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.\n */\nexport function numberSymbols(locale: string): NumberSymbols {\n const cached = cache.get(locale);\n if (cached !== undefined) return cached;\n let parts: Intl.NumberFormatPart[];\n try {\n parts = new Intl.NumberFormat(locale, { numberingSystem: 'latn' }).formatToParts(123456789012.5);\n } catch (cause) {\n throw copyFailure('invalid-payload', `\"${locale}\" is not a locale.`, cause);\n }\n // 123,456,789,012 in most locales; 1,23,45,67,89,012 in India's.\n const integers = parts.filter((part) => part.type === 'integer').map((part) => part.value.length);\n const symbols: NumberSymbols = {\n decimal: parts.some((part) => part.type === 'decimal' && part.value === ',') ? ',' : '.',\n // A locale that writes no group separator has none to add.\n group: parts.find((part) => part.type === 'group')?.value ?? '',\n primary: Number(integers[integers.length - 1]),\n secondary: Number(integers[Math.max(0, integers.length - 2)]),\n };\n // A small cache: locales come from settings, but a hostile caller could pass many.\n if (cache.size >= CACHE_SIZE) cache.clear();\n cache.set(locale, symbols);\n return symbols;\n}\n","import { asciiDigits } from '../core/digits';\nimport { positiveLimit } from '../core/limits';\nimport { readCurrency, type NumberCurrency } from './currency';\nimport { numberSymbols } from './locale';\n\n/** What a number was written as: `12` is a number, `12%` a percentage, `12\\u2030` per mille. */\nexport type NumberKind = 'number' | 'percent' | 'permille';\n\n/** A number read from text. */\nexport interface ParsedNumber {\n /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \\u20AC)`. */\n readonly value: number;\n /**\n * The same number as an exact decimal string, without rounding: `-1234.50` keeps its\n * trailing zero, and `0.1` is not `0.1000000000000000055\\u2026`. Use it for money.\n */\n readonly exact: string;\n /** `'percent'` or `'permille'` when the number was written with `%` or `\\u2030`. */\n readonly kind: NumberKind;\n /** The currency written with it, if any. */\n readonly currency: NumberCurrency | null;\n /**\n * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group\n * separator in some locales and a decimal separator in others. `locale` decided which;\n * ask the person when it matters.\n */\n readonly ambiguous: boolean;\n}\n\nexport interface ParseNumberOptions {\n /**\n * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping\n * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way\n * is read that way in every locale: `1.234,5` is 1234.5 everywhere.\n */\n readonly locale?: string;\n /** Accept negative numbers. Default `true`. */\n readonly negative?: boolean;\n /** Accept numbers with a fractional part. Default `true`. */\n readonly fraction?: boolean;\n /** Accept a currency symbol or code. Default `true`. */\n readonly currency?: boolean;\n /** Accept `%` and `\\u2030`. Default `true`. */\n readonly percent?: boolean;\n /** Text longer than this is not a number: `null`, unread. Default {@link DEFAULT_NUMBER_MAX_LENGTH}. */\n readonly maxLength?: number;\n}\n\n/** Longer text holds more than a number: it is not read at all, unless `maxLength` allows it. */\nexport const DEFAULT_NUMBER_MAX_LENGTH = 256;\n/** @deprecated The old name of {@link DEFAULT_NUMBER_MAX_LENGTH}; removed in 2.0. */\nexport const NUMBER_MAX_LENGTH: number = DEFAULT_NUMBER_MAX_LENGTH;\n\n/** Group separators that are never decimal separators: spaces and apostrophes. */\nconst GROUP_ONLY = new Set([' ', \"'\"]);\n/** The largest exponent read from scientific notation, past which no number is finite. */\nconst MAX_EXPONENT = 400;\n\ninterface Adornments {\n sign: '' | '-' | '+';\n /** An opening bracket before the number, and a closing one after it: accounting's minus. */\n open: boolean;\n close: boolean;\n currency: NumberCurrency | null;\n kind: NumberKind;\n}\n\n/**\n * Reads the signs, brackets, currency and percent on one side of the number. Returns\n * `false` when something else is there, or when one of them appears twice.\n */\nfunction readAdornments(text: string, into: Adornments, side: 'prefix' | 'suffix'): boolean {\n let rest = text;\n for (;;) {\n rest = rest.trimStart();\n if (rest === '') return true;\n const char = rest.charAt(0);\n let length = 1;\n if (char === '(' && side === 'prefix' && !into.open) into.open = true;\n else if (char === ')' && side === 'suffix' && !into.close) into.close = true;\n // A minus after the number is a trailing minus (`1234-`), as some accounting systems write it.\n else if ((char === '-' || (char === '+' && side === 'prefix')) && into.sign === '') into.sign = char;\n else if ((char === '%' || char === '\\u2030') && into.kind === 'number') into.kind = char === '%' ? 'percent' : 'permille';\n else {\n const read = into.currency === null ? readCurrency(rest) : null;\n if (read === null) return false;\n into.currency = read.currency;\n length = read.length;\n }\n rest = rest.slice(length);\n }\n}\n\n/** The text in a form the reader understands: ASCII digits, one minus, one apostrophe, plain spaces. */\nfunction normalize(text: string): string {\n return (\n asciiDigits(text)\n // Minus signs and dashes used as one.\n .replace(/[\\u2212\\u2012\\u2013]/g, '-')\n // Arabic percent sign; Arabic decimal and thousands separators come next.\n .replace(/\\u066A/g, '%')\n .replace(/[\\u2019\\u02BC\\u066C]/g, \"'\")\n .replace(/\\s/g, ' ')\n );\n}\n\n/** Whether `groups` (the integer part, split at its group separator) are grouped the way locales group. */\nfunction validGroups(groups: readonly string[]): boolean {\n const [first, ...rest] = groups;\n if (first === undefined || first === '' || first.length > 3 || rest.length === 0) return false;\n if (rest.every((group) => group.length === 3)) return true;\n // Lakh and crore: 12,34,567. The last group has 3 digits and the others 2.\n return first.length <= 2 && rest.slice(0, -1).every((group) => group.length === 2) && rest[rest.length - 1]?.length === 3;\n}\n\ninterface Mantissa {\n readonly integer: string;\n readonly fraction: string;\n readonly ambiguous: boolean;\n}\n\n/** The integer and fractional digits of `text` (digits and separators only), or `null`. */\nfunction readMantissa(text: string, decimalOfLocale: '.' | ',', arabicDecimal: boolean): Mantissa | null {\n const separators = text.replace(/\\d/g, '');\n if (separators === '') return { integer: text, fraction: '', ambiguous: false };\n // The decimal separator can only be the last separator, appearing once: `1,234,567.8`,\n // `1.234,5`. An Arabic decimal separator is one wherever it is.\n const candidate = arabicDecimal ? '.' : separators.charAt(separators.length - 1);\n const once = separators.split(candidate).length === 2;\n if (arabicDecimal && !once) return null;\n let decimal: string | null = null;\n let ambiguous = false;\n if (once && !GROUP_ONLY.has(candidate)) {\n const at = text.lastIndexOf(candidate);\n const before = text.slice(0, at);\n // A lone separator is a decimal unless it could also start a group of three.\n if (arabicDecimal || separators.length > 1 || text.length - at - 1 !== 3 || before === '' || before.length > 3 || before.startsWith('0')) decimal = candidate;\n else {\n ambiguous = true;\n decimal = candidate === decimalOfLocale ? candidate : null;\n }\n }\n const at = decimal === null ? text.length : text.lastIndexOf(decimal);\n const integerPart = text.slice(0, at);\n const fraction = text.slice(at + 1);\n if (!/^\\d*$/.test(fraction)) return null;\n const groupSeparators = integerPart.replace(/\\d/g, '');\n if (groupSeparators === '') return { integer: integerPart, fraction, ambiguous };\n const group = groupSeparators.charAt(0);\n if (groupSeparators !== group.repeat(groupSeparators.length) || !validGroups(integerPart.split(group))) return null;\n return { integer: integerPart.split(group).join(''), fraction, ambiguous };\n}\n\n/** `integer.fraction` times ten to the `exponent`, as an exact decimal string without a sign. */\nfunction shift(integer: string, fraction: string, exponent: number): string {\n const digits = integer + fraction;\n const point = integer.length + exponent;\n let whole: string;\n let decimals: string;\n if (exponent === 0) [whole, decimals] = [integer, fraction];\n else if (point <= 0) [whole, decimals] = ['0', '0'.repeat(-point) + digits];\n else if (point >= digits.length) [whole, decimals] = [digits + '0'.repeat(point - digits.length), ''];\n else [whole, decimals] = [digits.slice(0, point), digits.slice(point)];\n // Scientific notation's own trailing zeros say nothing about precision: they go.\n if (exponent !== 0) decimals = decimals.replace(/0+$/, '');\n whole = whole.replace(/^0+(?=\\d)/, '');\n return decimals === '' ? whole : `${whole}.${decimals}`;\n}\n\n/**\n * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice\n * or a web page, in any locale's format. The whole text must be one number, with at most a\n * sign, a currency and a percent sign around it; anything else gives `null`.\n *\n * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of\n * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.\n * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,\n * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.\n * - `-`, `+`, `\\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).\n * - Currency symbols and ISO codes, before or after: `$`, `\\u20AC`, `R$`, `kr`, `USD`, `CHF`.\n * - `%` and `\\u2030`, before or after; scientific notation (`1.5E-7`).\n * - Digits of any script, full-width characters, and Arabic separators.\n *\n * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one, or a `maxLength`\n * that is not a positive whole number.\n * @example\n * parseNumber('1.234,50 \\u20AC', { locale: 'de-DE' });\n * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\\u20AC', code: 'EUR' }, ambiguous: false }\n */\nexport function parseNumber(text: string, options: ParseNumberOptions = {}): ParsedNumber | null {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n if (text.length > positiveLimit(options.maxLength, DEFAULT_NUMBER_MAX_LENGTH, 'maxLength')) return null;\n const arabicDecimal = text.includes('\\u066B');\n const normalized = normalize(text.replace(/\\u066B/g, '.'));\n // The number: from its first digit (or a separator right before it, as in `.5`) to its last\n // digit. Not a dot that ends a word (`Rs.5` is 5 rupees).\n let start = normalized.search(/\\d/);\n if (start === -1) return null;\n if (/[.,]/.test(normalized.charAt(start - 1)) && !/\\p{L}/u.test(normalized.charAt(start - 2))) start -= 1;\n let end = normalized.length;\n while (!/\\d/.test(normalized.charAt(end - 1))) end -= 1;\n const adornments: Adornments = { sign: '', open: false, close: false, currency: null, kind: 'number' };\n if (!readAdornments(normalized.slice(0, start), adornments, 'prefix') || !readAdornments(normalized.slice(end), adornments, 'suffix')) return null;\n // Brackets come in pairs, and mean the minus: `-(5)` is a typo, not a number.\n if (adornments.open !== adornments.close || (adornments.open && adornments.sign !== '')) return null;\n\n const core = normalized.slice(start, end);\n // Scientific notation, as spreadsheets copy it: one decimal separator, never grouped.\n const scientific = /^(\\d*)(?:[.,](\\d*))?[eE]([+-]?\\d{1,3})$/.exec(core);\n let mantissa: Mantissa | null;\n if (scientific === null) mantissa = /^[\\d.,' ]+$/.test(core) ? readMantissa(core, symbols.decimal, arabicDecimal) : null;\n else mantissa = { integer: String(scientific[1]), fraction: scientific[2] ?? '', ambiguous: false };\n if (mantissa === null) return null;\n const exponent = scientific === null ? 0 : Number(scientific[3]);\n if (Math.abs(exponent) > MAX_EXPONENT) return null;\n\n const digits = shift(mantissa.integer === '' ? '0' : mantissa.integer, mantissa.fraction, exponent);\n const zero = /^0(?:\\.0*)?$/.test(digits);\n const negative = (adornments.sign === '-' || adornments.open) && !zero;\n const exact = negative ? `-${digits}` : digits;\n const value = Number(exact);\n if (!Number.isFinite(value)) return null;\n\n if (options.negative === false && negative) return null;\n if (options.fraction === false && /\\.\\d*[1-9]/.test(digits)) return null;\n if (options.currency === false && adornments.currency !== null) return null;\n if (options.percent === false && adornments.kind !== 'number') return null;\n if (adornments.currency !== null && adornments.kind !== 'number') return null;\n return { value, exact, kind: adornments.kind, currency: adornments.currency, ambiguous: mantissa.ambiguous };\n}\n","import { copyFailure } from '../core/errors';\nimport type { TextPayload } from '../core/payload';\nimport { numberSymbols } from './locale';\n\nexport interface FormatNumberOptions {\n /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */\n readonly locale?: string;\n /**\n * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets\n * read ungrouped numbers in every locale, and grouped ones only in their own.\n */\n readonly grouping?: boolean;\n /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */\n readonly fractionDigits?: number;\n}\n\n/** Plain decimal notation, as `parseNumber` gives in `exact`: `-1234.50`, `0.00000015`. */\nconst EXACT = /^(-?)(\\d+)(?:\\.(\\d+))?$/;\nconst NUMBER = /^(-?)(\\d+)(?:\\.(\\d+))?(?:e([+-]\\d+))?$/;\n\n/** `value` as sign, integer digits and fraction digits, exactly. */\nfunction decompose(value: number | string | bigint): readonly [boolean, string, string] {\n if (typeof value === 'bigint') {\n const text = value.toString();\n return text.startsWith('-') ? [true, text.slice(1), ''] : [false, text, ''];\n }\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw copyFailure('invalid-payload', `${String(value)} is not a finite number.`);\n // `String` gives the shortest text that reads back as the same number: 0.1 is `0.1`.\n const match = NUMBER.exec(String(value)) as RegExpExecArray;\n const sign = String(match[1]);\n const integer = String(match[2]);\n const fraction = match[3] ?? '';\n const shiftBy = Number(match[4] ?? '0');\n const digits = integer + fraction;\n const point = integer.length + shiftBy;\n if (point <= 0) return [sign === '-', '0', '0'.repeat(-point) + digits];\n if (point >= digits.length) return [sign === '-', digits + '0'.repeat(point - digits.length), ''];\n return [sign === '-', digits.slice(0, point), digits.slice(point)];\n }\n const match = EXACT.exec(value);\n if (match === null) throw copyFailure('invalid-payload', `\"${value.slice(0, 40)}\" is not a decimal number such as \"-1234.5\".`);\n return [match[1] === '-', String(match[2]), match[3] ?? ''];\n}\n\n/** `digits` plus one, carrying: `\"199\"` gives `\"200\"`, `\"99\"` gives `\"100\"`. */\nfunction increment(digits: string): string {\n let out = '';\n let carry = true;\n for (let index = digits.length - 1; index >= 0; index -= 1) {\n const digit: number = Number(digits.charAt(index)) + (carry ? 1 : 0);\n carry = digit === 10;\n out = String(digit % 10) + out;\n }\n return carry ? `1${out}` : out;\n}\n\n/** Groups `integer` from the right: the last group of `primary` digits, the others of `secondary`. */\nfunction group(integer: string, separator: string, primary: number, secondary: number): string {\n if (integer.length <= primary) return integer;\n const groups = [integer.slice(-primary)];\n let rest = integer.slice(0, -primary);\n while (rest.length > secondary) {\n groups.unshift(rest.slice(-secondary));\n rest = rest.slice(0, -secondary);\n }\n groups.unshift(rest);\n return groups.join(separator);\n}\n\n/**\n * Writes a number in a locale's format, exactly: no float rounding, whatever its size.\n * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so\n * money read from one locale can be written in another without losing a cent.\n *\n * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is\n * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.\n * @example\n * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // \"1.234,50\"\n */\nexport function formatNumber(value: number | string | bigint, options: FormatNumberOptions = {}): string {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n const digits = options.fractionDigits;\n if (digits !== undefined && !(Number.isInteger(digits) && digits >= 0 && digits <= 100)) {\n throw copyFailure('invalid-payload', `fractionDigits must be a whole number from 0 to 100, not ${String(digits)}.`);\n }\n const [negative, rawInteger, rawFraction] = decompose(value);\n let integer = rawInteger.replace(/^0+(?=\\d)/, '');\n let fraction = rawFraction;\n if (digits !== undefined) {\n if (fraction.length > digits) {\n const roundUp = fraction.charAt(digits) >= '5';\n fraction = fraction.slice(0, digits);\n if (roundUp) {\n const rounded = increment(integer + fraction);\n integer = rounded.slice(0, rounded.length - digits);\n fraction = rounded.slice(rounded.length - digits);\n }\n } else fraction = fraction.padEnd(digits, '0');\n }\n const zero = /^0*$/.test(integer + fraction);\n const whole = options.grouping === true ? group(integer, symbols.group, symbols.primary, symbols.secondary) : integer;\n return `${negative && !zero ? '-' : ''}${whole}${fraction === '' ? '' : symbols.decimal + fraction}`;\n}\n\n/**\n * A copy payload for a number, written for the locale it will be pasted in: ungrouped by\n * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.\n *\n * @example\n * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));\n */\nexport function numberPayload(value: number | string | bigint, options: FormatNumberOptions = {}): TextPayload {\n return { kind: 'text', value: formatNumber(value, options) };\n}\n","import { asTextField, insertText, replaceFieldValue, type TextField } from '../core/text-field';\nimport { formatNumber } from './format';\nimport { parseNumber, type ParsedNumber, type ParseNumberOptions } from './parse';\n\n/** What {@link pasteAsNumber} did. */\nexport type NumberPasteOutcome =\n /** The paste held a number: it was inserted, written the way the field takes it. */\n | 'pasted'\n /** The paste was not a number (or the field is read-only): nothing was inserted. */\n | 'rejected'\n /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */\n | 'ignored';\n\nexport interface PasteAsNumberOptions extends ParseNumberOptions {\n /**\n * How to write the number into the field. Default: `exact` for `<input type=\"number\">`,\n * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,\n * ungrouped (`1234,5` in `de-DE`).\n */\n readonly format?: (parsed: ParsedNumber) => string;\n /** Called with the number before it is inserted: show `ambiguous` readings here. */\n readonly onNumber?: (parsed: ParsedNumber) => void;\n /** Called with the pasted text when it was not a number, or the field takes no input. */\n readonly onReject?: (text: string) => void;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface NumberPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nfunction asNumberInput(target: EventTarget | null): HTMLInputElement | null {\n const element = target as (Partial<Element> & { type?: unknown }) | null;\n return element?.nodeName === 'INPUT' && element.type === 'number' ? (target as HTMLInputElement) : null;\n}\n\n/**\n * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank\n * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either\n * rejects these from `<input type=\"number\">` or keeps the text as it is. This reads the\n * number, inserts it the way the field takes it (with undo intact in text fields), and\n * turns away pastes that are not a number.\n *\n * Works on `<input type=\"number\">`, text `<input>`s (use `inputmode=\"decimal\"`) and\n * `<textarea>`s; other elements are left to the browser.\n *\n * @example\n * <input inputMode=\"decimal\" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />\n */\nexport function pasteAsNumber(event: NumberPasteEvent, options: PasteAsNumberOptions = {}): NumberPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'ignored';\n const numberInput = asNumberInput(event.currentTarget) ?? asNumberInput(event.target);\n const field: TextField | null = numberInput ?? asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null) return 'ignored';\n const text = event.clipboardData.getData('text/plain');\n if (text === '') return 'ignored';\n event.preventDefault();\n const parsed = parseNumber(text.trim(), options);\n if (parsed !== null && !field.disabled && !field.readOnly) {\n options.onNumber?.(parsed);\n const value = options.format?.(parsed) ?? (numberInput === null ? formatNumber(parsed.exact, options) : parsed.exact);\n if (numberInput === null ? insertText(field, value) : replaceFieldValue(numberInput, value)) return 'pasted';\n }\n options.onReject?.(text);\n return 'rejected';\n}\n"],"mappings":";;;;;;;;AAsBA,MAAM,YAAY,CAAC,GAAG;CATpB,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAC3G,CAAC,MAAM,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CA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AM,MAAM,gBAAgB,OAAO,aAAa,OAAO,OAAO,OAAO,IAAI,OAAO;EAC/G,IAAI,gBAAgB,OAAOC,mBAAAA,WAAW,OAAO,KAAK,IAAIC,mBAAAA,kBAAkB,aAAa,KAAK,GAAG,OAAO;CACtG;CACA,QAAQ,WAAW,IAAI;CACvB,OAAO;AACT"}
|
package/dist/number.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { f as TextPayload } from "./chunks/payload-
|
|
2
|
+
import { f as TextPayload } from "./chunks/payload-qkAWVXWA.cjs";
|
|
3
3
|
//#region src/number/currency.d.ts
|
|
4
4
|
/** A currency written next to a number. */
|
|
5
5
|
interface NumberCurrency {
|
|
@@ -47,9 +47,13 @@ interface ParseNumberOptions {
|
|
|
47
47
|
readonly currency?: boolean;
|
|
48
48
|
/** Accept `%` and `\u2030`. Default `true`. */
|
|
49
49
|
readonly percent?: boolean;
|
|
50
|
+
/** Text longer than this is not a number: `null`, unread. Default {@link DEFAULT_NUMBER_MAX_LENGTH}. */
|
|
51
|
+
readonly maxLength?: number;
|
|
50
52
|
}
|
|
51
|
-
/** Longer text holds more than a number: it is not read at all. */
|
|
52
|
-
export declare const
|
|
53
|
+
/** Longer text holds more than a number: it is not read at all, unless `maxLength` allows it. */
|
|
54
|
+
export declare const DEFAULT_NUMBER_MAX_LENGTH = 256;
|
|
55
|
+
/** @deprecated The old name of {@link DEFAULT_NUMBER_MAX_LENGTH}; removed in 2.0. */
|
|
56
|
+
export declare const NUMBER_MAX_LENGTH: number;
|
|
53
57
|
/**
|
|
54
58
|
* Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice
|
|
55
59
|
* or a web page, in any locale's format. The whole text must be one number, with at most a
|
|
@@ -64,7 +68,8 @@ export declare const NUMBER_MAX_LENGTH = 256;
|
|
|
64
68
|
* - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
|
|
65
69
|
* - Digits of any script, full-width characters, and Arabic separators.
|
|
66
70
|
*
|
|
67
|
-
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one
|
|
71
|
+
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one, or a `maxLength`
|
|
72
|
+
* that is not a positive whole number.
|
|
68
73
|
* @example
|
|
69
74
|
* parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
|
|
70
75
|
* // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
|
package/dist/number.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { f as TextPayload } from "./chunks/payload-
|
|
2
|
+
import { f as TextPayload } from "./chunks/payload-CcvSx_Hq.js";
|
|
3
3
|
//#region src/number/currency.d.ts
|
|
4
4
|
/** A currency written next to a number. */
|
|
5
5
|
interface NumberCurrency {
|
|
@@ -47,9 +47,13 @@ interface ParseNumberOptions {
|
|
|
47
47
|
readonly currency?: boolean;
|
|
48
48
|
/** Accept `%` and `\u2030`. Default `true`. */
|
|
49
49
|
readonly percent?: boolean;
|
|
50
|
+
/** Text longer than this is not a number: `null`, unread. Default {@link DEFAULT_NUMBER_MAX_LENGTH}. */
|
|
51
|
+
readonly maxLength?: number;
|
|
50
52
|
}
|
|
51
|
-
/** Longer text holds more than a number: it is not read at all. */
|
|
52
|
-
export declare const
|
|
53
|
+
/** Longer text holds more than a number: it is not read at all, unless `maxLength` allows it. */
|
|
54
|
+
export declare const DEFAULT_NUMBER_MAX_LENGTH = 256;
|
|
55
|
+
/** @deprecated The old name of {@link DEFAULT_NUMBER_MAX_LENGTH}; removed in 2.0. */
|
|
56
|
+
export declare const NUMBER_MAX_LENGTH: number;
|
|
53
57
|
/**
|
|
54
58
|
* Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice
|
|
55
59
|
* or a web page, in any locale's format. The whole text must be one number, with at most a
|
|
@@ -64,7 +68,8 @@ export declare const NUMBER_MAX_LENGTH = 256;
|
|
|
64
68
|
* - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
|
|
65
69
|
* - Digits of any script, full-width characters, and Arabic separators.
|
|
66
70
|
*
|
|
67
|
-
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one
|
|
71
|
+
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one, or a `maxLength`
|
|
72
|
+
* that is not a positive whole number.
|
|
68
73
|
* @example
|
|
69
74
|
* parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
|
|
70
75
|
* // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
|
package/dist/number.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { n as copyFailure } from "./chunks/errors-
|
|
2
|
+
import { n as copyFailure } from "./chunks/errors-CT-FfUtU.js";
|
|
3
|
+
import { t as positiveLimit } from "./chunks/limits-BP9R5wnr.js";
|
|
3
4
|
import { t as asciiDigits } from "./chunks/digits-DkU-O9_A.js";
|
|
4
5
|
import { n as insertText, r as replaceFieldValue, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
|
|
5
6
|
//#region src/number/currency.ts
|
|
@@ -110,7 +111,9 @@ function numberSymbols(locale) {
|
|
|
110
111
|
}
|
|
111
112
|
//#endregion
|
|
112
113
|
//#region src/number/parse.ts
|
|
113
|
-
/** Longer text holds more than a number: it is not read at all. */
|
|
114
|
+
/** Longer text holds more than a number: it is not read at all, unless `maxLength` allows it. */
|
|
115
|
+
const DEFAULT_NUMBER_MAX_LENGTH = 256;
|
|
116
|
+
/** @deprecated The old name of {@link DEFAULT_NUMBER_MAX_LENGTH}; removed in 2.0. */
|
|
114
117
|
const NUMBER_MAX_LENGTH = 256;
|
|
115
118
|
/** Group separators that are never decimal separators: spaces and apostrophes. */
|
|
116
119
|
const GROUP_ONLY = /* @__PURE__ */ new Set([" ", "'"]);
|
|
@@ -219,14 +222,15 @@ function shift(integer, fraction, exponent) {
|
|
|
219
222
|
* - `%` and `\u2030`, before or after; scientific notation (`1.5E-7`).
|
|
220
223
|
* - Digits of any script, full-width characters, and Arabic separators.
|
|
221
224
|
*
|
|
222
|
-
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one
|
|
225
|
+
* @throws {CopyFailure} `invalid-payload` for a `locale` that is not one, or a `maxLength`
|
|
226
|
+
* that is not a positive whole number.
|
|
223
227
|
* @example
|
|
224
228
|
* parseNumber('1.234,50 \u20AC', { locale: 'de-DE' });
|
|
225
229
|
* // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\u20AC', code: 'EUR' }, ambiguous: false }
|
|
226
230
|
*/
|
|
227
231
|
function parseNumber(text, options = {}) {
|
|
228
232
|
const symbols = numberSymbols(options.locale ?? "en-US");
|
|
229
|
-
if (text.length > 256) return null;
|
|
233
|
+
if (text.length > positiveLimit(options.maxLength, 256, "maxLength")) return null;
|
|
230
234
|
const arabicDecimal = text.includes("٫");
|
|
231
235
|
const normalized = normalize(text.replace(/\u066B/g, "."));
|
|
232
236
|
let start = normalized.search(/\d/);
|
|
@@ -431,6 +435,6 @@ function pasteAsNumber(event, options = {}) {
|
|
|
431
435
|
return "rejected";
|
|
432
436
|
}
|
|
433
437
|
//#endregion
|
|
434
|
-
export { NUMBER_MAX_LENGTH, formatNumber, numberPayload, numberSymbols, parseNumber, pasteAsNumber };
|
|
438
|
+
export { DEFAULT_NUMBER_MAX_LENGTH, NUMBER_MAX_LENGTH, formatNumber, numberPayload, numberSymbols, parseNumber, pasteAsNumber };
|
|
435
439
|
|
|
436
440
|
//# sourceMappingURL=number.js.map
|
package/dist/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","names":[],"sources":["../src/number/currency.ts","../src/number/locale.ts","../src/number/parse.ts","../src/number/format.ts","../src/number/paste.ts"],"sourcesContent":["/** A currency written next to a number. */\nexport interface NumberCurrency {\n /** As it was written, normalized: `\\u20AC`, `R$`, `kr`, `USD`. */\n readonly symbol: string;\n /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\\u00A5`, `kr` and `Rs`. */\n readonly code: string | null;\n}\n\n/**\n * Currency symbols, after NFKC (so `\\uFF04` is `$` and `\\u20A8` is `Rs`). Symbols that several\n * currencies share have no code: the text alone can't tell a dollar from another.\n */\nconst SYMBOLS: readonly (readonly [string, string | null])[] = [\n ['US$', 'USD'], ['CA$', 'CAD'], ['C$', 'CAD'], ['AU$', 'AUD'], ['A$', 'AUD'], ['NZ$', 'NZD'], ['HK$', 'HKD'],\n ['S$', 'SGD'], ['R$', 'BRL'], ['MX$', 'MXN'], ['NT$', 'TWD'], ['$', null],\n ['\\u20AC', 'EUR'], ['\\u00A3', 'GBP'], ['JP\\u00A5', 'JPY'], ['CN\\u00A5', 'CNY'], ['\\u00A5', null],\n ['\\u20B9', 'INR'], ['Rs.', null], ['Rs', null], ['\\u20A9', 'KRW'], ['\\u20BD', 'RUB'], ['\\u20BA', 'TRY'],\n ['\\u20AA', 'ILS'], ['\\u20AB', 'VND'], ['\\u20B1', 'PHP'], ['\\u0E3F', 'THB'], ['\\u20B4', 'UAH'], ['\\u20A6', 'NGN'],\n ['\\u20B8', 'KZT'], ['\\u09F3', 'BDT'], ['z\\u0142', 'PLN'], ['K\\u010D', 'CZK'], ['kr.', null], ['kr', null], ['Fr.', 'CHF'],\n];\n\n/** Longest first, so `US$` is read before `$` and `Rs.` before `Rs`. */\nconst BY_LENGTH = [...SYMBOLS].sort((a, b) => b[0].length - a[0].length).map(([symbol, code]) => [symbol, symbol.toLowerCase(), code] as const);\n\nlet codes: ReadonlySet<string> | null | undefined;\n\n/** Whether `code` (upper case) is an ISO 4217 code the runtime knows; any three letters where it can't say. */\nexport function isCurrencyCode(code: string): boolean {\n if (codes === undefined) {\n const supported = (Intl as { supportedValuesOf?: (key: 'currency') => string[] }).supportedValuesOf;\n codes = typeof supported === 'function' ? new Set(supported('currency')) : null;\n }\n return /^[A-Z]{3}$/.test(code) && (codes === null || codes.has(code));\n}\n\n/** For tests: forget the runtime's codes, so they are read again. */\nexport function resetCurrencyCodes(): void {\n codes = undefined;\n}\n\nconst LETTER = /\\p{L}/u;\n\n/**\n * The currency at the start of `text`, and how many characters it takes. A symbol or code\n * made of letters must end there: `Rs` is not read from `Rsx`, nor `USD` from `USDT`.\n */\nexport function readCurrency(text: string): { readonly currency: NumberCurrency; readonly length: number } | null {\n const lower = text.toLowerCase();\n for (const [symbol, key, code] of BY_LENGTH) {\n if (lower.startsWith(key) && !(LETTER.test(symbol.slice(-1)) && LETTER.test(text.charAt(key.length)))) {\n return { currency: { symbol, code }, length: key.length };\n }\n }\n const word = /^\\p{L}+/u.exec(text)?.[0] ?? '';\n const code = word.toUpperCase();\n return word.length === 3 && isCurrencyCode(code) ? { currency: { symbol: code, code }, length: 3 } : null;\n}\n","import { copyFailure } from '../core/errors';\n\n/** How a locale writes numbers, in Latin digits. */\nexport interface NumberSymbols {\n /** The decimal separator. */\n readonly decimal: '.' | ',';\n /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */\n readonly group: string;\n /** Digits in the last group of the integer part: 3 almost everywhere. */\n readonly primary: number;\n /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */\n readonly secondary: number;\n}\n\nconst cache = new Map<string, NumberSymbols>();\nconst CACHE_SIZE = 32;\n\n/**\n * How `locale` writes numbers, from `Intl.NumberFormat`.\n *\n * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.\n */\nexport function numberSymbols(locale: string): NumberSymbols {\n const cached = cache.get(locale);\n if (cached !== undefined) return cached;\n let parts: Intl.NumberFormatPart[];\n try {\n parts = new Intl.NumberFormat(locale, { numberingSystem: 'latn' }).formatToParts(123456789012.5);\n } catch (cause) {\n throw copyFailure('invalid-payload', `\"${locale}\" is not a locale.`, cause);\n }\n // 123,456,789,012 in most locales; 1,23,45,67,89,012 in India's.\n const integers = parts.filter((part) => part.type === 'integer').map((part) => part.value.length);\n const symbols: NumberSymbols = {\n decimal: parts.some((part) => part.type === 'decimal' && part.value === ',') ? ',' : '.',\n // A locale that writes no group separator has none to add.\n group: parts.find((part) => part.type === 'group')?.value ?? '',\n primary: Number(integers[integers.length - 1]),\n secondary: Number(integers[Math.max(0, integers.length - 2)]),\n };\n // A small cache: locales come from settings, but a hostile caller could pass many.\n if (cache.size >= CACHE_SIZE) cache.clear();\n cache.set(locale, symbols);\n return symbols;\n}\n","import { asciiDigits } from '../core/digits';\nimport { readCurrency, type NumberCurrency } from './currency';\nimport { numberSymbols } from './locale';\n\n/** What a number was written as: `12` is a number, `12%` a percentage, `12\\u2030` per mille. */\nexport type NumberKind = 'number' | 'percent' | 'permille';\n\n/** A number read from text. */\nexport interface ParsedNumber {\n /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \\u20AC)`. */\n readonly value: number;\n /**\n * The same number as an exact decimal string, without rounding: `-1234.50` keeps its\n * trailing zero, and `0.1` is not `0.1000000000000000055\\u2026`. Use it for money.\n */\n readonly exact: string;\n /** `'percent'` or `'permille'` when the number was written with `%` or `\\u2030`. */\n readonly kind: NumberKind;\n /** The currency written with it, if any. */\n readonly currency: NumberCurrency | null;\n /**\n * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group\n * separator in some locales and a decimal separator in others. `locale` decided which;\n * ask the person when it matters.\n */\n readonly ambiguous: boolean;\n}\n\nexport interface ParseNumberOptions {\n /**\n * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping\n * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way\n * is read that way in every locale: `1.234,5` is 1234.5 everywhere.\n */\n readonly locale?: string;\n /** Accept negative numbers. Default `true`. */\n readonly negative?: boolean;\n /** Accept numbers with a fractional part. Default `true`. */\n readonly fraction?: boolean;\n /** Accept a currency symbol or code. Default `true`. */\n readonly currency?: boolean;\n /** Accept `%` and `\\u2030`. Default `true`. */\n readonly percent?: boolean;\n}\n\n/** Longer text holds more than a number: it is not read at all. */\nexport const NUMBER_MAX_LENGTH = 256;\n\n/** Group separators that are never decimal separators: spaces and apostrophes. */\nconst GROUP_ONLY = new Set([' ', \"'\"]);\n/** The largest exponent read from scientific notation, past which no number is finite. */\nconst MAX_EXPONENT = 400;\n\ninterface Adornments {\n sign: '' | '-' | '+';\n /** An opening bracket before the number, and a closing one after it: accounting's minus. */\n open: boolean;\n close: boolean;\n currency: NumberCurrency | null;\n kind: NumberKind;\n}\n\n/**\n * Reads the signs, brackets, currency and percent on one side of the number. Returns\n * `false` when something else is there, or when one of them appears twice.\n */\nfunction readAdornments(text: string, into: Adornments, side: 'prefix' | 'suffix'): boolean {\n let rest = text;\n for (;;) {\n rest = rest.trimStart();\n if (rest === '') return true;\n const char = rest.charAt(0);\n let length = 1;\n if (char === '(' && side === 'prefix' && !into.open) into.open = true;\n else if (char === ')' && side === 'suffix' && !into.close) into.close = true;\n // A minus after the number is a trailing minus (`1234-`), as some accounting systems write it.\n else if ((char === '-' || (char === '+' && side === 'prefix')) && into.sign === '') into.sign = char;\n else if ((char === '%' || char === '\\u2030') && into.kind === 'number') into.kind = char === '%' ? 'percent' : 'permille';\n else {\n const read = into.currency === null ? readCurrency(rest) : null;\n if (read === null) return false;\n into.currency = read.currency;\n length = read.length;\n }\n rest = rest.slice(length);\n }\n}\n\n/** The text in a form the reader understands: ASCII digits, one minus, one apostrophe, plain spaces. */\nfunction normalize(text: string): string {\n return (\n asciiDigits(text)\n // Minus signs and dashes used as one.\n .replace(/[\\u2212\\u2012\\u2013]/g, '-')\n // Arabic percent sign; Arabic decimal and thousands separators come next.\n .replace(/\\u066A/g, '%')\n .replace(/[\\u2019\\u02BC\\u066C]/g, \"'\")\n .replace(/\\s/g, ' ')\n );\n}\n\n/** Whether `groups` (the integer part, split at its group separator) are grouped the way locales group. */\nfunction validGroups(groups: readonly string[]): boolean {\n const [first, ...rest] = groups;\n if (first === undefined || first === '' || first.length > 3 || rest.length === 0) return false;\n if (rest.every((group) => group.length === 3)) return true;\n // Lakh and crore: 12,34,567. The last group has 3 digits and the others 2.\n return first.length <= 2 && rest.slice(0, -1).every((group) => group.length === 2) && rest[rest.length - 1]?.length === 3;\n}\n\ninterface Mantissa {\n readonly integer: string;\n readonly fraction: string;\n readonly ambiguous: boolean;\n}\n\n/** The integer and fractional digits of `text` (digits and separators only), or `null`. */\nfunction readMantissa(text: string, decimalOfLocale: '.' | ',', arabicDecimal: boolean): Mantissa | null {\n const separators = text.replace(/\\d/g, '');\n if (separators === '') return { integer: text, fraction: '', ambiguous: false };\n // The decimal separator can only be the last separator, appearing once: `1,234,567.8`,\n // `1.234,5`. An Arabic decimal separator is one wherever it is.\n const candidate = arabicDecimal ? '.' : separators.charAt(separators.length - 1);\n const once = separators.split(candidate).length === 2;\n if (arabicDecimal && !once) return null;\n let decimal: string | null = null;\n let ambiguous = false;\n if (once && !GROUP_ONLY.has(candidate)) {\n const at = text.lastIndexOf(candidate);\n const before = text.slice(0, at);\n // A lone separator is a decimal unless it could also start a group of three.\n if (arabicDecimal || separators.length > 1 || text.length - at - 1 !== 3 || before === '' || before.length > 3 || before.startsWith('0')) decimal = candidate;\n else {\n ambiguous = true;\n decimal = candidate === decimalOfLocale ? candidate : null;\n }\n }\n const at = decimal === null ? text.length : text.lastIndexOf(decimal);\n const integerPart = text.slice(0, at);\n const fraction = text.slice(at + 1);\n if (!/^\\d*$/.test(fraction)) return null;\n const groupSeparators = integerPart.replace(/\\d/g, '');\n if (groupSeparators === '') return { integer: integerPart, fraction, ambiguous };\n const group = groupSeparators.charAt(0);\n if (groupSeparators !== group.repeat(groupSeparators.length) || !validGroups(integerPart.split(group))) return null;\n return { integer: integerPart.split(group).join(''), fraction, ambiguous };\n}\n\n/** `integer.fraction` times ten to the `exponent`, as an exact decimal string without a sign. */\nfunction shift(integer: string, fraction: string, exponent: number): string {\n const digits = integer + fraction;\n const point = integer.length + exponent;\n let whole: string;\n let decimals: string;\n if (exponent === 0) [whole, decimals] = [integer, fraction];\n else if (point <= 0) [whole, decimals] = ['0', '0'.repeat(-point) + digits];\n else if (point >= digits.length) [whole, decimals] = [digits + '0'.repeat(point - digits.length), ''];\n else [whole, decimals] = [digits.slice(0, point), digits.slice(point)];\n // Scientific notation's own trailing zeros say nothing about precision: they go.\n if (exponent !== 0) decimals = decimals.replace(/0+$/, '');\n whole = whole.replace(/^0+(?=\\d)/, '');\n return decimals === '' ? whole : `${whole}.${decimals}`;\n}\n\n/**\n * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice\n * or a web page, in any locale's format. The whole text must be one number, with at most a\n * sign, a currency and a percent sign around it; anything else gives `null`.\n *\n * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of\n * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.\n * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,\n * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.\n * - `-`, `+`, `\\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).\n * - Currency symbols and ISO codes, before or after: `$`, `\\u20AC`, `R$`, `kr`, `USD`, `CHF`.\n * - `%` and `\\u2030`, before or after; scientific notation (`1.5E-7`).\n * - Digits of any script, full-width characters, and Arabic separators.\n *\n * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one.\n * @example\n * parseNumber('1.234,50 \\u20AC', { locale: 'de-DE' });\n * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\\u20AC', code: 'EUR' }, ambiguous: false }\n */\nexport function parseNumber(text: string, options: ParseNumberOptions = {}): ParsedNumber | null {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n if (text.length > NUMBER_MAX_LENGTH) return null;\n const arabicDecimal = text.includes('\\u066B');\n const normalized = normalize(text.replace(/\\u066B/g, '.'));\n // The number: from its first digit (or a separator right before it, as in `.5`) to its last\n // digit. Not a dot that ends a word (`Rs.5` is 5 rupees).\n let start = normalized.search(/\\d/);\n if (start === -1) return null;\n if (/[.,]/.test(normalized.charAt(start - 1)) && !/\\p{L}/u.test(normalized.charAt(start - 2))) start -= 1;\n let end = normalized.length;\n while (!/\\d/.test(normalized.charAt(end - 1))) end -= 1;\n const adornments: Adornments = { sign: '', open: false, close: false, currency: null, kind: 'number' };\n if (!readAdornments(normalized.slice(0, start), adornments, 'prefix') || !readAdornments(normalized.slice(end), adornments, 'suffix')) return null;\n // Brackets come in pairs, and mean the minus: `-(5)` is a typo, not a number.\n if (adornments.open !== adornments.close || (adornments.open && adornments.sign !== '')) return null;\n\n const core = normalized.slice(start, end);\n // Scientific notation, as spreadsheets copy it: one decimal separator, never grouped.\n const scientific = /^(\\d*)(?:[.,](\\d*))?[eE]([+-]?\\d{1,3})$/.exec(core);\n let mantissa: Mantissa | null;\n if (scientific === null) mantissa = /^[\\d.,' ]+$/.test(core) ? readMantissa(core, symbols.decimal, arabicDecimal) : null;\n else mantissa = { integer: String(scientific[1]), fraction: scientific[2] ?? '', ambiguous: false };\n if (mantissa === null) return null;\n const exponent = scientific === null ? 0 : Number(scientific[3]);\n if (Math.abs(exponent) > MAX_EXPONENT) return null;\n\n const digits = shift(mantissa.integer === '' ? '0' : mantissa.integer, mantissa.fraction, exponent);\n const zero = /^0(?:\\.0*)?$/.test(digits);\n const negative = (adornments.sign === '-' || adornments.open) && !zero;\n const exact = negative ? `-${digits}` : digits;\n const value = Number(exact);\n if (!Number.isFinite(value)) return null;\n\n if (options.negative === false && negative) return null;\n if (options.fraction === false && /\\.\\d*[1-9]/.test(digits)) return null;\n if (options.currency === false && adornments.currency !== null) return null;\n if (options.percent === false && adornments.kind !== 'number') return null;\n if (adornments.currency !== null && adornments.kind !== 'number') return null;\n return { value, exact, kind: adornments.kind, currency: adornments.currency, ambiguous: mantissa.ambiguous };\n}\n","import { copyFailure } from '../core/errors';\nimport type { TextPayload } from '../core/payload';\nimport { numberSymbols } from './locale';\n\nexport interface FormatNumberOptions {\n /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */\n readonly locale?: string;\n /**\n * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets\n * read ungrouped numbers in every locale, and grouped ones only in their own.\n */\n readonly grouping?: boolean;\n /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */\n readonly fractionDigits?: number;\n}\n\n/** Plain decimal notation, as `parseNumber` gives in `exact`: `-1234.50`, `0.00000015`. */\nconst EXACT = /^(-?)(\\d+)(?:\\.(\\d+))?$/;\nconst NUMBER = /^(-?)(\\d+)(?:\\.(\\d+))?(?:e([+-]\\d+))?$/;\n\n/** `value` as sign, integer digits and fraction digits, exactly. */\nfunction decompose(value: number | string | bigint): readonly [boolean, string, string] {\n if (typeof value === 'bigint') {\n const text = value.toString();\n return text.startsWith('-') ? [true, text.slice(1), ''] : [false, text, ''];\n }\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw copyFailure('invalid-payload', `${String(value)} is not a finite number.`);\n // `String` gives the shortest text that reads back as the same number: 0.1 is `0.1`.\n const match = NUMBER.exec(String(value)) as RegExpExecArray;\n const sign = String(match[1]);\n const integer = String(match[2]);\n const fraction = match[3] ?? '';\n const shiftBy = Number(match[4] ?? '0');\n const digits = integer + fraction;\n const point = integer.length + shiftBy;\n if (point <= 0) return [sign === '-', '0', '0'.repeat(-point) + digits];\n if (point >= digits.length) return [sign === '-', digits + '0'.repeat(point - digits.length), ''];\n return [sign === '-', digits.slice(0, point), digits.slice(point)];\n }\n const match = EXACT.exec(value);\n if (match === null) throw copyFailure('invalid-payload', `\"${value.slice(0, 40)}\" is not a decimal number such as \"-1234.5\".`);\n return [match[1] === '-', String(match[2]), match[3] ?? ''];\n}\n\n/** `digits` plus one, carrying: `\"199\"` gives `\"200\"`, `\"99\"` gives `\"100\"`. */\nfunction increment(digits: string): string {\n let out = '';\n let carry = true;\n for (let index = digits.length - 1; index >= 0; index -= 1) {\n const digit: number = Number(digits.charAt(index)) + (carry ? 1 : 0);\n carry = digit === 10;\n out = String(digit % 10) + out;\n }\n return carry ? `1${out}` : out;\n}\n\n/** Groups `integer` from the right: the last group of `primary` digits, the others of `secondary`. */\nfunction group(integer: string, separator: string, primary: number, secondary: number): string {\n if (integer.length <= primary) return integer;\n const groups = [integer.slice(-primary)];\n let rest = integer.slice(0, -primary);\n while (rest.length > secondary) {\n groups.unshift(rest.slice(-secondary));\n rest = rest.slice(0, -secondary);\n }\n groups.unshift(rest);\n return groups.join(separator);\n}\n\n/**\n * Writes a number in a locale's format, exactly: no float rounding, whatever its size.\n * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so\n * money read from one locale can be written in another without losing a cent.\n *\n * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is\n * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.\n * @example\n * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // \"1.234,50\"\n */\nexport function formatNumber(value: number | string | bigint, options: FormatNumberOptions = {}): string {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n const digits = options.fractionDigits;\n if (digits !== undefined && !(Number.isInteger(digits) && digits >= 0 && digits <= 100)) {\n throw copyFailure('invalid-payload', `fractionDigits must be a whole number from 0 to 100, not ${String(digits)}.`);\n }\n const [negative, rawInteger, rawFraction] = decompose(value);\n let integer = rawInteger.replace(/^0+(?=\\d)/, '');\n let fraction = rawFraction;\n if (digits !== undefined) {\n if (fraction.length > digits) {\n const roundUp = fraction.charAt(digits) >= '5';\n fraction = fraction.slice(0, digits);\n if (roundUp) {\n const rounded = increment(integer + fraction);\n integer = rounded.slice(0, rounded.length - digits);\n fraction = rounded.slice(rounded.length - digits);\n }\n } else fraction = fraction.padEnd(digits, '0');\n }\n const zero = /^0*$/.test(integer + fraction);\n const whole = options.grouping === true ? group(integer, symbols.group, symbols.primary, symbols.secondary) : integer;\n return `${negative && !zero ? '-' : ''}${whole}${fraction === '' ? '' : symbols.decimal + fraction}`;\n}\n\n/**\n * A copy payload for a number, written for the locale it will be pasted in: ungrouped by\n * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.\n *\n * @example\n * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));\n */\nexport function numberPayload(value: number | string | bigint, options: FormatNumberOptions = {}): TextPayload {\n return { kind: 'text', value: formatNumber(value, options) };\n}\n","import { asTextField, insertText, replaceFieldValue, type TextField } from '../core/text-field';\nimport { formatNumber } from './format';\nimport { parseNumber, type ParsedNumber, type ParseNumberOptions } from './parse';\n\n/** What {@link pasteAsNumber} did. */\nexport type NumberPasteOutcome =\n /** The paste held a number: it was inserted, written the way the field takes it. */\n | 'pasted'\n /** The paste was not a number (or the field is read-only): nothing was inserted. */\n | 'rejected'\n /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */\n | 'ignored';\n\nexport interface PasteAsNumberOptions extends ParseNumberOptions {\n /**\n * How to write the number into the field. Default: `exact` for `<input type=\"number\">`,\n * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,\n * ungrouped (`1234,5` in `de-DE`).\n */\n readonly format?: (parsed: ParsedNumber) => string;\n /** Called with the number before it is inserted: show `ambiguous` readings here. */\n readonly onNumber?: (parsed: ParsedNumber) => void;\n /** Called with the pasted text when it was not a number, or the field takes no input. */\n readonly onReject?: (text: string) => void;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface NumberPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nfunction asNumberInput(target: EventTarget | null): HTMLInputElement | null {\n const element = target as (Partial<Element> & { type?: unknown }) | null;\n return element?.nodeName === 'INPUT' && element.type === 'number' ? (target as HTMLInputElement) : null;\n}\n\n/**\n * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank\n * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either\n * rejects these from `<input type=\"number\">` or keeps the text as it is. This reads the\n * number, inserts it the way the field takes it (with undo intact in text fields), and\n * turns away pastes that are not a number.\n *\n * Works on `<input type=\"number\">`, text `<input>`s (use `inputmode=\"decimal\"`) and\n * `<textarea>`s; other elements are left to the browser.\n *\n * @example\n * <input inputMode=\"decimal\" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />\n */\nexport function pasteAsNumber(event: NumberPasteEvent, options: PasteAsNumberOptions = {}): NumberPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'ignored';\n const numberInput = asNumberInput(event.currentTarget) ?? asNumberInput(event.target);\n const field: TextField | null = numberInput ?? asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null) return 'ignored';\n const text = event.clipboardData.getData('text/plain');\n if (text === '') return 'ignored';\n event.preventDefault();\n const parsed = parseNumber(text.trim(), options);\n if (parsed !== null && !field.disabled && !field.readOnly) {\n options.onNumber?.(parsed);\n const value = options.format?.(parsed) ?? (numberInput === null ? formatNumber(parsed.exact, options) : parsed.exact);\n if (numberInput === null ? insertText(field, value) : replaceFieldValue(numberInput, value)) return 'pasted';\n }\n options.onReject?.(text);\n return 'rejected';\n}\n"],"mappings":";;;;;;AAsBA,MAAM,YAAY,CAAC,GAAG;CATpB,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAC3G,CAAC,MAAM,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,KAAK,IAAI;CACxE,CAAC,KAAU,KAAK;CAAG,CAAC,KAAU,KAAK;CAAG,CAAC,OAAY,KAAK;CAAG,CAAC,OAAY,KAAK;CAAG,CAAC,KAAU,IAAI;CAC/F,CAAC,KAAU,KAAK;CAAG,CAAC,OAAO,IAAI;CAAG,CAAC,MAAM,IAAI;CAAG,CAAC,K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AC,OAAO,MAAM,KAAK,QAAQ,aAAa,KAAK,KAAK,QAAQ,UAAU;AAC5F;;;;;;;;AASA,SAAgB,cAAc,OAAiC,UAA+B,CAAC,GAAgB;CAC7G,OAAO;EAAE,MAAM;EAAQ,OAAO,aAAa,OAAO,OAAO;CAAE;AAC7D;;;AC/EA,SAAS,cAAc,QAAqD;CAC1E,MAAM,UAAU;CAChB,OAAO,SAAS,aAAa,WAAW,QAAQ,SAAS,WAAY,SAA8B;AACrG;;;;;;;;;;;;;;AAeA,SAAgB,cAAc,OAAyB,UAAgC,CAAC,GAAuB;CAC7G,IAAI,MAAM,oBAAoB,MAAM,kBAAkB,MAAM,OAAO;CACnE,MAAM,cAAc,cAAc,MAAM,aAAa,KAAK,cAAc,MAAM,MAAM;CACpF,MAAM,QAA0B,eAAe,YAAY,MAAM,aAAa,KAAK,YAAY,MAAM,MAAM;CAC3G,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,OAAO,MAAM,cAAc,QAAQ,YAAY;CACrD,IAAI,SAAS,IAAI,OAAO;CACxB,MAAM,eAAe;CACrB,MAAM,SAAS,YAAY,KAAK,KAAK,GAAG,OAAO;CAC/C,IAAI,WAAW,QAAQ,CAAC,MAAM,YAAY,CAAC,MAAM,UAAU;EACzD,QAAQ,WAAW,MAAM;EACzB,MAAM,QAAQ,QAAQ,SAAS,MAAM,MAAM,gBAAgB,OAAO,aAAa,OAAO,OAAO,OAAO,IAAI,OAAO;EAC/G,IAAI,gBAAgB,OAAO,WAAW,OAAO,KAAK,IAAI,kBAAkB,aAAa,KAAK,GAAG,OAAO;CACtG;CACA,QAAQ,WAAW,IAAI;CACvB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"number.js","names":[],"sources":["../src/number/currency.ts","../src/number/locale.ts","../src/number/parse.ts","../src/number/format.ts","../src/number/paste.ts"],"sourcesContent":["/** A currency written next to a number. */\nexport interface NumberCurrency {\n /** As it was written, normalized: `\\u20AC`, `R$`, `kr`, `USD`. */\n readonly symbol: string;\n /** Its ISO 4217 code, when the symbol names one currency: `null` for `$`, `\\u00A5`, `kr` and `Rs`. */\n readonly code: string | null;\n}\n\n/**\n * Currency symbols, after NFKC (so `\\uFF04` is `$` and `\\u20A8` is `Rs`). Symbols that several\n * currencies share have no code: the text alone can't tell a dollar from another.\n */\nconst SYMBOLS: readonly (readonly [string, string | null])[] = [\n ['US$', 'USD'], ['CA$', 'CAD'], ['C$', 'CAD'], ['AU$', 'AUD'], ['A$', 'AUD'], ['NZ$', 'NZD'], ['HK$', 'HKD'],\n ['S$', 'SGD'], ['R$', 'BRL'], ['MX$', 'MXN'], ['NT$', 'TWD'], ['$', null],\n ['\\u20AC', 'EUR'], ['\\u00A3', 'GBP'], ['JP\\u00A5', 'JPY'], ['CN\\u00A5', 'CNY'], ['\\u00A5', null],\n ['\\u20B9', 'INR'], ['Rs.', null], ['Rs', null], ['\\u20A9', 'KRW'], ['\\u20BD', 'RUB'], ['\\u20BA', 'TRY'],\n ['\\u20AA', 'ILS'], ['\\u20AB', 'VND'], ['\\u20B1', 'PHP'], ['\\u0E3F', 'THB'], ['\\u20B4', 'UAH'], ['\\u20A6', 'NGN'],\n ['\\u20B8', 'KZT'], ['\\u09F3', 'BDT'], ['z\\u0142', 'PLN'], ['K\\u010D', 'CZK'], ['kr.', null], ['kr', null], ['Fr.', 'CHF'],\n];\n\n/** Longest first, so `US$` is read before `$` and `Rs.` before `Rs`. */\nconst BY_LENGTH = [...SYMBOLS].sort((a, b) => b[0].length - a[0].length).map(([symbol, code]) => [symbol, symbol.toLowerCase(), code] as const);\n\nlet codes: ReadonlySet<string> | null | undefined;\n\n/** Whether `code` (upper case) is an ISO 4217 code the runtime knows; any three letters where it can't say. */\nexport function isCurrencyCode(code: string): boolean {\n if (codes === undefined) {\n const supported = (Intl as { supportedValuesOf?: (key: 'currency') => string[] }).supportedValuesOf;\n codes = typeof supported === 'function' ? new Set(supported('currency')) : null;\n }\n return /^[A-Z]{3}$/.test(code) && (codes === null || codes.has(code));\n}\n\n/** For tests: forget the runtime's codes, so they are read again. */\nexport function resetCurrencyCodes(): void {\n codes = undefined;\n}\n\nconst LETTER = /\\p{L}/u;\n\n/**\n * The currency at the start of `text`, and how many characters it takes. A symbol or code\n * made of letters must end there: `Rs` is not read from `Rsx`, nor `USD` from `USDT`.\n */\nexport function readCurrency(text: string): { readonly currency: NumberCurrency; readonly length: number } | null {\n const lower = text.toLowerCase();\n for (const [symbol, key, code] of BY_LENGTH) {\n if (lower.startsWith(key) && !(LETTER.test(symbol.slice(-1)) && LETTER.test(text.charAt(key.length)))) {\n return { currency: { symbol, code }, length: key.length };\n }\n }\n const word = /^\\p{L}+/u.exec(text)?.[0] ?? '';\n const code = word.toUpperCase();\n return word.length === 3 && isCurrencyCode(code) ? { currency: { symbol: code, code }, length: 3 } : null;\n}\n","import { copyFailure } from '../core/errors';\n\n/** How a locale writes numbers, in Latin digits. */\nexport interface NumberSymbols {\n /** The decimal separator. */\n readonly decimal: '.' | ',';\n /** The group separator, as the locale writes it (a no-break space in French, for one); `''` for none. */\n readonly group: string;\n /** Digits in the last group of the integer part: 3 almost everywhere. */\n readonly primary: number;\n /** Digits in the groups before it: 2 in India's lakh and crore grouping, 3 elsewhere. */\n readonly secondary: number;\n}\n\nconst cache = new Map<string, NumberSymbols>();\nconst CACHE_SIZE = 32;\n\n/**\n * How `locale` writes numbers, from `Intl.NumberFormat`.\n *\n * @throws {CopyFailure} `invalid-payload` for a string that is not a locale.\n */\nexport function numberSymbols(locale: string): NumberSymbols {\n const cached = cache.get(locale);\n if (cached !== undefined) return cached;\n let parts: Intl.NumberFormatPart[];\n try {\n parts = new Intl.NumberFormat(locale, { numberingSystem: 'latn' }).formatToParts(123456789012.5);\n } catch (cause) {\n throw copyFailure('invalid-payload', `\"${locale}\" is not a locale.`, cause);\n }\n // 123,456,789,012 in most locales; 1,23,45,67,89,012 in India's.\n const integers = parts.filter((part) => part.type === 'integer').map((part) => part.value.length);\n const symbols: NumberSymbols = {\n decimal: parts.some((part) => part.type === 'decimal' && part.value === ',') ? ',' : '.',\n // A locale that writes no group separator has none to add.\n group: parts.find((part) => part.type === 'group')?.value ?? '',\n primary: Number(integers[integers.length - 1]),\n secondary: Number(integers[Math.max(0, integers.length - 2)]),\n };\n // A small cache: locales come from settings, but a hostile caller could pass many.\n if (cache.size >= CACHE_SIZE) cache.clear();\n cache.set(locale, symbols);\n return symbols;\n}\n","import { asciiDigits } from '../core/digits';\nimport { positiveLimit } from '../core/limits';\nimport { readCurrency, type NumberCurrency } from './currency';\nimport { numberSymbols } from './locale';\n\n/** What a number was written as: `12` is a number, `12%` a percentage, `12\\u2030` per mille. */\nexport type NumberKind = 'number' | 'percent' | 'permille';\n\n/** A number read from text. */\nexport interface ParsedNumber {\n /** The number as written: `12` for `12%`, `-1234.5` for `(1.234,50 \\u20AC)`. */\n readonly value: number;\n /**\n * The same number as an exact decimal string, without rounding: `-1234.50` keeps its\n * trailing zero, and `0.1` is not `0.1000000000000000055\\u2026`. Use it for money.\n */\n readonly exact: string;\n /** `'percent'` or `'permille'` when the number was written with `%` or `\\u2030`. */\n readonly kind: NumberKind;\n /** The currency written with it, if any. */\n readonly currency: NumberCurrency | null;\n /**\n * The text had one `,` or `.` before exactly three digits (`1,234`, `1.234`): a group\n * separator in some locales and a decimal separator in others. `locale` decided which;\n * ask the person when it matters.\n */\n readonly ambiguous: boolean;\n}\n\nexport interface ParseNumberOptions {\n /**\n * The locale whose decimal separator settles an ambiguous `1,234` or `1.234`: grouping\n * in `en-US`, a decimal in `de-DE`. Default `'en-US'`. Text that can only be read one way\n * is read that way in every locale: `1.234,5` is 1234.5 everywhere.\n */\n readonly locale?: string;\n /** Accept negative numbers. Default `true`. */\n readonly negative?: boolean;\n /** Accept numbers with a fractional part. Default `true`. */\n readonly fraction?: boolean;\n /** Accept a currency symbol or code. Default `true`. */\n readonly currency?: boolean;\n /** Accept `%` and `\\u2030`. Default `true`. */\n readonly percent?: boolean;\n /** Text longer than this is not a number: `null`, unread. Default {@link DEFAULT_NUMBER_MAX_LENGTH}. */\n readonly maxLength?: number;\n}\n\n/** Longer text holds more than a number: it is not read at all, unless `maxLength` allows it. */\nexport const DEFAULT_NUMBER_MAX_LENGTH = 256;\n/** @deprecated The old name of {@link DEFAULT_NUMBER_MAX_LENGTH}; removed in 2.0. */\nexport const NUMBER_MAX_LENGTH: number = DEFAULT_NUMBER_MAX_LENGTH;\n\n/** Group separators that are never decimal separators: spaces and apostrophes. */\nconst GROUP_ONLY = new Set([' ', \"'\"]);\n/** The largest exponent read from scientific notation, past which no number is finite. */\nconst MAX_EXPONENT = 400;\n\ninterface Adornments {\n sign: '' | '-' | '+';\n /** An opening bracket before the number, and a closing one after it: accounting's minus. */\n open: boolean;\n close: boolean;\n currency: NumberCurrency | null;\n kind: NumberKind;\n}\n\n/**\n * Reads the signs, brackets, currency and percent on one side of the number. Returns\n * `false` when something else is there, or when one of them appears twice.\n */\nfunction readAdornments(text: string, into: Adornments, side: 'prefix' | 'suffix'): boolean {\n let rest = text;\n for (;;) {\n rest = rest.trimStart();\n if (rest === '') return true;\n const char = rest.charAt(0);\n let length = 1;\n if (char === '(' && side === 'prefix' && !into.open) into.open = true;\n else if (char === ')' && side === 'suffix' && !into.close) into.close = true;\n // A minus after the number is a trailing minus (`1234-`), as some accounting systems write it.\n else if ((char === '-' || (char === '+' && side === 'prefix')) && into.sign === '') into.sign = char;\n else if ((char === '%' || char === '\\u2030') && into.kind === 'number') into.kind = char === '%' ? 'percent' : 'permille';\n else {\n const read = into.currency === null ? readCurrency(rest) : null;\n if (read === null) return false;\n into.currency = read.currency;\n length = read.length;\n }\n rest = rest.slice(length);\n }\n}\n\n/** The text in a form the reader understands: ASCII digits, one minus, one apostrophe, plain spaces. */\nfunction normalize(text: string): string {\n return (\n asciiDigits(text)\n // Minus signs and dashes used as one.\n .replace(/[\\u2212\\u2012\\u2013]/g, '-')\n // Arabic percent sign; Arabic decimal and thousands separators come next.\n .replace(/\\u066A/g, '%')\n .replace(/[\\u2019\\u02BC\\u066C]/g, \"'\")\n .replace(/\\s/g, ' ')\n );\n}\n\n/** Whether `groups` (the integer part, split at its group separator) are grouped the way locales group. */\nfunction validGroups(groups: readonly string[]): boolean {\n const [first, ...rest] = groups;\n if (first === undefined || first === '' || first.length > 3 || rest.length === 0) return false;\n if (rest.every((group) => group.length === 3)) return true;\n // Lakh and crore: 12,34,567. The last group has 3 digits and the others 2.\n return first.length <= 2 && rest.slice(0, -1).every((group) => group.length === 2) && rest[rest.length - 1]?.length === 3;\n}\n\ninterface Mantissa {\n readonly integer: string;\n readonly fraction: string;\n readonly ambiguous: boolean;\n}\n\n/** The integer and fractional digits of `text` (digits and separators only), or `null`. */\nfunction readMantissa(text: string, decimalOfLocale: '.' | ',', arabicDecimal: boolean): Mantissa | null {\n const separators = text.replace(/\\d/g, '');\n if (separators === '') return { integer: text, fraction: '', ambiguous: false };\n // The decimal separator can only be the last separator, appearing once: `1,234,567.8`,\n // `1.234,5`. An Arabic decimal separator is one wherever it is.\n const candidate = arabicDecimal ? '.' : separators.charAt(separators.length - 1);\n const once = separators.split(candidate).length === 2;\n if (arabicDecimal && !once) return null;\n let decimal: string | null = null;\n let ambiguous = false;\n if (once && !GROUP_ONLY.has(candidate)) {\n const at = text.lastIndexOf(candidate);\n const before = text.slice(0, at);\n // A lone separator is a decimal unless it could also start a group of three.\n if (arabicDecimal || separators.length > 1 || text.length - at - 1 !== 3 || before === '' || before.length > 3 || before.startsWith('0')) decimal = candidate;\n else {\n ambiguous = true;\n decimal = candidate === decimalOfLocale ? candidate : null;\n }\n }\n const at = decimal === null ? text.length : text.lastIndexOf(decimal);\n const integerPart = text.slice(0, at);\n const fraction = text.slice(at + 1);\n if (!/^\\d*$/.test(fraction)) return null;\n const groupSeparators = integerPart.replace(/\\d/g, '');\n if (groupSeparators === '') return { integer: integerPart, fraction, ambiguous };\n const group = groupSeparators.charAt(0);\n if (groupSeparators !== group.repeat(groupSeparators.length) || !validGroups(integerPart.split(group))) return null;\n return { integer: integerPart.split(group).join(''), fraction, ambiguous };\n}\n\n/** `integer.fraction` times ten to the `exponent`, as an exact decimal string without a sign. */\nfunction shift(integer: string, fraction: string, exponent: number): string {\n const digits = integer + fraction;\n const point = integer.length + exponent;\n let whole: string;\n let decimals: string;\n if (exponent === 0) [whole, decimals] = [integer, fraction];\n else if (point <= 0) [whole, decimals] = ['0', '0'.repeat(-point) + digits];\n else if (point >= digits.length) [whole, decimals] = [digits + '0'.repeat(point - digits.length), ''];\n else [whole, decimals] = [digits.slice(0, point), digits.slice(point)];\n // Scientific notation's own trailing zeros say nothing about precision: they go.\n if (exponent !== 0) decimals = decimals.replace(/0+$/, '');\n whole = whole.replace(/^0+(?=\\d)/, '');\n return decimals === '' ? whole : `${whole}.${decimals}`;\n}\n\n/**\n * Reads a number the way people paste one: from a spreadsheet, a bank statement, an invoice\n * or a web page, in any locale's format. The whole text must be one number, with at most a\n * sign, a currency and a percent sign around it; anything else gives `null`.\n *\n * - Group separators `,` `.` `'` and spaces (no-break and narrow ones too), in groups of\n * three or the lakh and crore grouping (`12,34,567`). Wrong grouping gives `null`.\n * - The decimal separator is whichever of `,` and `.` the text shows is one (`1.234,5`,\n * `1,5`, `0.500`); only a lone separator before three digits (`1,234`) is settled by `locale`.\n * - `-`, `+`, `\\u2212`, a trailing minus (`1234-`) and accounting brackets (`(1,234)`).\n * - Currency symbols and ISO codes, before or after: `$`, `\\u20AC`, `R$`, `kr`, `USD`, `CHF`.\n * - `%` and `\\u2030`, before or after; scientific notation (`1.5E-7`).\n * - Digits of any script, full-width characters, and Arabic separators.\n *\n * @throws {CopyFailure} `invalid-payload` for a `locale` that is not one, or a `maxLength`\n * that is not a positive whole number.\n * @example\n * parseNumber('1.234,50 \\u20AC', { locale: 'de-DE' });\n * // { value: 1234.5, exact: '1234.50', kind: 'number', currency: { symbol: '\\u20AC', code: 'EUR' }, ambiguous: false }\n */\nexport function parseNumber(text: string, options: ParseNumberOptions = {}): ParsedNumber | null {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n if (text.length > positiveLimit(options.maxLength, DEFAULT_NUMBER_MAX_LENGTH, 'maxLength')) return null;\n const arabicDecimal = text.includes('\\u066B');\n const normalized = normalize(text.replace(/\\u066B/g, '.'));\n // The number: from its first digit (or a separator right before it, as in `.5`) to its last\n // digit. Not a dot that ends a word (`Rs.5` is 5 rupees).\n let start = normalized.search(/\\d/);\n if (start === -1) return null;\n if (/[.,]/.test(normalized.charAt(start - 1)) && !/\\p{L}/u.test(normalized.charAt(start - 2))) start -= 1;\n let end = normalized.length;\n while (!/\\d/.test(normalized.charAt(end - 1))) end -= 1;\n const adornments: Adornments = { sign: '', open: false, close: false, currency: null, kind: 'number' };\n if (!readAdornments(normalized.slice(0, start), adornments, 'prefix') || !readAdornments(normalized.slice(end), adornments, 'suffix')) return null;\n // Brackets come in pairs, and mean the minus: `-(5)` is a typo, not a number.\n if (adornments.open !== adornments.close || (adornments.open && adornments.sign !== '')) return null;\n\n const core = normalized.slice(start, end);\n // Scientific notation, as spreadsheets copy it: one decimal separator, never grouped.\n const scientific = /^(\\d*)(?:[.,](\\d*))?[eE]([+-]?\\d{1,3})$/.exec(core);\n let mantissa: Mantissa | null;\n if (scientific === null) mantissa = /^[\\d.,' ]+$/.test(core) ? readMantissa(core, symbols.decimal, arabicDecimal) : null;\n else mantissa = { integer: String(scientific[1]), fraction: scientific[2] ?? '', ambiguous: false };\n if (mantissa === null) return null;\n const exponent = scientific === null ? 0 : Number(scientific[3]);\n if (Math.abs(exponent) > MAX_EXPONENT) return null;\n\n const digits = shift(mantissa.integer === '' ? '0' : mantissa.integer, mantissa.fraction, exponent);\n const zero = /^0(?:\\.0*)?$/.test(digits);\n const negative = (adornments.sign === '-' || adornments.open) && !zero;\n const exact = negative ? `-${digits}` : digits;\n const value = Number(exact);\n if (!Number.isFinite(value)) return null;\n\n if (options.negative === false && negative) return null;\n if (options.fraction === false && /\\.\\d*[1-9]/.test(digits)) return null;\n if (options.currency === false && adornments.currency !== null) return null;\n if (options.percent === false && adornments.kind !== 'number') return null;\n if (adornments.currency !== null && adornments.kind !== 'number') return null;\n return { value, exact, kind: adornments.kind, currency: adornments.currency, ambiguous: mantissa.ambiguous };\n}\n","import { copyFailure } from '../core/errors';\nimport type { TextPayload } from '../core/payload';\nimport { numberSymbols } from './locale';\n\nexport interface FormatNumberOptions {\n /** The locale whose decimal and group separators to use. Default `'en-US'`. Digits are always Latin. */\n readonly locale?: string;\n /**\n * Group the integer part (`1,234,567`; `12,34,567` in `en-IN`). Default `false`: spreadsheets\n * read ungrouped numbers in every locale, and grouped ones only in their own.\n */\n readonly grouping?: boolean;\n /** Exactly this many decimals (0 to 100), rounding half away from zero. Default: as many as the number has. */\n readonly fractionDigits?: number;\n}\n\n/** Plain decimal notation, as `parseNumber` gives in `exact`: `-1234.50`, `0.00000015`. */\nconst EXACT = /^(-?)(\\d+)(?:\\.(\\d+))?$/;\nconst NUMBER = /^(-?)(\\d+)(?:\\.(\\d+))?(?:e([+-]\\d+))?$/;\n\n/** `value` as sign, integer digits and fraction digits, exactly. */\nfunction decompose(value: number | string | bigint): readonly [boolean, string, string] {\n if (typeof value === 'bigint') {\n const text = value.toString();\n return text.startsWith('-') ? [true, text.slice(1), ''] : [false, text, ''];\n }\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw copyFailure('invalid-payload', `${String(value)} is not a finite number.`);\n // `String` gives the shortest text that reads back as the same number: 0.1 is `0.1`.\n const match = NUMBER.exec(String(value)) as RegExpExecArray;\n const sign = String(match[1]);\n const integer = String(match[2]);\n const fraction = match[3] ?? '';\n const shiftBy = Number(match[4] ?? '0');\n const digits = integer + fraction;\n const point = integer.length + shiftBy;\n if (point <= 0) return [sign === '-', '0', '0'.repeat(-point) + digits];\n if (point >= digits.length) return [sign === '-', digits + '0'.repeat(point - digits.length), ''];\n return [sign === '-', digits.slice(0, point), digits.slice(point)];\n }\n const match = EXACT.exec(value);\n if (match === null) throw copyFailure('invalid-payload', `\"${value.slice(0, 40)}\" is not a decimal number such as \"-1234.5\".`);\n return [match[1] === '-', String(match[2]), match[3] ?? ''];\n}\n\n/** `digits` plus one, carrying: `\"199\"` gives `\"200\"`, `\"99\"` gives `\"100\"`. */\nfunction increment(digits: string): string {\n let out = '';\n let carry = true;\n for (let index = digits.length - 1; index >= 0; index -= 1) {\n const digit: number = Number(digits.charAt(index)) + (carry ? 1 : 0);\n carry = digit === 10;\n out = String(digit % 10) + out;\n }\n return carry ? `1${out}` : out;\n}\n\n/** Groups `integer` from the right: the last group of `primary` digits, the others of `secondary`. */\nfunction group(integer: string, separator: string, primary: number, secondary: number): string {\n if (integer.length <= primary) return integer;\n const groups = [integer.slice(-primary)];\n let rest = integer.slice(0, -primary);\n while (rest.length > secondary) {\n groups.unshift(rest.slice(-secondary));\n rest = rest.slice(0, -secondary);\n }\n groups.unshift(rest);\n return groups.join(separator);\n}\n\n/**\n * Writes a number in a locale's format, exactly: no float rounding, whatever its size.\n * Takes a `number`, a `bigint`, or an exact decimal string (`parseNumber`'s `exact`), so\n * money read from one locale can be written in another without losing a cent.\n *\n * @throws {CopyFailure} `invalid-payload` for a number that is not finite, a string that is\n * not plain decimal notation, a `fractionDigits` out of range, or a `locale` that is not one.\n * @example\n * formatNumber('1234.5', { locale: 'de-DE', grouping: true, fractionDigits: 2 }); // \"1.234,50\"\n */\nexport function formatNumber(value: number | string | bigint, options: FormatNumberOptions = {}): string {\n const symbols = numberSymbols(options.locale ?? 'en-US');\n const digits = options.fractionDigits;\n if (digits !== undefined && !(Number.isInteger(digits) && digits >= 0 && digits <= 100)) {\n throw copyFailure('invalid-payload', `fractionDigits must be a whole number from 0 to 100, not ${String(digits)}.`);\n }\n const [negative, rawInteger, rawFraction] = decompose(value);\n let integer = rawInteger.replace(/^0+(?=\\d)/, '');\n let fraction = rawFraction;\n if (digits !== undefined) {\n if (fraction.length > digits) {\n const roundUp = fraction.charAt(digits) >= '5';\n fraction = fraction.slice(0, digits);\n if (roundUp) {\n const rounded = increment(integer + fraction);\n integer = rounded.slice(0, rounded.length - digits);\n fraction = rounded.slice(rounded.length - digits);\n }\n } else fraction = fraction.padEnd(digits, '0');\n }\n const zero = /^0*$/.test(integer + fraction);\n const whole = options.grouping === true ? group(integer, symbols.group, symbols.primary, symbols.secondary) : integer;\n return `${negative && !zero ? '-' : ''}${whole}${fraction === '' ? '' : symbols.decimal + fraction}`;\n}\n\n/**\n * A copy payload for a number, written for the locale it will be pasted in: ungrouped by\n * default, so a spreadsheet reads it as a number. Pass it to `copy()` or `useCopy`.\n *\n * @example\n * copy(numberPayload(invoice.total, { locale: navigator.language, fractionDigits: 2 }));\n */\nexport function numberPayload(value: number | string | bigint, options: FormatNumberOptions = {}): TextPayload {\n return { kind: 'text', value: formatNumber(value, options) };\n}\n","import { asTextField, insertText, replaceFieldValue, type TextField } from '../core/text-field';\nimport { formatNumber } from './format';\nimport { parseNumber, type ParsedNumber, type ParseNumberOptions } from './parse';\n\n/** What {@link pasteAsNumber} did. */\nexport type NumberPasteOutcome =\n /** The paste held a number: it was inserted, written the way the field takes it. */\n | 'pasted'\n /** The paste was not a number (or the field is read-only): nothing was inserted. */\n | 'rejected'\n /** Not a paste for this handler (no text, already handled, or not a text or number field): left to the browser. */\n | 'ignored';\n\nexport interface PasteAsNumberOptions extends ParseNumberOptions {\n /**\n * How to write the number into the field. Default: `exact` for `<input type=\"number\">`,\n * which only takes `.` as the decimal separator; elsewhere the number in `locale`'s format,\n * ungrouped (`1234,5` in `de-DE`).\n */\n readonly format?: (parsed: ParsedNumber) => string;\n /** Called with the number before it is inserted: show `ambiguous` readings here. */\n readonly onNumber?: (parsed: ParsedNumber) => void;\n /** Called with the pasted text when it was not a number, or the field takes no input. */\n readonly onReject?: (text: string) => void;\n}\n\n/** Structural paste event: a DOM `ClipboardEvent` and React's `onPaste` event both fit. */\nexport interface NumberPasteEvent {\n readonly clipboardData: { getData(format: string): string } | null;\n readonly currentTarget: EventTarget | null;\n readonly target: EventTarget | null;\n readonly defaultPrevented: boolean;\n preventDefault(): void;\n}\n\nfunction asNumberInput(target: EventTarget | null): HTMLInputElement | null {\n const element = target as (Partial<Element> & { type?: unknown }) | null;\n return element?.nodeName === 'INPUT' && element.type === 'number' ? (target as HTMLInputElement) : null;\n}\n\n/**\n * A paste handler for number and amount fields. People paste `1.234,50 €` from a bank\n * statement, `$1,234.50` from an invoice, or `(1,234)` from a spreadsheet; a browser either\n * rejects these from `<input type=\"number\">` or keeps the text as it is. This reads the\n * number, inserts it the way the field takes it (with undo intact in text fields), and\n * turns away pastes that are not a number.\n *\n * Works on `<input type=\"number\">`, text `<input>`s (use `inputmode=\"decimal\"`) and\n * `<textarea>`s; other elements are left to the browser.\n *\n * @example\n * <input inputMode=\"decimal\" onPaste={(event) => pasteAsNumber(event, { locale: 'de-DE' })} />\n */\nexport function pasteAsNumber(event: NumberPasteEvent, options: PasteAsNumberOptions = {}): NumberPasteOutcome {\n if (event.defaultPrevented || event.clipboardData === null) return 'ignored';\n const numberInput = asNumberInput(event.currentTarget) ?? asNumberInput(event.target);\n const field: TextField | null = numberInput ?? asTextField(event.currentTarget) ?? asTextField(event.target);\n if (field === null) return 'ignored';\n const text = event.clipboardData.getData('text/plain');\n if (text === '') return 'ignored';\n event.preventDefault();\n const parsed = parseNumber(text.trim(), options);\n if (parsed !== null && !field.disabled && !field.readOnly) {\n options.onNumber?.(parsed);\n const value = options.format?.(parsed) ?? (numberInput === null ? formatNumber(parsed.exact, options) : parsed.exact);\n if (numberInput === null ? insertText(field, value) : replaceFieldValue(numberInput, value)) return 'pasted';\n }\n options.onReject?.(text);\n return 'rejected';\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,YAAY,CAAC,GAAG;CATpB,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,MAAM,KAAK;CAAG,CAAC,OAAO,KAAK;CAAG,CAAC,OAAO,KAAK;CAC3G,CAAC,MAAM,K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AAO,OAAO,OAAO,IAAI,OAAO;EAC/G,IAAI,gBAAgB,OAAO,WAAW,OAAO,KAAK,IAAI,kBAAkB,aAAa,KAAK,GAAG,OAAO;CACtG;CACA,QAAQ,WAAW,IAAI;CACvB,OAAO;AACT"}
|
package/dist/otp.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_field = require("./chunks/field-
|
|
3
|
+
const require_field = require("./chunks/field-B6SRWRbI.cjs");
|
|
4
|
+
exports.DEFAULT_OTP_MAX_LENGTH = require_field.DEFAULT_OTP_MAX_LENGTH;
|
|
4
5
|
exports.OTP_SCAN_LENGTH = require_field.OTP_SCAN_LENGTH;
|
|
5
6
|
exports.createOtpField = require_field.createOtpField;
|
|
6
7
|
exports.extractOtp = require_field.extractOtp;
|
package/dist/otp.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import { a as WebOtpStatus, i as createOtpField, n as OtpFieldOptions, o as OtpAlphabet, r as OtpSnapshot, s as normalizeOtpText, t as OtpField } from "./chunks/field-BTsKTs2M.cjs";
|
|
3
3
|
//#region src/otp/extract.d.ts
|
|
4
|
-
/** Text past this many characters is not read: a code is near the start of a message. */
|
|
5
|
-
export declare const
|
|
4
|
+
/** Text past this many characters is not read, unless `maxLength` allows it: a code is near the start of a message. */
|
|
5
|
+
export declare const DEFAULT_OTP_MAX_LENGTH = 100000;
|
|
6
|
+
/** @deprecated The old name of {@link DEFAULT_OTP_MAX_LENGTH}; removed in 2.0. */
|
|
7
|
+
export declare const OTP_SCAN_LENGTH: number;
|
|
6
8
|
interface ExtractOtpOptions {
|
|
7
9
|
/** The code's length, or its range. Default 4 to 8. */
|
|
8
10
|
readonly length?: number | {
|
|
@@ -16,6 +18,8 @@ interface ExtractOtpOptions {
|
|
|
16
18
|
* the format the WebOTP API reads) for another host gives no code: it was not meant for you.
|
|
17
19
|
*/
|
|
18
20
|
readonly domain?: string;
|
|
21
|
+
/** Read only this many characters of the text. Default {@link DEFAULT_OTP_MAX_LENGTH}. */
|
|
22
|
+
readonly maxLength?: number;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Where the code was found.
|
|
@@ -46,7 +50,8 @@ interface OtpMatch {
|
|
|
46
50
|
* code. When several numbers could be the code and no keyword points at one, the result is
|
|
47
51
|
* `null`: guessing would fill in a wrong code.
|
|
48
52
|
*
|
|
49
|
-
* @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range
|
|
53
|
+
* @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range,
|
|
54
|
+
* or a `maxLength` that is not a positive whole number.
|
|
50
55
|
*/
|
|
51
56
|
export declare function extractOtp(text: string, options?: ExtractOtpOptions): OtpMatch | null;
|
|
52
57
|
//#endregion
|
package/dist/otp.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import { a as WebOtpStatus, i as createOtpField, n as OtpFieldOptions, o as OtpAlphabet, r as OtpSnapshot, s as normalizeOtpText, t as OtpField } from "./chunks/field-BTsKTs2M.js";
|
|
3
3
|
//#region src/otp/extract.d.ts
|
|
4
|
-
/** Text past this many characters is not read: a code is near the start of a message. */
|
|
5
|
-
export declare const
|
|
4
|
+
/** Text past this many characters is not read, unless `maxLength` allows it: a code is near the start of a message. */
|
|
5
|
+
export declare const DEFAULT_OTP_MAX_LENGTH = 100000;
|
|
6
|
+
/** @deprecated The old name of {@link DEFAULT_OTP_MAX_LENGTH}; removed in 2.0. */
|
|
7
|
+
export declare const OTP_SCAN_LENGTH: number;
|
|
6
8
|
interface ExtractOtpOptions {
|
|
7
9
|
/** The code's length, or its range. Default 4 to 8. */
|
|
8
10
|
readonly length?: number | {
|
|
@@ -16,6 +18,8 @@ interface ExtractOtpOptions {
|
|
|
16
18
|
* the format the WebOTP API reads) for another host gives no code: it was not meant for you.
|
|
17
19
|
*/
|
|
18
20
|
readonly domain?: string;
|
|
21
|
+
/** Read only this many characters of the text. Default {@link DEFAULT_OTP_MAX_LENGTH}. */
|
|
22
|
+
readonly maxLength?: number;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Where the code was found.
|
|
@@ -46,7 +50,8 @@ interface OtpMatch {
|
|
|
46
50
|
* code. When several numbers could be the code and no keyword points at one, the result is
|
|
47
51
|
* `null`: guessing would fill in a wrong code.
|
|
48
52
|
*
|
|
49
|
-
* @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range
|
|
53
|
+
* @throws {CopyFailure} `invalid-payload` for a `length` that is not 1 to 32, or a reversed range,
|
|
54
|
+
* or a `maxLength` that is not a positive whole number.
|
|
50
55
|
*/
|
|
51
56
|
export declare function extractOtp(text: string, options?: ExtractOtpOptions): OtpMatch | null;
|
|
52
57
|
//#endregion
|
package/dist/otp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
export { n as OTP_SCAN_LENGTH, t as createOtpField,
|
|
2
|
+
export { n as DEFAULT_OTP_MAX_LENGTH, r as OTP_SCAN_LENGTH, t as createOtpField, i as extractOtp, a as normalizeOtpText } from "./chunks/field-DsRKkbav.js";
|
package/dist/rich.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_errors = require("./chunks/errors-
|
|
4
|
-
const require_url = require("./chunks/url-
|
|
3
|
+
const require_errors = require("./chunks/errors-DFmEAC4E.cjs");
|
|
4
|
+
const require_url = require("./chunks/url-BrhVUwn7.cjs");
|
|
5
5
|
const require_inert_html = require("./chunks/inert-html-DyxjWDok.cjs");
|
|
6
6
|
const require_url$1 = require("./chunks/url-B9jdFGQy.cjs");
|
|
7
|
-
const require_contrast = require("./chunks/contrast-
|
|
7
|
+
const require_contrast = require("./chunks/contrast-C9d8QuaF.cjs");
|
|
8
8
|
//#region src/rich/policy.ts
|
|
9
9
|
/**
|
|
10
10
|
* What portable rich text may contain: the elements, attributes and CSS that Gmail,
|