@rowsncolumns/utils 9.5.0 → 9.5.3
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/dist/cjs/clipboard-html-sanitize.d.ts +15 -0
- package/dist/cjs/clipboard-html-sanitize.d.ts.map +1 -0
- package/dist/cjs/clipboard-html-sanitize.js +237 -0
- package/dist/cjs/condition-operand.d.ts +54 -0
- package/dist/cjs/condition-operand.d.ts.map +1 -0
- package/dist/cjs/condition-operand.js +223 -0
- package/dist/cjs/conditional-format.d.ts.map +1 -1
- package/dist/cjs/conditional-format.js +5 -59
- package/dist/cjs/data-validation.d.ts +9 -0
- package/dist/cjs/data-validation.d.ts.map +1 -1
- package/dist/cjs/data-validation.js +29 -60
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/rich-text-html.d.ts +9 -0
- package/dist/cjs/rich-text-html.d.ts.map +1 -1
- package/dist/cjs/rich-text-html.js +52 -23
- package/dist/cjs/sheet-names.d.ts +60 -0
- package/dist/cjs/sheet-names.d.ts.map +1 -0
- package/dist/cjs/sheet-names.js +157 -0
- package/dist/cjs/sheet-protection.d.ts +9 -0
- package/dist/cjs/sheet-protection.d.ts.map +1 -0
- package/dist/cjs/sheet-protection.js +11 -0
- package/dist/cjs/string.d.ts +31 -0
- package/dist/cjs/string.d.ts.map +1 -1
- package/dist/cjs/string.js +73 -3
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/clipboard-html-sanitize.d.ts +15 -0
- package/dist/esm/clipboard-html-sanitize.d.ts.map +1 -0
- package/dist/esm/clipboard-html-sanitize.js +192 -0
- package/dist/esm/condition-operand.d.ts +54 -0
- package/dist/esm/condition-operand.d.ts.map +1 -0
- package/dist/esm/condition-operand.js +203 -0
- package/dist/esm/conditional-format.d.ts.map +1 -1
- package/dist/esm/conditional-format.js +5 -57
- package/dist/esm/data-validation.d.ts +9 -0
- package/dist/esm/data-validation.d.ts.map +1 -1
- package/dist/esm/data-validation.js +27 -57
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/rich-text-html.d.ts +9 -0
- package/dist/esm/rich-text-html.d.ts.map +1 -1
- package/dist/esm/rich-text-html.js +20 -4
- package/dist/esm/sheet-names.d.ts +60 -0
- package/dist/esm/sheet-names.d.ts.map +1 -0
- package/dist/esm/sheet-names.js +109 -0
- package/dist/esm/sheet-protection.d.ts +9 -0
- package/dist/esm/sheet-protection.d.ts.map +1 -0
- package/dist/esm/sheet-protection.js +8 -0
- package/dist/esm/string.d.ts +31 -0
- package/dist/esm/string.d.ts.map +1 -1
- package/dist/esm/string.js +62 -2
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/esm/string.js
CHANGED
|
@@ -118,13 +118,35 @@ export const cellRangeToAddress = (sheetName, range) => {
|
|
|
118
118
|
columnIndex: range.endColumnIndex,
|
|
119
119
|
})}`;
|
|
120
120
|
};
|
|
121
|
-
|
|
121
|
+
/** `A1`-style lookalike: 1–3 ASCII letters followed only by digits (`AB12`, `XFD1`). */
|
|
122
|
+
const SHEET_NAME_A1_LOOKALIKE = /^[A-Za-z]{1,3}\d+$/;
|
|
123
|
+
/** `R1C1`-style lookalike: an optional-digit `R` part and/or `C` part, nothing else (`R`, `C22`, `R1C1`). */
|
|
124
|
+
const SHEET_NAME_R1C1_LOOKALIKE = /^(?:[Rr]\d*)?(?:[Cc]\d*)?$/;
|
|
125
|
+
/**
|
|
126
|
+
* Must `name` be single-quoted as a sheet qualifier (`'My Data'!A1`)? Excel writes it bare only when
|
|
127
|
+
* it is a plain identifier — ASCII letters and digits, starting with a letter — and cannot be read
|
|
128
|
+
* as something else: a cell reference (`A1`, `XFD1`, `R1C1`), or a boolean (`TRUE`). A leading digit
|
|
129
|
+
* (`2024`, `1Sheet`) always quotes. Deliberately a superset of Excel's minimum (a `_`, `.` or
|
|
130
|
+
* non-ASCII letter also quotes): over-quoting is always valid, under-quoting makes `=2024!A1` a
|
|
131
|
+
* formula Excel rejects (rowsncolumns/spreadsheet#939 K-10).
|
|
132
|
+
*/
|
|
133
|
+
export const sheetNameNeedsQuoting = (name) => name.length === 0 ||
|
|
134
|
+
/[^A-Za-z0-9]/.test(name) ||
|
|
135
|
+
/^\d/.test(name) ||
|
|
136
|
+
SHEET_NAME_A1_LOOKALIKE.test(name) ||
|
|
137
|
+
SHEET_NAME_R1C1_LOOKALIKE.test(name) ||
|
|
138
|
+
/^(?:true|false)$/i.test(name);
|
|
139
|
+
/**
|
|
140
|
+
* Quote a sheet name for use as a formula qualifier when Excel requires it (see
|
|
141
|
+
* {@link sheetNameNeedsQuoting}); apostrophes inside are doubled (`'O''Neil'`). Rename, cross-sheet
|
|
142
|
+
* reference generation and formula-bar insertion all quote through here so they agree.
|
|
143
|
+
*/
|
|
122
144
|
export const sanitizeSheetName = (name) => {
|
|
123
145
|
if (name === void 0)
|
|
124
146
|
return void 0;
|
|
125
147
|
if (typeof name === "number")
|
|
126
148
|
return name;
|
|
127
|
-
if (
|
|
149
|
+
if (sheetNameNeedsQuoting(name)) {
|
|
128
150
|
// Escape single quotes by doubling them for valid sheet references.
|
|
129
151
|
const escaped = name.replace(/'/g, "''");
|
|
130
152
|
return `'${escaped}'`;
|
|
@@ -238,6 +260,44 @@ const URL_SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;
|
|
|
238
260
|
// explicit scheme (javascript:, data:, vbscript:, …) is a script/content
|
|
239
261
|
// injection vector and is rejected.
|
|
240
262
|
const SAFE_URL_SCHEMES = new Set(["http", "https", "mailto", "tel", "ftp"]);
|
|
263
|
+
/**
|
|
264
|
+
* Whether a hyperlink target read from untrusted markup (clipboard HTML) may
|
|
265
|
+
* be kept. A URL with an explicit scheme must use one of the safe schemes;
|
|
266
|
+
* scheme-less, protocol-relative, path and fragment references are allowed
|
|
267
|
+
* (they are normalized by {@link normalizeExternalUrl} before being opened).
|
|
268
|
+
* Applies the same tab/newline and C0-control stripping as the browser's URL
|
|
269
|
+
* canonicalization so `java\tscript:` cannot slip through.
|
|
270
|
+
*/
|
|
271
|
+
export const isSafeHyperlinkUri = (uri) => {
|
|
272
|
+
if (uri == null) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
const trimmed = uri
|
|
276
|
+
.replace(/[\t\n\r]/g, "")
|
|
277
|
+
.replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, "")
|
|
278
|
+
.trim();
|
|
279
|
+
if (!trimmed) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const schemeMatch = URL_SCHEME.exec(trimmed);
|
|
283
|
+
if (!schemeMatch) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
return SAFE_URL_SCHEMES.has(schemeMatch[1].toLowerCase());
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Escape text for interpolation into an HTML text node (`text/html`
|
|
290
|
+
* clipboard fragments): a cell whose value is literally `<b>x</b>` must paste
|
|
291
|
+
* back as that text, not as bold "x".
|
|
292
|
+
*/
|
|
293
|
+
export const escapeHtmlText = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
294
|
+
/** Escape a value for interpolation into a quoted HTML attribute. */
|
|
295
|
+
export const escapeHtmlAttribute = (value) => value
|
|
296
|
+
.replace(/&/g, "&")
|
|
297
|
+
.replace(/"/g, """)
|
|
298
|
+
.replace(/'/g, "'")
|
|
299
|
+
.replace(/</g, "<")
|
|
300
|
+
.replace(/>/g, ">");
|
|
241
301
|
/**
|
|
242
302
|
* Normalize an external hyperlink target for the browser. A stored URL
|
|
243
303
|
* without a scheme ("paradigm.xyz") would otherwise be resolved relative to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["../../array.ts","../../cell-data-helpers.ts","../../clipboard-html-sanitize.ts","../../color.ts","../../colors.ts","../../condition-operand.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-names.ts","../../sheet-protection.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rowsncolumns/utils",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.3",
|
|
4
4
|
"author": "Vinay M",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"numfmt": "^3.2.2",
|
|
47
|
-
"@rowsncolumns/common-types": ">=5.3.
|
|
47
|
+
"@rowsncolumns/common-types": ">=5.3.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {},
|
|
50
50
|
"peerDependencies": {}
|