@nitpicker/report-google-sheets 0.18.1 → 0.20.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/lib/data/create-discrepancies.d.ts +10 -12
- package/lib/data/create-discrepancies.js +27 -31
- package/lib/data/create-image-list.d.ts +26 -6
- package/lib/data/create-image-list.js +65 -39
- package/lib/data/create-links.d.ts +18 -1
- package/lib/data/create-links.js +91 -55
- package/lib/data/create-page-list.d.ts +24 -24
- package/lib/data/create-page-list.js +178 -224
- package/lib/data/create-referrers-relational-table.d.ts +13 -7
- package/lib/data/create-referrers-relational-table.js +57 -47
- package/lib/data/create-resources-relational-table.d.ts +7 -0
- package/lib/data/create-resources-relational-table.js +41 -33
- package/lib/data/create-resources.d.ts +24 -124
- package/lib/data/create-resources.js +100 -264
- package/lib/data/create-violations.d.ts +7 -6
- package/lib/data/create-violations.js +34 -19
- package/lib/dedupe-progress-message.d.ts +17 -0
- package/lib/dedupe-progress-message.js +26 -0
- package/lib/format-progress-count.d.ts +19 -0
- package/lib/format-progress-count.js +22 -0
- package/lib/open-report-archive.d.ts +54 -0
- package/lib/open-report-archive.js +76 -0
- package/lib/report.d.ts +23 -10
- package/lib/report.js +146 -149
- package/lib/reports/get-plugin-reports.d.ts +14 -6
- package/lib/reports/get-plugin-reports.js +14 -34
- package/lib/sheets/create-sheets.d.ts +66 -36
- package/lib/sheets/create-sheets.js +228 -362
- package/lib/sheets/estimate-cell-budget.d.ts +55 -0
- package/lib/sheets/estimate-cell-budget.js +56 -0
- package/lib/sheets/types.d.ts +111 -91
- package/lib/test-helpers/assert-no-lazy-cells.d.ts +16 -0
- package/lib/test-helpers/assert-no-lazy-cells.js +23 -0
- package/lib/test-helpers/cell-inspection.d.ts +20 -0
- package/lib/test-helpers/cell-inspection.js +21 -0
- package/lib/test-helpers/create-mock-sheet.d.ts +30 -0
- package/lib/test-helpers/create-mock-sheet.js +71 -0
- package/lib/test-helpers/one-chunk.d.ts +8 -0
- package/lib/test-helpers/one-chunk.js +11 -0
- package/lib/utils/join-urls-for-note.d.ts +27 -0
- package/lib/utils/join-urls-for-note.js +48 -0
- package/lib/utils/truncate-note-text.d.ts +15 -0
- package/lib/utils/truncate-note-text.js +23 -0
- package/package.json +13 -12
- package/lib/archive.d.ts +0 -20
- package/lib/archive.js +0 -34
- package/lib/sheets/run-finalize-resources.d.ts +0 -40
- package/lib/sheets/run-finalize-resources.js +0 -44
- package/lib/types.d.ts +0 -11
- package/lib/types.js +0 -1
- package/lib/utils/canonicalize-url.d.ts +0 -53
- package/lib/utils/canonicalize-url.js +0 -105
- package/lib/utils/has-prop-filter.d.ts +0 -18
- package/lib/utils/has-prop-filter.js +0 -19
- package/lib/utils/sort-resources-by-url.d.ts +0 -69
- package/lib/utils/sort-resources-by-url.js +0 -223
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/prefer-code-point --
|
|
2
|
-
* This file deliberately uses `charCodeAt` (UTF-16 code units) rather
|
|
3
|
-
* than `codePointAt` (Unicode code points). The natural-sort algorithm
|
|
4
|
-
* is byte-level by definition in Pool's reference C implementation,
|
|
5
|
-
* and advancing the index by one per call only works when each call
|
|
6
|
-
* returns one unit. Mixing in `codePointAt` would force separate
|
|
7
|
-
* surrogate-pair handling for negligible benefit (URLs are
|
|
8
|
-
* effectively ASCII at the sort layer).
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* ASCII character codes used by {@link naturalCompare}. Computed once
|
|
12
|
-
* via `charCodeAt` so `'Z'` reads more naturally than `0x5A`.
|
|
13
|
-
*/
|
|
14
|
-
const CHAR_NUL = 0;
|
|
15
|
-
const CHAR_TAB = '\t'.charCodeAt(0);
|
|
16
|
-
const CHAR_CR = '\r'.charCodeAt(0);
|
|
17
|
-
const CHAR_SPACE = ' '.charCodeAt(0);
|
|
18
|
-
const CHAR_ZERO = '0'.charCodeAt(0);
|
|
19
|
-
const CHAR_NINE = '9'.charCodeAt(0);
|
|
20
|
-
const CHAR_UPPER_A = 'A'.charCodeAt(0);
|
|
21
|
-
const CHAR_UPPER_Z = 'Z'.charCodeAt(0);
|
|
22
|
-
const ASCII_CASE_SHIFT = 'a'.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
23
|
-
/**
|
|
24
|
-
* Returns the UTF-16 code unit at `i`, or 0 (NUL) when out of range.
|
|
25
|
-
* Mimics how Pool's C reference treats the implicit `'\0'` terminator
|
|
26
|
-
* — JavaScript strings have no terminator, so we synthesize one.
|
|
27
|
-
* @param s - The string being scanned.
|
|
28
|
-
* @param i - Zero-based index.
|
|
29
|
-
*/
|
|
30
|
-
function codeAtOrNul(s, i) {
|
|
31
|
-
return i < s.length ? s.charCodeAt(i) : CHAR_NUL;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Matches Pool's `nat_isspace`: ASCII whitespace (`\t`, `\n`, `\v`,
|
|
35
|
-
* `\f`, `\r`, ` `). Codes 9..13 are contiguous in ASCII so a single
|
|
36
|
-
* range covers `\t \n \v \f \r`.
|
|
37
|
-
* @param c - UTF-16 code unit.
|
|
38
|
-
*/
|
|
39
|
-
function isAsciiWhitespace(c) {
|
|
40
|
-
return c === CHAR_SPACE || (c >= CHAR_TAB && c <= CHAR_CR);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Matches Pool's `nat_isdigit`: ASCII `'0'..'9'`.
|
|
44
|
-
* @param c - UTF-16 code unit.
|
|
45
|
-
*/
|
|
46
|
-
function isAsciiDigit(c) {
|
|
47
|
-
return c >= CHAR_ZERO && c <= CHAR_NINE;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Pool's `compare_right` — used when no leading zero is present in
|
|
51
|
-
* either run. Walks both digit runs to their end. The first side to
|
|
52
|
-
* exhaust its digit run is the smaller number. If both runs end at
|
|
53
|
-
* the same time, the bias (first non-equal digit seen) decides.
|
|
54
|
-
*
|
|
55
|
-
* Returns 0 only when both runs end simultaneously with no bias —
|
|
56
|
-
* i.e. the two runs encode the same integer.
|
|
57
|
-
* @param a - First string.
|
|
58
|
-
* @param ai - Start index in `a` (pointing at the first digit).
|
|
59
|
-
* @param b - Second string.
|
|
60
|
-
* @param bi - Start index in `b` (pointing at the first digit).
|
|
61
|
-
*/
|
|
62
|
-
function compareRight(a, ai, b, bi) {
|
|
63
|
-
let bias = 0;
|
|
64
|
-
for (;;) {
|
|
65
|
-
const ca = codeAtOrNul(a, ai);
|
|
66
|
-
const cb = codeAtOrNul(b, bi);
|
|
67
|
-
const aDigit = isAsciiDigit(ca);
|
|
68
|
-
const bDigit = isAsciiDigit(cb);
|
|
69
|
-
if (!aDigit && !bDigit)
|
|
70
|
-
return bias;
|
|
71
|
-
if (!aDigit)
|
|
72
|
-
return -1;
|
|
73
|
-
if (!bDigit)
|
|
74
|
-
return 1;
|
|
75
|
-
if (bias === 0) {
|
|
76
|
-
if (ca < cb)
|
|
77
|
-
bias = -1;
|
|
78
|
-
else if (ca > cb)
|
|
79
|
-
bias = 1;
|
|
80
|
-
}
|
|
81
|
-
ai++;
|
|
82
|
-
bi++;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Pool's `compare_left` — used when **either** run starts with a
|
|
87
|
-
* `'0'`, treating both runs as the fractional part of a decimal
|
|
88
|
-
* (e.g. `"01"` < `"1"` because `0.01 < 0.1`). Compares left-aligned
|
|
89
|
-
* digit-by-digit and returns at the first mismatch.
|
|
90
|
-
*
|
|
91
|
-
* Returns 0 only when both runs are identical character-by-character
|
|
92
|
-
* up to their end.
|
|
93
|
-
* @param a - First string.
|
|
94
|
-
* @param ai - Start index in `a` (pointing at the first digit).
|
|
95
|
-
* @param b - Second string.
|
|
96
|
-
* @param bi - Start index in `b` (pointing at the first digit).
|
|
97
|
-
*/
|
|
98
|
-
function compareLeft(a, ai, b, bi) {
|
|
99
|
-
for (;;) {
|
|
100
|
-
const ca = codeAtOrNul(a, ai);
|
|
101
|
-
const cb = codeAtOrNul(b, bi);
|
|
102
|
-
const aDigit = isAsciiDigit(ca);
|
|
103
|
-
const bDigit = isAsciiDigit(cb);
|
|
104
|
-
if (!aDigit && !bDigit)
|
|
105
|
-
return 0;
|
|
106
|
-
if (!aDigit)
|
|
107
|
-
return -1;
|
|
108
|
-
if (!bDigit)
|
|
109
|
-
return 1;
|
|
110
|
-
if (ca < cb)
|
|
111
|
-
return -1;
|
|
112
|
-
if (ca > cb)
|
|
113
|
-
return 1;
|
|
114
|
-
ai++;
|
|
115
|
-
bi++;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Natural-order string comparator, ported from Martin Pool's
|
|
120
|
-
* `strnatcmp.c` (sourcefrog/natsort, originally derived from Stuart
|
|
121
|
-
* Cheshire's 1996 Macintosh natural sort). Faithful to the C
|
|
122
|
-
* reference's dispatch:
|
|
123
|
-
*
|
|
124
|
-
* - Skip leading ASCII whitespace on both sides.
|
|
125
|
-
* - When both sides have a digit run:
|
|
126
|
-
* - If **either** run starts with `'0'`, treat them as fractional
|
|
127
|
-
* and use {@link compareLeft} (left-aligned digit-by-digit).
|
|
128
|
-
* - Otherwise use {@link compareRight} (length-first, with bias for
|
|
129
|
-
* ties).
|
|
130
|
-
* - End-of-string on both sides means equal.
|
|
131
|
-
* - Otherwise fold ASCII letters to lower case and compare one
|
|
132
|
-
* UTF-16 code unit.
|
|
133
|
-
*
|
|
134
|
-
* Allocates no intermediate strings: only `charCodeAt` and integer
|
|
135
|
-
* arithmetic. That makes the function safe to invoke O(N log N)
|
|
136
|
-
* times during a 1M+ element sort without inflating the V8 heap with
|
|
137
|
-
* derived `SeqString` allocations.
|
|
138
|
-
*
|
|
139
|
-
* **Benchmark reference (Node 24, M-class CPU):** 100K-entry sort
|
|
140
|
-
* completes in ~650 ms with median heap delta ratio
|
|
141
|
-
* `heapDelta(100K) / heapDelta(10K) ≈ 5–15×`. If either measurement
|
|
142
|
-
* jumps by an order of magnitude (multi-second elapsed, ratio > 100),
|
|
143
|
-
* suspect a regression that reintroduced per-compare string
|
|
144
|
-
* allocation or `Intl.Collator` dispatch.
|
|
145
|
-
*
|
|
146
|
-
* **UTF-16 semantics:** index moves one code unit per step. ASCII
|
|
147
|
-
* URLs (the only kind the archive currently stores) are entirely
|
|
148
|
-
* BMP, so this is equivalent to per-character iteration. URLs that
|
|
149
|
-
* contain surrogate pairs (e.g. raw emoji in path segments) compare
|
|
150
|
-
* as UTF-16 code unit sequences, which is deterministic but not
|
|
151
|
-
* equivalent to Unicode code-point order. That matches `strnatcmp.c`
|
|
152
|
-
* — it also operates on bytes, not Unicode scalars.
|
|
153
|
-
* @param a - First URL.
|
|
154
|
-
* @param b - Second URL.
|
|
155
|
-
* @returns Negative if `a < b`, positive if `a > b`, zero if equal.
|
|
156
|
-
*/
|
|
157
|
-
export function naturalCompare(a, b) {
|
|
158
|
-
let ai = 0;
|
|
159
|
-
let bi = 0;
|
|
160
|
-
for (;;) {
|
|
161
|
-
let ca = codeAtOrNul(a, ai);
|
|
162
|
-
let cb = codeAtOrNul(b, bi);
|
|
163
|
-
while (isAsciiWhitespace(ca)) {
|
|
164
|
-
ai++;
|
|
165
|
-
ca = codeAtOrNul(a, ai);
|
|
166
|
-
}
|
|
167
|
-
while (isAsciiWhitespace(cb)) {
|
|
168
|
-
bi++;
|
|
169
|
-
cb = codeAtOrNul(b, bi);
|
|
170
|
-
}
|
|
171
|
-
if (isAsciiDigit(ca) && isAsciiDigit(cb)) {
|
|
172
|
-
const fractional = ca === CHAR_ZERO || cb === CHAR_ZERO;
|
|
173
|
-
const result = fractional ? compareLeft(a, ai, b, bi) : compareRight(a, ai, b, bi);
|
|
174
|
-
if (result !== 0)
|
|
175
|
-
return result;
|
|
176
|
-
// Both digit-run helpers return 0 only when the digit
|
|
177
|
-
// runs are pointwise equal up to their joint end. Fall
|
|
178
|
-
// through and let the trailing byte compare advance
|
|
179
|
-
// past the shared first digit, exactly like Pool's C
|
|
180
|
-
// source.
|
|
181
|
-
}
|
|
182
|
-
if (ca === CHAR_NUL && cb === CHAR_NUL) {
|
|
183
|
-
return 0;
|
|
184
|
-
}
|
|
185
|
-
const fa = ca >= CHAR_UPPER_A && ca <= CHAR_UPPER_Z ? ca + ASCII_CASE_SHIFT : ca;
|
|
186
|
-
const fb = cb >= CHAR_UPPER_A && cb <= CHAR_UPPER_Z ? cb + ASCII_CASE_SHIFT : cb;
|
|
187
|
-
if (fa < fb)
|
|
188
|
-
return -1;
|
|
189
|
-
if (fa > fb)
|
|
190
|
-
return 1;
|
|
191
|
-
ai++;
|
|
192
|
-
bi++;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Sorts archive resources by their URL in natural order, returning a
|
|
197
|
-
* new array (the input is left untouched). Uses
|
|
198
|
-
* {@link naturalCompare} as the comparator, so embedded integers
|
|
199
|
-
* compare by value (`image-2.jpg` < `image-10.jpg`) and ASCII case
|
|
200
|
-
* is folded.
|
|
201
|
-
*
|
|
202
|
-
* The sort is stable (V8 TimSort). Each comparison allocates no
|
|
203
|
-
* intermediate strings, so the only extra memory is V8's TimSort
|
|
204
|
-
* auxiliary buffer — O(N) pointer-sized entries, not O(N × URL length).
|
|
205
|
-
* @param resources - The list of resources to sort. Only the `url`
|
|
206
|
-
* field is read. A `null` url (a blob-routed resource whose identity
|
|
207
|
-
* is a large `data:` URI — see `create-entity-tables.ts`'s
|
|
208
|
-
* `resource_items url / blob mutual-exclusion CHECK`) sorts as if it
|
|
209
|
-
* were the empty string, placing it first.
|
|
210
|
-
* @returns A new array sorted by URL in natural order.
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* sortResourcesByUrl([
|
|
214
|
-
* { url: 'https://x/img-10.jpg' },
|
|
215
|
-
* { url: 'https://x/img-2.jpg' },
|
|
216
|
-
* { url: 'https://x/img-1.jpg' },
|
|
217
|
-
* ]);
|
|
218
|
-
* // → [{ url: 'https://x/img-1.jpg' }, { url: 'https://x/img-2.jpg' }, { url: 'https://x/img-10.jpg' }]
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
export function sortResourcesByUrl(resources) {
|
|
222
|
-
return resources.toSorted((a, b) => naturalCompare(a.url ?? '', b.url ?? ''));
|
|
223
|
-
}
|