color-name-list 11.9.1 → 11.10.1

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.
Files changed (38) hide show
  1. package/.github/workflows/build-and-release.yml +57 -0
  2. package/.github/workflows/build.yml +22 -7
  3. package/.husky/pre-commit +1 -1
  4. package/README.md +14 -9
  5. package/changes.svg +3 -3
  6. package/dist/colornames.bestof.csv +4532 -4532
  7. package/dist/colornames.bestof.esm.js +1 -4535
  8. package/dist/colornames.bestof.esm.mjs +1 -4535
  9. package/dist/colornames.bestof.json +1 -4535
  10. package/dist/colornames.bestof.scss +1 -4535
  11. package/dist/colornames.bestof.umd.js +1 -4543
  12. package/dist/colornames.bestof.yaml +9067 -4534
  13. package/dist/colornames.csv +30290 -30289
  14. package/dist/colornames.esm.js +1 -30292
  15. package/dist/colornames.esm.mjs +1 -30292
  16. package/dist/colornames.html +1 -1
  17. package/dist/colornames.json +1 -30292
  18. package/dist/colornames.min.json +1 -1
  19. package/dist/colornames.scss +1 -30292
  20. package/dist/colornames.short.csv +2885 -2885
  21. package/dist/colornames.short.esm.js +1 -2888
  22. package/dist/colornames.short.esm.mjs +1 -2888
  23. package/dist/colornames.short.json +1 -2888
  24. package/dist/colornames.short.scss +1 -2888
  25. package/dist/colornames.short.umd.js +1 -2896
  26. package/dist/colornames.short.yaml +5773 -2887
  27. package/dist/colornames.umd.js +1 -30300
  28. package/dist/colornames.xml +4 -0
  29. package/dist/colornames.yaml +60584 -30291
  30. package/dist/history.json +1 -61120
  31. package/package.json +7 -5
  32. package/scripts/build.js +67 -15
  33. package/scripts/tools/history.js +6 -1
  34. package/src/colornames.csv +1 -0
  35. package/tests/formats.test.js +46 -0
  36. package/tests/imports.test.js +119 -0
  37. package/vitest.config.js +8 -0
  38. package/.github/workflows/release.yml +0 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "color-name-list",
3
- "version": "11.9.1",
3
+ "version": "11.10.1",
4
4
  "description": "long list of color names",
5
5
  "main": "dist/colornames.json",
6
6
  "browser": "dist/colornames.umd.js",
@@ -24,13 +24,14 @@
24
24
  "scripts": {
25
25
  "commit": "git-cz",
26
26
  "pull-colors": "curl -L 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQube6Y0wHyEtJnjg0eU3N7VseoxVnD4L9uDqvWZdl_tzzrHDVN10IPP7cdFipX8j70atNMLfPCB0Q6/pub?gid=40578722&single=true&output=csv' -o src/colornames.csv",
27
- "test": "node scripts/build.js --testOnly",
28
- "clean-dist-folder": "rm -rf dist && mkdir dist",
29
- "build": "npm run clean-dist-folder && node scripts/build.js && npm run build-history && npm run prettier",
27
+ "test": "npm run build --testonly && npm run build && vitest run",
28
+ "test:watch": "vitest",
29
+ "build": "node scripts/build.js && npm run prettier",
30
30
  "prettier": "prettier --write ./dist/*",
31
31
  "lint": "eslint ./scripts",
32
32
  "semantic-release": "semantic-release",
33
33
  "build-history": "node scripts/tools/history.js > dist/history.json",
34
+ "history": "node scripts/tools/history.js > dist/history.json",
34
35
  "prepare": "husky"
35
36
  },
36
37
  "repository": {
@@ -65,7 +66,8 @@
65
66
  "husky": "^9.1.6",
66
67
  "prettier": "^3.5.3",
67
68
  "seedrandom": "^3.0.5",
68
- "semantic-release": "^24.2.0"
69
+ "semantic-release": "^24.2.0",
70
+ "vitest": "^3.1.2"
69
71
  },
70
72
  "engines": {
71
73
  "node": ">=20.11.0",
package/scripts/build.js CHANGED
@@ -135,6 +135,12 @@ const JSONExportStringShort = JSON.stringify(
135
135
  )
136
136
  );
137
137
 
138
+ // make sure dist folder exists
139
+ const distFolder = path.normalize(`${baseFolder}${folderDist}`);
140
+ if (!fs.existsSync(distFolder)) {
141
+ fs.mkdirSync(distFolder);
142
+ }
143
+
138
144
  fs.writeFileSync(path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`), JSONExportString);
139
145
 
140
146
  fs.writeFileSync(
@@ -404,24 +410,70 @@ function log(key, value, message, errorLevel = 1) {
404
410
  // gets SVG template
405
411
  const svgTpl = fs.readFileSync(path.normalize(__dirname + '/changes.svg.tpl'), 'utf8').toString();
406
412
 
407
- // generates an SVG image with the new color based on the diff ot the last commit to the current
413
+ // generates an SVG image with the new colors based on the diff between the last two commits that changed the file
408
414
  function diffSVG() {
415
+ // Get the last two commits that modified the CSV file
409
416
  exec(
410
- `git diff -U0 HEAD ${baseFolder}${folderDist}${fileNameSrc}.csv`,
417
+ `git log -n 2 --pretty=format:"%H" -- ${baseFolder}${folderSrc}${fileNameSrc}.csv`,
411
418
  function (err, stdout, stderr) {
412
- const diffTxt = stdout;
413
- if (!/(?<=^[+])[^+].*/gm.test(diffTxt)) return;
414
- const changes = diffTxt.match(/(?<=^[+])[^+].*/gm).filter((i) => i);
415
- const svgTxtStr = changes.reduce((str, change, i) => {
416
- const changeParts = change.split(',');
417
- return `${str}<text x="40" y="${20 + (i + 1) * 70}" fill="${
418
- changeParts[1]
419
- }">${changeParts[0].replace(/&/g, '&amp;')}</text>`;
420
- }, '');
421
-
422
- fs.writeFileSync(
423
- path.normalize(`${baseFolder}changes.svg`),
424
- svgTpl.replace(/{height}/g, changes.length * 70 + 80).replace(/{items}/g, svgTxtStr)
419
+ if (err) {
420
+ console.error('Error getting commit history:', err);
421
+ return;
422
+ }
423
+
424
+ const commits = stdout.trim().split('\n');
425
+ if (commits.length < 2) {
426
+ console.log('Not enough commit history to generate diff');
427
+ return;
428
+ }
429
+
430
+ const newerCommit = commits[0];
431
+ const olderCommit = commits[1];
432
+
433
+ // Compare the two commits
434
+ exec(
435
+ `git diff -w -U0 ${olderCommit} ${newerCommit} -- ${baseFolder}${folderSrc}${fileNameSrc}.csv`,
436
+ function (err, stdout, stderr) {
437
+ if (err) {
438
+ console.error('Error generating diff:', err);
439
+ return;
440
+ }
441
+
442
+ const diffTxt = stdout;
443
+ if (!/(?<=^[+])[^+].*/gm.test(diffTxt)) {
444
+ console.log('No changes detected in the color file');
445
+ return;
446
+ }
447
+
448
+ const changes = diffTxt.match(/(?<=^[+])[^+].*/gm).filter((i) => i);
449
+
450
+ // Filter out the header line if it was included in the diff
451
+ const filteredChanges = changes.filter((line) => !line.startsWith('name,hex'));
452
+
453
+ if (filteredChanges.length === 0) {
454
+ console.log('No color changes detected');
455
+ return;
456
+ }
457
+
458
+ const svgTxtStr = filteredChanges.reduce((str, change, i) => {
459
+ const changeParts = change.split(',');
460
+ // Make sure we have both the name and hex color
461
+ if (changeParts.length < 2) return str;
462
+
463
+ return `${str}<text x="40" y="${20 + (i + 1) * 70}" fill="${
464
+ changeParts[1]
465
+ }">${changeParts[0].replace(/&/g, '&amp;')}</text>`;
466
+ }, '');
467
+
468
+ fs.writeFileSync(
469
+ path.normalize(`${baseFolder}changes.svg`),
470
+ svgTpl
471
+ .replace(/{height}/g, filteredChanges.length * 70 + 80)
472
+ .replace(/{items}/g, svgTxtStr)
473
+ );
474
+
475
+ console.log(`Generated SVG showing ${filteredChanges.length} new color(s)`);
476
+ }
425
477
  );
426
478
  }
427
479
  );
@@ -19,7 +19,7 @@ async function main() {
19
19
 
20
20
  for (const commit of allCommits) {
21
21
  // Figure out what changed in that particular commit
22
- const diff = cmd(`git show --ignore-cr-at-eol ${commit} -- ./src/colornames.csv`)
22
+ const diff = cmd(`git show -w --ignore-cr-at-eol ${commit} -- ./src/colornames.csv`)
23
23
  .split('\n')
24
24
  .filter(Boolean);
25
25
 
@@ -30,6 +30,11 @@ async function main() {
30
30
  const modified = {};
31
31
 
32
32
  for (const line of diff) {
33
+ // Ignore the header row
34
+ if (line.match(/^(\+|-)?name,hex/)) {
35
+ continue;
36
+ }
37
+
33
38
  const res = line.match(/^((?<op>(\+|-)))(?<name>[^,]+),(?<hex>[^,]+)/);
34
39
  if (!res) {
35
40
  continue;
@@ -20509,6 +20509,7 @@ Pinkish Orange,#ff724c,
20509
20509
  Pinkish Purple,#d648d7,
20510
20510
  Pinkish Red,#f10c45,
20511
20511
  Pinkish Tan,#d99b82,
20512
+ Pinkish White,#fff1fa,
20512
20513
  Pinkling,#eb84f5,x
20513
20514
  Pinkman,#dd11ff,x
20514
20515
  Pinktone,#f9ced1,
@@ -0,0 +1,46 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { parseCSVString } from '../scripts/lib.js';
5
+
6
+ describe('Other Format Tests', () => {
7
+ // Load CSV data for comparison
8
+ const csvSource = fs.readFileSync(path.resolve('./src/colornames.csv'), 'utf8').toString();
9
+ const csvData = parseCSVString(csvSource);
10
+ const csvColors = csvData.entries.map(entry => ({
11
+ name: entry.name,
12
+ hex: entry.hex
13
+ }));
14
+
15
+ describe('CSV Output', () => {
16
+ it('should correctly generate CSV files', () => {
17
+ const mainCsv = fs.readFileSync(path.resolve('./dist/colornames.csv'), 'utf8');
18
+ const bestofCsv = fs.readFileSync(path.resolve('./dist/colornames.bestof.csv'), 'utf8');
19
+ const shortCsv = fs.readFileSync(path.resolve('./dist/colornames.short.csv'), 'utf8');
20
+
21
+ // Check that the files are not empty
22
+ expect(mainCsv.length).toBeGreaterThan(0);
23
+ expect(bestofCsv.length).toBeGreaterThan(0);
24
+ expect(shortCsv.length).toBeGreaterThan(0);
25
+
26
+ // Verify headers
27
+ expect(mainCsv).toMatch(/^name,hex/);
28
+ expect(bestofCsv).toMatch(/^name,hex/);
29
+ expect(shortCsv).toMatch(/^name,hex/);
30
+
31
+ // Parse the CSV files
32
+ const mainData = parseCSVString(mainCsv);
33
+ const bestofData = parseCSVString(bestofCsv);
34
+ const shortData = parseCSVString(shortCsv);
35
+
36
+ // Verify data integrity
37
+ expect(mainData.entries.length).toBe(csvColors.length);
38
+ expect(bestofData.entries.length).toBeLessThan(csvColors.length);
39
+ expect(shortData.entries.length).toBeLessThan(bestofData.entries.length);
40
+
41
+ // Verify structure
42
+ expect(mainData.entries[0]).toHaveProperty('name');
43
+ expect(mainData.entries[0]).toHaveProperty('hex');
44
+ });
45
+ });
46
+ });
@@ -0,0 +1,119 @@
1
+ import { describe, it, expect } from 'vitest';
2
+
3
+ import * as esmColors from '../dist/colornames.esm.js';
4
+ import * as esmBestOfColors from '../dist/colornames.bestof.esm.js';
5
+ import * as esmShortColors from '../dist/colornames.short.esm.js';
6
+
7
+ // Import JSON files directly
8
+ import jsonColors from '../dist/colornames.json' assert { type: 'json' };
9
+ import jsonBestOfColors from '../dist/colornames.bestof.json' assert { type: 'json' };
10
+ import jsonShortColors from '../dist/colornames.short.json' assert { type: 'json' };
11
+
12
+ // Import minified JSON files
13
+ import jsonMinColors from '../dist/colornames.min.json' assert { type: 'json' };
14
+ import jsonMinBestOfColors from '../dist/colornames.bestof.min.json' assert { type: 'json' };
15
+ import jsonMinShortColors from '../dist/colornames.short.min.json' assert { type: 'json' };
16
+
17
+ // Also import the source CSV file for verification
18
+ import fs from 'fs';
19
+ import path from 'path';
20
+ import { parseCSVString } from '../scripts/lib.js';
21
+
22
+ describe('Color Names Import Tests', () => {
23
+ // Load CSV data for comparison
24
+ const csvSource = fs.readFileSync(path.resolve('./src/colornames.csv'), 'utf8').toString();
25
+ const csvData = parseCSVString(csvSource);
26
+ const csvColors = csvData.entries.map(entry => ({
27
+ name: entry.name,
28
+ hex: entry.hex
29
+ }));
30
+
31
+ describe('JSON Files', () => {
32
+ it('should import main JSON file correctly', () => {
33
+ expect(jsonColors).toBeDefined();
34
+ expect(Array.isArray(jsonColors)).toBe(true);
35
+ expect(jsonColors.length).toBeGreaterThan(0);
36
+ expect(jsonColors[0]).toHaveProperty('name');
37
+ expect(jsonColors[0]).toHaveProperty('hex');
38
+ expect(jsonColors.length).toBe(csvColors.length);
39
+ });
40
+
41
+ it('should import bestof JSON file correctly', () => {
42
+ expect(jsonBestOfColors).toBeDefined();
43
+ expect(Array.isArray(jsonBestOfColors)).toBe(true);
44
+ expect(jsonBestOfColors.length).toBeGreaterThan(0);
45
+ expect(jsonBestOfColors[0]).toHaveProperty('name');
46
+ expect(jsonBestOfColors[0]).toHaveProperty('hex');
47
+ expect(jsonBestOfColors.length).toBeLessThan(csvColors.length);
48
+ });
49
+
50
+ it('should import short JSON file correctly', () => {
51
+ expect(jsonShortColors).toBeDefined();
52
+ expect(Array.isArray(jsonShortColors)).toBe(true);
53
+ expect(jsonShortColors.length).toBeGreaterThan(0);
54
+ expect(jsonShortColors[0]).toHaveProperty('name');
55
+ expect(jsonShortColors[0]).toHaveProperty('hex');
56
+ expect(jsonShortColors.length).toBeLessThan(csvColors.length);
57
+ });
58
+
59
+ it('should import minified JSON files correctly', () => {
60
+ expect(jsonMinColors).toBeDefined();
61
+ expect(typeof jsonMinColors).toBe('object');
62
+ expect(Object.keys(jsonMinColors).length).toBeGreaterThan(0);
63
+ expect(Object.values(jsonMinColors).length).toBe(csvColors.length);
64
+
65
+ expect(jsonMinBestOfColors).toBeDefined();
66
+ expect(typeof jsonMinBestOfColors).toBe('object');
67
+ expect(Object.keys(jsonMinBestOfColors).length).toBeGreaterThan(0);
68
+
69
+ expect(jsonMinShortColors).toBeDefined();
70
+ expect(typeof jsonMinShortColors).toBe('object');
71
+ expect(Object.keys(jsonMinShortColors).length).toBeGreaterThan(0);
72
+ });
73
+ });
74
+
75
+ describe('ESM Files', () => {
76
+ it('should import main ESM file correctly', () => {
77
+ expect(esmColors).toBeDefined();
78
+ expect(esmColors.colornames).toBeDefined();
79
+ expect(Array.isArray(esmColors.colornames)).toBe(true);
80
+ expect(esmColors.colornames.length).toBeGreaterThan(0);
81
+ expect(esmColors.colornames[0]).toHaveProperty('name');
82
+ expect(esmColors.colornames[0]).toHaveProperty('hex');
83
+ expect(esmColors.colornames.length).toBe(csvColors.length);
84
+ });
85
+
86
+ it('should import bestof ESM file correctly', () => {
87
+ expect(esmBestOfColors).toBeDefined();
88
+ expect(esmBestOfColors.colornames).toBeDefined();
89
+ expect(Array.isArray(esmBestOfColors.colornames)).toBe(true);
90
+ expect(esmBestOfColors.colornames.length).toBeGreaterThan(0);
91
+ expect(esmBestOfColors.colornames[0]).toHaveProperty('name');
92
+ expect(esmBestOfColors.colornames[0]).toHaveProperty('hex');
93
+ });
94
+
95
+ it('should import short ESM file correctly', () => {
96
+ expect(esmShortColors).toBeDefined();
97
+ expect(esmShortColors.colornames).toBeDefined();
98
+ expect(Array.isArray(esmShortColors.colornames)).toBe(true);
99
+ expect(esmShortColors.colornames.length).toBeGreaterThan(0);
100
+ expect(esmShortColors.colornames[0]).toHaveProperty('name');
101
+ expect(esmShortColors.colornames[0]).toHaveProperty('hex');
102
+ });
103
+ });
104
+
105
+ describe('Content Verification', () => {
106
+ it('should contain expected color names', () => {
107
+ // Check for some common color names
108
+ const commonColors = ['black', 'white', 'red', 'blue', 'green', 'yellow', 'purple', 'pink'];
109
+
110
+ // Convert to lowercase for easier comparison
111
+ const allNames = jsonColors.map(color => color.name.toLowerCase());
112
+
113
+ commonColors.forEach(color => {
114
+ // Check if at least one entry contains this common color name
115
+ expect(allNames.some(name => name.includes(color))).toBe(true);
116
+ });
117
+ });
118
+ });
119
+ });
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['tests/**/*.test.js'],
6
+ environment: 'node',
7
+ },
8
+ });
@@ -1,26 +0,0 @@
1
- name: Semantic Release
2
-
3
- on:
4
- push:
5
- branches: [main]
6
-
7
- jobs:
8
- release:
9
- name: Release
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Checkout
13
- uses: actions/checkout@v1
14
- - name: Setup Node.js
15
- uses: actions/setup-node@v1
16
- with:
17
- node-version: 20
18
- - name: Install dependencies
19
- run: npm ci
20
- - name: Test
21
- run: npm test
22
- - name: Release
23
- env:
24
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26
- run: npx semantic-release