color-name-list 11.26.0 → 12.0.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/.vscode/tasks.json +48 -0
- package/README.md +5 -3
- package/changes.svg +3 -3
- package/dist/colornames.bestof.csv +22 -21
- package/dist/colornames.bestof.esm.js +1 -1
- package/dist/colornames.bestof.esm.mjs +1 -1
- package/dist/colornames.bestof.html +1 -1
- package/dist/colornames.bestof.json +1 -1
- package/dist/colornames.bestof.min.json +1 -1
- package/dist/colornames.bestof.scss +1 -1
- package/dist/colornames.bestof.umd.js +1 -1
- package/dist/colornames.bestof.xml +65 -61
- package/dist/colornames.bestof.yaml +51 -48
- package/dist/colornames.csv +42 -212
- package/dist/colornames.esm.js +1 -1
- package/dist/colornames.esm.mjs +1 -1
- package/dist/colornames.html +1 -1
- package/dist/colornames.json +1 -1
- package/dist/colornames.min.json +1 -1
- package/dist/colornames.scss +1 -1
- package/dist/colornames.short.csv +16 -17
- package/dist/colornames.short.esm.js +1 -1
- package/dist/colornames.short.esm.mjs +1 -1
- package/dist/colornames.short.html +1 -1
- package/dist/colornames.short.json +1 -1
- package/dist/colornames.short.min.json +1 -1
- package/dist/colornames.short.scss +1 -1
- package/dist/colornames.short.umd.js +1 -1
- package/dist/colornames.short.xml +50 -54
- package/dist/colornames.short.yaml +39 -42
- package/dist/colornames.umd.js +1 -1
- package/dist/colornames.xml +91 -771
- package/dist/colornames.yaml +75 -585
- package/dist/history.json +1 -1
- package/package.json +1 -1
- package/scripts/build.js +15 -2
- package/scripts/lib.js +55 -0
- package/src/colornames.csv +50 -220
- package/tests/duplicate-allowlist.json +12 -0
- package/tests/duplicates.test.js +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { findNearDuplicateNameConflicts } from '../scripts/lib.js';
|
|
5
|
+
import allowlist from './duplicate-allowlist.json';
|
|
6
|
+
|
|
7
|
+
describe('Duplicate-like color names', () => {
|
|
8
|
+
it('should not contain names that only differ by spacing/punctuation/case/accents', () => {
|
|
9
|
+
const csvPath = path.resolve('./src/colornames.csv');
|
|
10
|
+
const raw = fs.readFileSync(csvPath, 'utf8').replace(/\r\n/g, '\n').trimEnd();
|
|
11
|
+
const lines = raw.split('\n');
|
|
12
|
+
expect(lines.length).toBeGreaterThan(1);
|
|
13
|
+
|
|
14
|
+
const header = lines.shift();
|
|
15
|
+
expect(header.startsWith('name,hex')).toBe(true);
|
|
16
|
+
|
|
17
|
+
const items = lines.map((l, idx) => {
|
|
18
|
+
const lineNumber = idx + 2; // +1 for header, +1 because idx is 0-based
|
|
19
|
+
if (!l.trim()) return null;
|
|
20
|
+
const firstComma = l.indexOf(',');
|
|
21
|
+
const name = firstComma === -1 ? l : l.slice(0, firstComma);
|
|
22
|
+
return { name, lineNumber };
|
|
23
|
+
}).filter(Boolean);
|
|
24
|
+
|
|
25
|
+
const conflicts = findNearDuplicateNameConflicts(items, { allowlist });
|
|
26
|
+
|
|
27
|
+
if (conflicts.length) {
|
|
28
|
+
// Create a helpful error message with examples and hints.
|
|
29
|
+
const groupCount = conflicts.length;
|
|
30
|
+
const msgLines = [
|
|
31
|
+
`Found ${groupCount} duplicate-like group${groupCount === 1 ? '' : 's'} (case/accents/punctuation-insensitive):`,
|
|
32
|
+
'',
|
|
33
|
+
];
|
|
34
|
+
conflicts
|
|
35
|
+
// make message deterministic by sorting
|
|
36
|
+
.sort((a, b) => a.norm.localeCompare(b.norm))
|
|
37
|
+
.forEach(({ norm, entries }) => {
|
|
38
|
+
const unique = [];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
// De-duplicate exact same name+line pairs in output
|
|
41
|
+
for (const e of entries) {
|
|
42
|
+
const key = `${e.name}@${e.lineNumber}`;
|
|
43
|
+
if (!seen.has(key)) {
|
|
44
|
+
seen.add(key);
|
|
45
|
+
unique.push(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// sort entries by line number for readability
|
|
49
|
+
unique.sort((a, b) => a.lineNumber - b.lineNumber);
|
|
50
|
+
msgLines.push(` • ${norm}:`);
|
|
51
|
+
unique.forEach((e) => msgLines.push(` - line ${e.lineNumber}: "${e.name}"`));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
msgLines.push(
|
|
55
|
+
'',
|
|
56
|
+
'This typically indicates near-duplicates that only differ by spacing/punctuation, like "Snow Pink" vs "Snowpink".',
|
|
57
|
+
'Please unify or remove duplicates to keep the dataset clean.',
|
|
58
|
+
'',
|
|
59
|
+
'Tip:',
|
|
60
|
+
' - Edit src/colornames.csv and keep a single preferred spelling. When in doubt, prefer the most common or simplest form or the British spelling.',
|
|
61
|
+
' - After changes, run: npm run sort-colors',
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
throw new Error(msgLines.join('\n'));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If we reach here, no conflicts were found.
|
|
68
|
+
expect(conflicts.length).toBe(0);
|
|
69
|
+
});
|
|
70
|
+
});
|