color-name-list 11.9.0 → 11.10.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/.gitattributes +1 -0
- package/.github/workflows/build-and-release.yml +57 -0
- package/.github/workflows/build.yml +30 -15
- package/.github/workflows/linting.yml +4 -4
- package/.github/workflows/updatesponsors.yml +1 -1
- package/.husky/pre-commit +1 -1
- package/.prettierignore +5 -0
- package/.prettierrc.json +7 -0
- package/CODE_OF_CONDUCT.md +10 -10
- package/README.md +29 -24
- package/dist/colornames.bestof.csv +4532 -4532
- package/dist/colornames.csv +30290 -30289
- 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 +2885 -2885
- package/dist/colornames.umd.js +1 -1
- package/dist/colornames.xml +4 -0
- package/dist/colornames.yaml +3 -0
- package/dist/history.json +1 -1
- package/eslint.config.js +26 -0
- package/package.json +16 -6
- package/scripts/build.js +92 -99
- package/scripts/lib.js +42 -30
- package/scripts/tools/filterUniques.js +9 -12
- package/scripts/tools/findLargestSpacesInRGB.js +8 -13
- package/scripts/tools/history.js +18 -11
- package/scripts/tools/remapNames.js +2 -4
- package/scripts/tools/shiftColors.js +7 -7
- package/src/colornames.csv +30292 -30291
- package/tests/formats.test.js +46 -0
- package/tests/imports.test.js +119 -0
- package/vitest.config.js +8 -0
- package/.eslintrc.json +0 -17
- package/.github/workflows/release.yml +0 -26
- package/.travis.yml +0 -27
package/eslint.config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
|
|
5
|
+
const compat = new FlatCompat();
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
js.configs.recommended,
|
|
9
|
+
...compat.extends('google', 'prettier'),
|
|
10
|
+
{
|
|
11
|
+
languageOptions: {
|
|
12
|
+
ecmaVersion: 2023,
|
|
13
|
+
sourceType: 'module',
|
|
14
|
+
globals: {
|
|
15
|
+
...globals.node,
|
|
16
|
+
...globals.es2023,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
semi: ['error', 'always'],
|
|
21
|
+
'no-console': 'off',
|
|
22
|
+
'valid-jsdoc': 'off', // Disable deprecated rule that's causing errors
|
|
23
|
+
'require-jsdoc': 'off', // Disable rule that's causing errors with flat config
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "color-name-list",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.10.0",
|
|
4
4
|
"description": "long list of color names",
|
|
5
5
|
"main": "dist/colornames.json",
|
|
6
6
|
"browser": "dist/colornames.umd.js",
|
|
@@ -24,11 +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": "
|
|
28
|
-
"
|
|
29
|
-
"build": "
|
|
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
|
+
"prettier": "prettier --write ./dist/*",
|
|
31
|
+
"lint": "eslint ./scripts",
|
|
30
32
|
"semantic-release": "semantic-release",
|
|
31
33
|
"build-history": "node scripts/tools/history.js > dist/history.json",
|
|
34
|
+
"history": "node scripts/tools/history.js > dist/history.json",
|
|
32
35
|
"prepare": "husky"
|
|
33
36
|
},
|
|
34
37
|
"repository": {
|
|
@@ -50,14 +53,21 @@
|
|
|
50
53
|
},
|
|
51
54
|
"homepage": "https://github.com/meodai/color-names#readme",
|
|
52
55
|
"devDependencies": {
|
|
56
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
57
|
+
"@eslint/js": "^9.25.1",
|
|
53
58
|
"closestvector": "^0.6.0",
|
|
54
59
|
"color-name-lists": "^3.2.0",
|
|
55
60
|
"commitizen": "^4.2.4",
|
|
56
|
-
"eslint": "^
|
|
61
|
+
"eslint": "^9.25.1",
|
|
57
62
|
"eslint-config-google": "^0.10.0",
|
|
63
|
+
"eslint-config-prettier": "^10.1.2",
|
|
64
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
65
|
+
"globals": "^16.0.0",
|
|
58
66
|
"husky": "^9.1.6",
|
|
67
|
+
"prettier": "^3.5.3",
|
|
59
68
|
"seedrandom": "^3.0.5",
|
|
60
|
-
"semantic-release": "^24.2.0"
|
|
69
|
+
"semantic-release": "^24.2.0",
|
|
70
|
+
"vitest": "^3.1.2"
|
|
61
71
|
},
|
|
62
72
|
"engines": {
|
|
63
73
|
"node": ">=20.11.0",
|
package/scripts/build.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parseCSVString, findDuplicates, objArrToString } from './lib.js';
|
|
|
4
4
|
import { exec } from 'child_process';
|
|
5
5
|
|
|
6
6
|
const args = process.argv;
|
|
7
|
-
const isTestRun = !!args.find((arg) =>
|
|
7
|
+
const isTestRun = !!args.find((arg) => arg === '--testOnly');
|
|
8
8
|
|
|
9
9
|
// only hex colors with 6 values
|
|
10
10
|
const hexColorValidation = /^#[0-9a-f]{6}$/;
|
|
@@ -33,10 +33,9 @@ const csvKeys = ['name', 'hex'];
|
|
|
33
33
|
const bestOfKey = 'good name';
|
|
34
34
|
|
|
35
35
|
// reads the CSV file contents
|
|
36
|
-
const src = fs
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
).toString();
|
|
36
|
+
const src = fs
|
|
37
|
+
.readFileSync(path.normalize(`${baseFolder}${folderSrc}${fileNameSrc}.csv`), 'utf8')
|
|
38
|
+
.toString();
|
|
40
39
|
|
|
41
40
|
const colorsSrc = parseCSVString(src);
|
|
42
41
|
|
|
@@ -56,8 +55,12 @@ csvKeys.forEach((key) => {
|
|
|
56
55
|
// loop hex values for validations
|
|
57
56
|
colorsSrc.values['hex'].forEach((hex) => {
|
|
58
57
|
// validate HEX values
|
|
59
|
-
if (
|
|
60
|
-
log(
|
|
58
|
+
if (!hexColorValidation.test(hex)) {
|
|
59
|
+
log(
|
|
60
|
+
'hex',
|
|
61
|
+
hex,
|
|
62
|
+
`${hex} is not a valid hex value. (Or to short, we avoid using the hex shorthands, no capital letters)`
|
|
63
|
+
);
|
|
61
64
|
}
|
|
62
65
|
});
|
|
63
66
|
|
|
@@ -76,19 +79,11 @@ colorsSrc.values['name'].forEach((name) => {
|
|
|
76
79
|
colorsSrc.values[bestOfKey].forEach((str) => {
|
|
77
80
|
// check for spaces
|
|
78
81
|
if (spacesValidation.test(str)) {
|
|
79
|
-
log(
|
|
80
|
-
`"${bestOfKey}" marker'`,
|
|
81
|
-
str,
|
|
82
|
-
`${str} found either a leading or trailing space (or both)`
|
|
83
|
-
);
|
|
82
|
+
log(`"${bestOfKey}" marker'`, str, `${str} found either a leading or trailing space (or both)`);
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
if (!(str ==
|
|
87
|
-
log(
|
|
88
|
-
`"${bestOfKey}" marker`,
|
|
89
|
-
str,
|
|
90
|
-
`${str} must be a lowercase "x" character or empty`
|
|
91
|
-
);
|
|
85
|
+
if (!(str == 'x' || str == '')) {
|
|
86
|
+
log(`"${bestOfKey}" marker`, str, `${str} must be a lowercase "x" character or empty`);
|
|
92
87
|
}
|
|
93
88
|
});
|
|
94
89
|
|
|
@@ -101,7 +96,8 @@ if (isTestRun) {
|
|
|
101
96
|
|
|
102
97
|
// creates JS related files
|
|
103
98
|
const JSONExportString = JSON.stringify(
|
|
104
|
-
[...colorsSrc.entries].map(
|
|
99
|
+
[...colorsSrc.entries].map(
|
|
100
|
+
// removes good name attributes
|
|
105
101
|
(val) => ({
|
|
106
102
|
name: val.name,
|
|
107
103
|
hex: val.hex,
|
|
@@ -110,14 +106,15 @@ const JSONExportString = JSON.stringify(
|
|
|
110
106
|
);
|
|
111
107
|
|
|
112
108
|
const JSONExportStringBestOf = JSON.stringify(
|
|
113
|
-
[...colorsSrc.entries]
|
|
114
|
-
(val) =>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
[...colorsSrc.entries]
|
|
110
|
+
.filter((val) => val[bestOfKey])
|
|
111
|
+
.map(
|
|
112
|
+
// removes good name attributes
|
|
113
|
+
(val) => ({
|
|
114
|
+
name: val.name,
|
|
115
|
+
hex: val.hex,
|
|
116
|
+
})
|
|
117
|
+
)
|
|
121
118
|
);
|
|
122
119
|
|
|
123
120
|
const JSONExportStringShort = JSON.stringify(
|
|
@@ -126,7 +123,7 @@ const JSONExportStringShort = JSON.stringify(
|
|
|
126
123
|
// make sure its only one word long
|
|
127
124
|
(val) =>
|
|
128
125
|
val[bestOfKey] &&
|
|
129
|
-
//val.name.split(" ").length === 1 &&
|
|
126
|
+
// val.name.split(" ").length === 1 &&
|
|
130
127
|
val.name.length < maxShortNameLength + 1
|
|
131
128
|
)
|
|
132
129
|
.map(
|
|
@@ -138,10 +135,13 @@ const JSONExportStringShort = JSON.stringify(
|
|
|
138
135
|
)
|
|
139
136
|
);
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
);
|
|
138
|
+
// make sure dist folder exists
|
|
139
|
+
const distFolder = path.normalize(`${baseFolder}${folderDist}`);
|
|
140
|
+
if (!fs.existsSync(distFolder)) {
|
|
141
|
+
fs.mkdirSync(distFolder);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fs.writeFileSync(path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`), JSONExportString);
|
|
145
145
|
|
|
146
146
|
fs.writeFileSync(
|
|
147
147
|
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameBestOfPostfix}.json`),
|
|
@@ -160,7 +160,7 @@ const miniJSONExportObj = colorsSrc.entries.reduce((obj, entry) => {
|
|
|
160
160
|
}, {});
|
|
161
161
|
|
|
162
162
|
const miniJSONExportObjBestOf = colorsSrc.entries.reduce((obj, entry) => {
|
|
163
|
-
if(entry[bestOfKey]) {
|
|
163
|
+
if (entry[bestOfKey]) {
|
|
164
164
|
obj[entry.hex.replace('#', '')] = entry.name;
|
|
165
165
|
}
|
|
166
166
|
return obj;
|
|
@@ -169,10 +169,10 @@ const miniJSONExportObjBestOf = colorsSrc.entries.reduce((obj, entry) => {
|
|
|
169
169
|
const miniJSONExportObjShort = colorsSrc.entries.reduce((obj, entry) => {
|
|
170
170
|
if (
|
|
171
171
|
entry[bestOfKey] &&
|
|
172
|
-
//entry.name.split(" ").length === 1 &&
|
|
172
|
+
// entry.name.split(" ").length === 1 &&
|
|
173
173
|
entry.name.length < maxShortNameLength + 1
|
|
174
174
|
) {
|
|
175
|
-
obj[entry.hex.replace(
|
|
175
|
+
obj[entry.hex.replace('#', '')] = entry.name;
|
|
176
176
|
}
|
|
177
177
|
return obj;
|
|
178
178
|
}, {});
|
|
@@ -193,15 +193,12 @@ fs.writeFileSync(
|
|
|
193
193
|
);
|
|
194
194
|
|
|
195
195
|
// gets UMD template
|
|
196
|
-
const umdTpl = fs.readFileSync(
|
|
197
|
-
path.normalize(__dirname + '/umd.js.tpl'),
|
|
198
|
-
'utf8'
|
|
199
|
-
).toString();
|
|
196
|
+
const umdTpl = fs.readFileSync(path.normalize(__dirname + '/umd.js.tpl'), 'utf8').toString();
|
|
200
197
|
|
|
201
198
|
// create UMD
|
|
202
199
|
fs.writeFileSync(
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.umd.js`),
|
|
201
|
+
umdTpl.replace('"{{COLORS}}"', JSONExportString)
|
|
205
202
|
);
|
|
206
203
|
|
|
207
204
|
fs.writeFileSync(
|
|
@@ -215,19 +212,16 @@ fs.writeFileSync(
|
|
|
215
212
|
);
|
|
216
213
|
|
|
217
214
|
// gets ESM template
|
|
218
|
-
const esmTpl = fs.readFileSync(
|
|
219
|
-
path.normalize(__dirname + '/esm.js.tpl'),
|
|
220
|
-
'utf8'
|
|
221
|
-
).toString();
|
|
215
|
+
const esmTpl = fs.readFileSync(path.normalize(__dirname + '/esm.js.tpl'), 'utf8').toString();
|
|
222
216
|
|
|
223
217
|
// create ESM
|
|
224
218
|
fs.writeFileSync(
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.esm.js`),
|
|
220
|
+
esmTpl.replace('"{{COLORS}}"', JSONExportString)
|
|
227
221
|
);
|
|
228
222
|
fs.writeFileSync(
|
|
229
|
-
|
|
230
|
-
|
|
223
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.esm.mjs`),
|
|
224
|
+
esmTpl.replace('"{{COLORS}}"', JSONExportString)
|
|
231
225
|
);
|
|
232
226
|
|
|
233
227
|
fs.writeFileSync(
|
|
@@ -251,18 +245,18 @@ fs.writeFileSync(
|
|
|
251
245
|
// create foreign formats
|
|
252
246
|
// configuration for the file outputs
|
|
253
247
|
const outputFormats = {
|
|
254
|
-
|
|
255
|
-
insertBefore: csvKeys.join(',') + '\
|
|
248
|
+
csv: {
|
|
249
|
+
insertBefore: csvKeys.join(',') + '\n',
|
|
256
250
|
},
|
|
257
|
-
|
|
258
|
-
insertBefore: '-\
|
|
251
|
+
yaml: {
|
|
252
|
+
insertBefore: '-\n ',
|
|
259
253
|
beforeValue: '"',
|
|
260
254
|
afterValue: '"',
|
|
261
255
|
includeKeyPerItem: true,
|
|
262
|
-
rowDelimitor: '\
|
|
263
|
-
itemDelimitor: '\
|
|
256
|
+
rowDelimitor: '\n-\n ',
|
|
257
|
+
itemDelimitor: '\n ',
|
|
264
258
|
},
|
|
265
|
-
|
|
259
|
+
scss: {
|
|
266
260
|
insertBefore: '$color-name-list: (',
|
|
267
261
|
beforeValue: '"',
|
|
268
262
|
afterValue: '"',
|
|
@@ -270,33 +264,29 @@ const outputFormats = {
|
|
|
270
264
|
itemDelimitor: ':',
|
|
271
265
|
rowDelimitor: ',',
|
|
272
266
|
},
|
|
273
|
-
|
|
267
|
+
html: {
|
|
274
268
|
insertBefore: `<table><thead><tr><th>${csvKeys.join('</th><th>')}</th></tr><thead><tbody><tr><td>`,
|
|
275
269
|
itemDelimitor: '</td><td>',
|
|
276
270
|
rowDelimitor: '</td></tr><tr><td>',
|
|
277
271
|
insertAfter: `</td></tr></tbody></table>`,
|
|
278
272
|
},
|
|
279
|
-
|
|
280
|
-
insertBefore: `<?xml version='1.0'?>\
|
|
281
|
-
itemDelimitor: `</${csvKeys[0]}>\
|
|
282
|
-
rowDelimitor: `</${csvKeys[1]}>\
|
|
283
|
-
insertAfter: `</${csvKeys[1]}>\
|
|
273
|
+
xml: {
|
|
274
|
+
insertBefore: `<?xml version='1.0'?>\n<colors>\n<color>\n<${csvKeys[0]}>`,
|
|
275
|
+
itemDelimitor: `</${csvKeys[0]}>\n<${csvKeys[1]}>`,
|
|
276
|
+
rowDelimitor: `</${csvKeys[1]}>\n</color>\n<color>\n<${csvKeys[0]}>`,
|
|
277
|
+
insertAfter: `</${csvKeys[1]}>\n</color>\n</colors>`,
|
|
284
278
|
},
|
|
285
279
|
};
|
|
286
280
|
|
|
287
281
|
for (const outputFormat in outputFormats) {
|
|
288
282
|
if (outputFormats[outputFormat]) {
|
|
289
|
-
let outputString = objArrToString(
|
|
290
|
-
colorsSrc.entries,
|
|
291
|
-
csvKeys,
|
|
292
|
-
outputFormats[outputFormat]
|
|
293
|
-
);
|
|
283
|
+
let outputString = objArrToString(colorsSrc.entries, csvKeys, outputFormats[outputFormat]);
|
|
294
284
|
if (outputFormat === 'html' || outputFormat === 'xml') {
|
|
295
285
|
outputString = outputString.replace(/&/g, '&');
|
|
296
286
|
}
|
|
297
287
|
fs.writeFileSync(
|
|
298
|
-
|
|
299
|
-
|
|
288
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.${outputFormat}`),
|
|
289
|
+
outputString
|
|
300
290
|
);
|
|
301
291
|
}
|
|
302
292
|
}
|
|
@@ -305,7 +295,7 @@ for (const outputFormat in outputFormats) {
|
|
|
305
295
|
for (const outputFormat in outputFormats) {
|
|
306
296
|
if (outputFormats[outputFormat]) {
|
|
307
297
|
let outputString = objArrToString(
|
|
308
|
-
colorsSrc.entries.filter((val) =>
|
|
298
|
+
colorsSrc.entries.filter((val) => val[bestOfKey]),
|
|
309
299
|
csvKeys,
|
|
310
300
|
outputFormats[outputFormat]
|
|
311
301
|
);
|
|
@@ -313,7 +303,9 @@ for (const outputFormat in outputFormats) {
|
|
|
313
303
|
outputString = outputString.replace(/&/g, '&');
|
|
314
304
|
}
|
|
315
305
|
fs.writeFileSync(
|
|
316
|
-
path.normalize(
|
|
306
|
+
path.normalize(
|
|
307
|
+
`${baseFolder}${folderDist}${fileNameSrc}${fileNameBestOfPostfix}.${outputFormat}`
|
|
308
|
+
),
|
|
317
309
|
outputString
|
|
318
310
|
);
|
|
319
311
|
}
|
|
@@ -326,7 +318,7 @@ for (const outputFormat in outputFormats) {
|
|
|
326
318
|
colorsSrc.entries.filter(
|
|
327
319
|
(val) =>
|
|
328
320
|
val[bestOfKey] &&
|
|
329
|
-
//val.name.split(" ").length === 1 &&
|
|
321
|
+
// val.name.split(" ").length === 1 &&
|
|
330
322
|
val.name.length < maxShortNameLength + 1
|
|
331
323
|
),
|
|
332
324
|
csvKeys,
|
|
@@ -336,38 +328,44 @@ for (const outputFormat in outputFormats) {
|
|
|
336
328
|
outputString = outputString.replace(/&/g, '&');
|
|
337
329
|
}
|
|
338
330
|
fs.writeFileSync(
|
|
339
|
-
path.normalize(
|
|
331
|
+
path.normalize(
|
|
332
|
+
`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.${outputFormat}`
|
|
333
|
+
),
|
|
340
334
|
outputString
|
|
341
335
|
);
|
|
342
336
|
}
|
|
343
337
|
}
|
|
344
338
|
|
|
345
339
|
// updates the color count in readme file
|
|
346
|
-
const readme = fs.readFileSync(
|
|
347
|
-
path.normalize(`${baseFolder}${readmeFileName}`),
|
|
348
|
-
'utf8'
|
|
349
|
-
).toString();
|
|
340
|
+
const readme = fs.readFileSync(path.normalize(`${baseFolder}${readmeFileName}`), 'utf8').toString();
|
|
350
341
|
fs.writeFileSync(
|
|
351
342
|
path.normalize(`${baseFolder}${readmeFileName}`),
|
|
352
|
-
readme
|
|
343
|
+
readme
|
|
344
|
+
.replace(
|
|
353
345
|
// update color count in text
|
|
354
346
|
/__\d+__/g,
|
|
355
347
|
`__${colorsSrc.entries.length}__`
|
|
356
|
-
)
|
|
348
|
+
)
|
|
349
|
+
.replace(
|
|
357
350
|
// update color count in badge
|
|
358
351
|
/\d+-colors-orange/,
|
|
359
352
|
`${colorsSrc.entries.length}-colors-orange`
|
|
360
|
-
)
|
|
353
|
+
)
|
|
354
|
+
.replace(
|
|
361
355
|
// update color count in percentage
|
|
362
356
|
/__\d+(\.\d+)?%__/,
|
|
363
357
|
`__${((colorsSrc.entries.length / (256 * 256 * 256)) * 100).toFixed(2)}%__`
|
|
364
|
-
)
|
|
358
|
+
)
|
|
359
|
+
.replace(
|
|
365
360
|
// update file size
|
|
366
361
|
/\d+(\.\d+)? MB\)__/g,
|
|
367
|
-
`${
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
362
|
+
`${(
|
|
363
|
+
fs.statSync(path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`)).size /
|
|
364
|
+
1024 /
|
|
365
|
+
1024
|
|
366
|
+
).toFixed(2)} MB)__`
|
|
367
|
+
),
|
|
368
|
+
'utf8'
|
|
371
369
|
);
|
|
372
370
|
|
|
373
371
|
/**
|
|
@@ -384,7 +382,7 @@ function showLog() {
|
|
|
384
382
|
console.log('*-------------------------*');
|
|
385
383
|
});
|
|
386
384
|
if (errorLevel) {
|
|
387
|
-
throw `⚠ failed because of the ${totalErrors} error${totalErrors > 1 ? 's' : ''} above
|
|
385
|
+
throw new Error(`⚠ failed because of the ${totalErrors} error${totalErrors > 1 ? 's' : ''} above ⚠`);
|
|
388
386
|
}
|
|
389
387
|
return totalErrors;
|
|
390
388
|
}
|
|
@@ -410,10 +408,7 @@ function log(key, value, message, errorLevel = 1) {
|
|
|
410
408
|
}
|
|
411
409
|
|
|
412
410
|
// gets SVG template
|
|
413
|
-
const svgTpl = fs.readFileSync(
|
|
414
|
-
path.normalize(__dirname + '/changes.svg.tpl'),
|
|
415
|
-
'utf8'
|
|
416
|
-
).toString();
|
|
411
|
+
const svgTpl = fs.readFileSync(path.normalize(__dirname + '/changes.svg.tpl'), 'utf8').toString();
|
|
417
412
|
|
|
418
413
|
// generates an SVG image with the new color based on the diff ot the last commit to the current
|
|
419
414
|
function diffSVG() {
|
|
@@ -421,23 +416,21 @@ function diffSVG() {
|
|
|
421
416
|
`git diff -U0 HEAD ${baseFolder}${folderDist}${fileNameSrc}.csv`,
|
|
422
417
|
function (err, stdout, stderr) {
|
|
423
418
|
const diffTxt = stdout;
|
|
424
|
-
if (!/(?<=^[
|
|
425
|
-
const changes = diffTxt.match(/(?<=^[
|
|
419
|
+
if (!/(?<=^[+])[^+].*/gm.test(diffTxt)) return;
|
|
420
|
+
const changes = diffTxt.match(/(?<=^[+])[^+].*/gm).filter((i) => i);
|
|
426
421
|
const svgTxtStr = changes.reduce((str, change, i) => {
|
|
427
|
-
const changeParts = change.split(
|
|
422
|
+
const changeParts = change.split(',');
|
|
428
423
|
return `${str}<text x="40" y="${20 + (i + 1) * 70}" fill="${
|
|
429
424
|
changeParts[1]
|
|
430
|
-
}">${changeParts[0].replace(/&/g,
|
|
431
|
-
},
|
|
425
|
+
}">${changeParts[0].replace(/&/g, '&')}</text>`;
|
|
426
|
+
}, '');
|
|
432
427
|
|
|
433
428
|
fs.writeFileSync(
|
|
434
429
|
path.normalize(`${baseFolder}changes.svg`),
|
|
435
|
-
svgTpl
|
|
436
|
-
.replace(/{height}/g, changes.length * 70 + 80)
|
|
437
|
-
.replace(/{items}/g, svgTxtStr)
|
|
430
|
+
svgTpl.replace(/{height}/g, changes.length * 70 + 80).replace(/{items}/g, svgTxtStr)
|
|
438
431
|
);
|
|
439
432
|
}
|
|
440
433
|
);
|
|
441
|
-
}
|
|
434
|
+
}
|
|
442
435
|
|
|
443
436
|
diffSVG();
|
package/scripts/lib.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* takes a CSV string an parse it
|
|
4
3
|
* @param {String} csvString CSV file contents
|
|
@@ -7,9 +6,7 @@
|
|
|
7
6
|
* @return {Object} Object with all entries, headers as Array,
|
|
8
7
|
* and entires per header as Array
|
|
9
8
|
*/
|
|
10
|
-
export const parseCSVString = (
|
|
11
|
-
csvString, csvDelimitor = ',', csvNewLine = '\r\n'
|
|
12
|
-
) => {
|
|
9
|
+
export const parseCSVString = (csvString, csvDelimitor = ',', csvNewLine = /\r?\n/) => {
|
|
13
10
|
const rows = csvString.split(csvNewLine);
|
|
14
11
|
|
|
15
12
|
// remove last empty row (if there is any)
|
|
@@ -46,7 +43,7 @@ export const parseCSVString = (
|
|
|
46
43
|
return entry;
|
|
47
44
|
});
|
|
48
45
|
|
|
49
|
-
return {headers, entries, values};
|
|
46
|
+
return { headers, entries, values };
|
|
50
47
|
};
|
|
51
48
|
|
|
52
49
|
/**
|
|
@@ -55,40 +52,55 @@ export const parseCSVString = (
|
|
|
55
52
|
* @return {array} array of second (or more) instance of duplicate items
|
|
56
53
|
*/
|
|
57
54
|
export const findDuplicates = (arr) => {
|
|
58
|
-
const lookUpObj={};
|
|
55
|
+
const lookUpObj = {};
|
|
59
56
|
const dupes = [];
|
|
60
57
|
|
|
61
58
|
arr.forEach((item) => {
|
|
62
|
-
if (
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(lookUpObj, item)) {
|
|
63
60
|
dupes.push(item);
|
|
64
61
|
}
|
|
65
|
-
lookUpObj[item]=0;
|
|
62
|
+
lookUpObj[item] = 0;
|
|
66
63
|
});
|
|
67
64
|
|
|
68
65
|
return dupes;
|
|
69
66
|
};
|
|
70
67
|
|
|
71
68
|
export const objArrToString = (arr, keys, options) => {
|
|
72
|
-
const settings = Object.assign(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
const settings = Object.assign(
|
|
70
|
+
{},
|
|
71
|
+
{
|
|
72
|
+
includeKeyPerItem: false,
|
|
73
|
+
beforeKey: '',
|
|
74
|
+
afterKey: '',
|
|
75
|
+
beforeValue: '',
|
|
76
|
+
afterValue: '',
|
|
77
|
+
keyValueSeparator: ':',
|
|
78
|
+
insertBefore: '',
|
|
79
|
+
insertAfter: '',
|
|
80
|
+
rowDelimitor: '\r\n',
|
|
81
|
+
itemDelimitor: ',',
|
|
82
|
+
},
|
|
83
|
+
options
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
settings.insertBefore +
|
|
88
|
+
arr
|
|
89
|
+
.map((item) => {
|
|
90
|
+
return keys
|
|
91
|
+
.map((key) => {
|
|
92
|
+
return (
|
|
93
|
+
(settings.includeKeyPerItem
|
|
94
|
+
? settings.beforeKey + key + settings.afterKey + settings.keyValueSeparator
|
|
95
|
+
: '') +
|
|
96
|
+
settings.beforeValue +
|
|
97
|
+
item[key] +
|
|
98
|
+
settings.afterValue
|
|
99
|
+
);
|
|
100
|
+
})
|
|
101
|
+
.join(settings.itemDelimitor);
|
|
102
|
+
})
|
|
103
|
+
.join(settings.rowDelimitor) +
|
|
104
|
+
settings.insertAfter
|
|
105
|
+
);
|
|
94
106
|
};
|
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
|
|
3
|
-
//const colors = fs.readFileSync('refs.csv').toString().split(`\n`);
|
|
4
|
-
//const colorsSRCfile = fs.readFileSync(__dirname + '/../../historic-master.json', 'utf8');
|
|
3
|
+
// const colors = fs.readFileSync('refs.csv').toString().split(`\n`);
|
|
4
|
+
// const colorsSRCfile = fs.readFileSync(__dirname + '/../../historic-master.json', 'utf8');
|
|
5
5
|
const colorsSRCfile = fs.readFileSync(__dirname + '/json.json', 'utf8');
|
|
6
6
|
|
|
7
7
|
const colors = JSON.parse(colorsSRCfile);
|
|
8
8
|
|
|
9
|
-
const namedColors = JSON.parse(
|
|
10
|
-
fs.readFileSync(__dirname + '/../../dist/colornames.json', 'utf8')
|
|
11
|
-
);
|
|
9
|
+
const namedColors = JSON.parse(fs.readFileSync(__dirname + '/../../dist/colornames.json', 'utf8'));
|
|
12
10
|
|
|
13
11
|
const uniqueColors = [];
|
|
14
12
|
|
|
15
13
|
colors.forEach((color) => {
|
|
16
14
|
let name = color['name'].replace(/Gray/g, 'Grey');
|
|
17
|
-
const foundMath = namedColors.find(item => {
|
|
18
|
-
return
|
|
15
|
+
const foundMath = namedColors.find((item) => {
|
|
16
|
+
return (
|
|
17
|
+
item.name.toLowerCase() === name.toLowerCase() ||
|
|
19
18
|
item.name.toLowerCase() === name.toLowerCase().split(' ').reverse().join(' ') ||
|
|
20
19
|
item.name.toLowerCase() === name.toLowerCase().split(' ').join('-') ||
|
|
21
|
-
item.name.toLowerCase() === name.toLowerCase().split('-').join(' ')
|
|
20
|
+
item.name.toLowerCase() === name.toLowerCase().split('-').join(' ')
|
|
21
|
+
);
|
|
22
22
|
});
|
|
23
23
|
if (!foundMath) {
|
|
24
|
-
uniqueColors.push([
|
|
25
|
-
name,
|
|
26
|
-
color['hex'].toLowerCase()
|
|
27
|
-
]);
|
|
24
|
+
uniqueColors.push([name, color['hex'].toLowerCase()]);
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const RGB_HEX = /^#?(?:([\da-f]{3})[\da-f]?|([\da-f]{6})(?:[\da-f]{2})?)$/i;
|
|
3
3
|
|
|
4
|
-
const namedColors = JSON.parse(
|
|
5
|
-
fs.readFileSync(__dirname + '/../../dist/colornames.json', 'utf8')
|
|
6
|
-
);
|
|
4
|
+
const namedColors = JSON.parse(fs.readFileSync(__dirname + '/../../dist/colornames.json', 'utf8'));
|
|
7
5
|
|
|
8
6
|
const hexToRgb = (hexSrt) => {
|
|
9
7
|
const [, short, long] = String(hexSrt).match(RGB_HEX) || [];
|
|
@@ -12,13 +10,11 @@ const hexToRgb = (hexSrt) => {
|
|
|
12
10
|
const value = Number.parseInt(long, 16);
|
|
13
11
|
return {
|
|
14
12
|
r: value >> 16,
|
|
15
|
-
g: value >> 8 &
|
|
16
|
-
b: value &
|
|
13
|
+
g: (value >> 8) & 0xff,
|
|
14
|
+
b: value & 0xff,
|
|
17
15
|
};
|
|
18
16
|
} else if (short) {
|
|
19
|
-
const rgbArray = Array.from(short,
|
|
20
|
-
(s) => Number.parseInt(s, 16)
|
|
21
|
-
).map((n) => (n << 4) | n);
|
|
17
|
+
const rgbArray = Array.from(short, (s) => Number.parseInt(s, 16)).map((n) => (n << 4) | n);
|
|
22
18
|
return {
|
|
23
19
|
r: rgbArray[0],
|
|
24
20
|
g: rgbArray[1],
|
|
@@ -28,11 +24,10 @@ const hexToRgb = (hexSrt) => {
|
|
|
28
24
|
};
|
|
29
25
|
|
|
30
26
|
const rgbColors = namedColors.map((color) => {
|
|
31
|
-
const {r,g,b} = hexToRgb(color.hex);
|
|
27
|
+
const { r, g, b } = hexToRgb(color.hex);
|
|
32
28
|
return [r, g, b];
|
|
33
29
|
});
|
|
34
30
|
|
|
35
|
-
|
|
36
31
|
function calculateDistance(r, g, b, rgbColors) {
|
|
37
32
|
let distance = 0;
|
|
38
33
|
for (let i = 0; i < rgbColors.length; i++) {
|
|
@@ -46,9 +41,9 @@ function calculateDistance(r, g, b, rgbColors) {
|
|
|
46
41
|
function findLargestSpaceInRGB(rgbColors) {
|
|
47
42
|
const rgb = [0, 0, 0];
|
|
48
43
|
let largestDistance = 0;
|
|
49
|
-
for (let i = 0; i < 256; i+=10) {
|
|
50
|
-
for (let j = 0; j < 256; j+=10) {
|
|
51
|
-
for (let k = 0; k < 256; k+=10) {
|
|
44
|
+
for (let i = 0; i < 256; i += 10) {
|
|
45
|
+
for (let j = 0; j < 256; j += 10) {
|
|
46
|
+
for (let k = 0; k < 256; k += 10) {
|
|
52
47
|
const distance = calculateDistance(i, j, k, rgbColors);
|
|
53
48
|
if (distance > largestDistance) {
|
|
54
49
|
largestDistance = distance;
|