color-name-list 11.8.0 → 11.9.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.
- package/.gitattributes +1 -0
- package/.github/workflows/build.yml +11 -11
- package/.github/workflows/linting.yml +4 -4
- package/.github/workflows/release.yml +1 -1
- package/.github/workflows/updatesponsors.yml +1 -1
- package/.prettierignore +5 -0
- package/.prettierrc.json +7 -0
- package/CODE_OF_CONDUCT.md +10 -10
- package/README.md +21 -21
- package/changes.svg +3 -3
- package/dist/colornames.bestof.csv +8 -0
- package/dist/colornames.bestof.esm.js +4535 -1
- package/dist/colornames.bestof.esm.mjs +4535 -1
- package/dist/colornames.bestof.html +1 -1
- package/dist/colornames.bestof.json +4535 -1
- package/dist/colornames.bestof.min.json +1 -1
- package/dist/colornames.bestof.scss +4535 -1
- package/dist/colornames.bestof.umd.js +4543 -1
- package/dist/colornames.bestof.xml +32 -0
- package/dist/colornames.bestof.yaml +4542 -9051
- package/dist/colornames.csv +11 -1
- package/dist/colornames.esm.js +30292 -1
- package/dist/colornames.esm.mjs +30292 -1
- package/dist/colornames.html +1 -1
- package/dist/colornames.json +30292 -1
- package/dist/colornames.min.json +1 -1
- package/dist/colornames.scss +30292 -1
- package/dist/colornames.short.csv +6 -0
- package/dist/colornames.short.esm.js +2888 -1
- package/dist/colornames.short.esm.mjs +2888 -1
- package/dist/colornames.short.html +1 -1
- package/dist/colornames.short.json +2888 -1
- package/dist/colornames.short.min.json +1 -1
- package/dist/colornames.short.scss +2888 -1
- package/dist/colornames.short.umd.js +2896 -1
- package/dist/colornames.short.xml +24 -0
- package/dist/colornames.short.yaml +2893 -5761
- package/dist/colornames.umd.js +30300 -1
- package/dist/colornames.xml +41 -1
- package/dist/colornames.yaml +30301 -60561
- package/dist/history.json +61120 -1
- package/eslint.config.js +26 -0
- package/package.json +11 -3
- package/scripts/build.js +86 -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 +13 -11
- package/scripts/tools/remapNames.js +2 -4
- package/scripts/tools/shiftColors.js +7 -7
- package/src/colornames.csv +30290 -30280
- package/.eslintrc.json +0 -17
- 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.9.1",
|
|
4
4
|
"description": "long list of color names",
|
|
5
5
|
"main": "dist/colornames.json",
|
|
6
6
|
"browser": "dist/colornames.umd.js",
|
|
@@ -26,7 +26,9 @@
|
|
|
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
27
|
"test": "node scripts/build.js --testOnly",
|
|
28
28
|
"clean-dist-folder": "rm -rf dist && mkdir dist",
|
|
29
|
-
"build": "npm run clean-dist-folder && node scripts/build.js && npm run build-history",
|
|
29
|
+
"build": "npm run clean-dist-folder && node scripts/build.js && npm run build-history && 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",
|
|
32
34
|
"prepare": "husky"
|
|
@@ -50,12 +52,18 @@
|
|
|
50
52
|
},
|
|
51
53
|
"homepage": "https://github.com/meodai/color-names#readme",
|
|
52
54
|
"devDependencies": {
|
|
55
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
56
|
+
"@eslint/js": "^9.25.1",
|
|
53
57
|
"closestvector": "^0.6.0",
|
|
54
58
|
"color-name-lists": "^3.2.0",
|
|
55
59
|
"commitizen": "^4.2.4",
|
|
56
|
-
"eslint": "^
|
|
60
|
+
"eslint": "^9.25.1",
|
|
57
61
|
"eslint-config-google": "^0.10.0",
|
|
62
|
+
"eslint-config-prettier": "^10.1.2",
|
|
63
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
64
|
+
"globals": "^16.0.0",
|
|
58
65
|
"husky": "^9.1.6",
|
|
66
|
+
"prettier": "^3.5.3",
|
|
59
67
|
"seedrandom": "^3.0.5",
|
|
60
68
|
"semantic-release": "^24.2.0"
|
|
61
69
|
},
|
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,7 @@ const JSONExportStringShort = JSON.stringify(
|
|
|
138
135
|
)
|
|
139
136
|
);
|
|
140
137
|
|
|
141
|
-
fs.writeFileSync(
|
|
142
|
-
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`),
|
|
143
|
-
JSONExportString
|
|
144
|
-
);
|
|
138
|
+
fs.writeFileSync(path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`), JSONExportString);
|
|
145
139
|
|
|
146
140
|
fs.writeFileSync(
|
|
147
141
|
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameBestOfPostfix}.json`),
|
|
@@ -160,7 +154,7 @@ const miniJSONExportObj = colorsSrc.entries.reduce((obj, entry) => {
|
|
|
160
154
|
}, {});
|
|
161
155
|
|
|
162
156
|
const miniJSONExportObjBestOf = colorsSrc.entries.reduce((obj, entry) => {
|
|
163
|
-
if(entry[bestOfKey]) {
|
|
157
|
+
if (entry[bestOfKey]) {
|
|
164
158
|
obj[entry.hex.replace('#', '')] = entry.name;
|
|
165
159
|
}
|
|
166
160
|
return obj;
|
|
@@ -169,10 +163,10 @@ const miniJSONExportObjBestOf = colorsSrc.entries.reduce((obj, entry) => {
|
|
|
169
163
|
const miniJSONExportObjShort = colorsSrc.entries.reduce((obj, entry) => {
|
|
170
164
|
if (
|
|
171
165
|
entry[bestOfKey] &&
|
|
172
|
-
//entry.name.split(" ").length === 1 &&
|
|
166
|
+
// entry.name.split(" ").length === 1 &&
|
|
173
167
|
entry.name.length < maxShortNameLength + 1
|
|
174
168
|
) {
|
|
175
|
-
obj[entry.hex.replace(
|
|
169
|
+
obj[entry.hex.replace('#', '')] = entry.name;
|
|
176
170
|
}
|
|
177
171
|
return obj;
|
|
178
172
|
}, {});
|
|
@@ -193,15 +187,12 @@ fs.writeFileSync(
|
|
|
193
187
|
);
|
|
194
188
|
|
|
195
189
|
// gets UMD template
|
|
196
|
-
const umdTpl = fs.readFileSync(
|
|
197
|
-
path.normalize(__dirname + '/umd.js.tpl'),
|
|
198
|
-
'utf8'
|
|
199
|
-
).toString();
|
|
190
|
+
const umdTpl = fs.readFileSync(path.normalize(__dirname + '/umd.js.tpl'), 'utf8').toString();
|
|
200
191
|
|
|
201
192
|
// create UMD
|
|
202
193
|
fs.writeFileSync(
|
|
203
|
-
|
|
204
|
-
|
|
194
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.umd.js`),
|
|
195
|
+
umdTpl.replace('"{{COLORS}}"', JSONExportString)
|
|
205
196
|
);
|
|
206
197
|
|
|
207
198
|
fs.writeFileSync(
|
|
@@ -215,19 +206,16 @@ fs.writeFileSync(
|
|
|
215
206
|
);
|
|
216
207
|
|
|
217
208
|
// gets ESM template
|
|
218
|
-
const esmTpl = fs.readFileSync(
|
|
219
|
-
path.normalize(__dirname + '/esm.js.tpl'),
|
|
220
|
-
'utf8'
|
|
221
|
-
).toString();
|
|
209
|
+
const esmTpl = fs.readFileSync(path.normalize(__dirname + '/esm.js.tpl'), 'utf8').toString();
|
|
222
210
|
|
|
223
211
|
// create ESM
|
|
224
212
|
fs.writeFileSync(
|
|
225
|
-
|
|
226
|
-
|
|
213
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.esm.js`),
|
|
214
|
+
esmTpl.replace('"{{COLORS}}"', JSONExportString)
|
|
227
215
|
);
|
|
228
216
|
fs.writeFileSync(
|
|
229
|
-
|
|
230
|
-
|
|
217
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.esm.mjs`),
|
|
218
|
+
esmTpl.replace('"{{COLORS}}"', JSONExportString)
|
|
231
219
|
);
|
|
232
220
|
|
|
233
221
|
fs.writeFileSync(
|
|
@@ -251,18 +239,18 @@ fs.writeFileSync(
|
|
|
251
239
|
// create foreign formats
|
|
252
240
|
// configuration for the file outputs
|
|
253
241
|
const outputFormats = {
|
|
254
|
-
|
|
255
|
-
insertBefore: csvKeys.join(',') + '\
|
|
242
|
+
csv: {
|
|
243
|
+
insertBefore: csvKeys.join(',') + '\n',
|
|
256
244
|
},
|
|
257
|
-
|
|
258
|
-
insertBefore: '-\
|
|
245
|
+
yaml: {
|
|
246
|
+
insertBefore: '-\n ',
|
|
259
247
|
beforeValue: '"',
|
|
260
248
|
afterValue: '"',
|
|
261
249
|
includeKeyPerItem: true,
|
|
262
|
-
rowDelimitor: '\
|
|
263
|
-
itemDelimitor: '\
|
|
250
|
+
rowDelimitor: '\n-\n ',
|
|
251
|
+
itemDelimitor: '\n ',
|
|
264
252
|
},
|
|
265
|
-
|
|
253
|
+
scss: {
|
|
266
254
|
insertBefore: '$color-name-list: (',
|
|
267
255
|
beforeValue: '"',
|
|
268
256
|
afterValue: '"',
|
|
@@ -270,33 +258,29 @@ const outputFormats = {
|
|
|
270
258
|
itemDelimitor: ':',
|
|
271
259
|
rowDelimitor: ',',
|
|
272
260
|
},
|
|
273
|
-
|
|
261
|
+
html: {
|
|
274
262
|
insertBefore: `<table><thead><tr><th>${csvKeys.join('</th><th>')}</th></tr><thead><tbody><tr><td>`,
|
|
275
263
|
itemDelimitor: '</td><td>',
|
|
276
264
|
rowDelimitor: '</td></tr><tr><td>',
|
|
277
265
|
insertAfter: `</td></tr></tbody></table>`,
|
|
278
266
|
},
|
|
279
|
-
|
|
280
|
-
insertBefore: `<?xml version='1.0'?>\
|
|
281
|
-
itemDelimitor: `</${csvKeys[0]}>\
|
|
282
|
-
rowDelimitor: `</${csvKeys[1]}>\
|
|
283
|
-
insertAfter: `</${csvKeys[1]}>\
|
|
267
|
+
xml: {
|
|
268
|
+
insertBefore: `<?xml version='1.0'?>\n<colors>\n<color>\n<${csvKeys[0]}>`,
|
|
269
|
+
itemDelimitor: `</${csvKeys[0]}>\n<${csvKeys[1]}>`,
|
|
270
|
+
rowDelimitor: `</${csvKeys[1]}>\n</color>\n<color>\n<${csvKeys[0]}>`,
|
|
271
|
+
insertAfter: `</${csvKeys[1]}>\n</color>\n</colors>`,
|
|
284
272
|
},
|
|
285
273
|
};
|
|
286
274
|
|
|
287
275
|
for (const outputFormat in outputFormats) {
|
|
288
276
|
if (outputFormats[outputFormat]) {
|
|
289
|
-
let outputString = objArrToString(
|
|
290
|
-
colorsSrc.entries,
|
|
291
|
-
csvKeys,
|
|
292
|
-
outputFormats[outputFormat]
|
|
293
|
-
);
|
|
277
|
+
let outputString = objArrToString(colorsSrc.entries, csvKeys, outputFormats[outputFormat]);
|
|
294
278
|
if (outputFormat === 'html' || outputFormat === 'xml') {
|
|
295
279
|
outputString = outputString.replace(/&/g, '&');
|
|
296
280
|
}
|
|
297
281
|
fs.writeFileSync(
|
|
298
|
-
|
|
299
|
-
|
|
282
|
+
path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.${outputFormat}`),
|
|
283
|
+
outputString
|
|
300
284
|
);
|
|
301
285
|
}
|
|
302
286
|
}
|
|
@@ -305,7 +289,7 @@ for (const outputFormat in outputFormats) {
|
|
|
305
289
|
for (const outputFormat in outputFormats) {
|
|
306
290
|
if (outputFormats[outputFormat]) {
|
|
307
291
|
let outputString = objArrToString(
|
|
308
|
-
colorsSrc.entries.filter((val) =>
|
|
292
|
+
colorsSrc.entries.filter((val) => val[bestOfKey]),
|
|
309
293
|
csvKeys,
|
|
310
294
|
outputFormats[outputFormat]
|
|
311
295
|
);
|
|
@@ -313,7 +297,9 @@ for (const outputFormat in outputFormats) {
|
|
|
313
297
|
outputString = outputString.replace(/&/g, '&');
|
|
314
298
|
}
|
|
315
299
|
fs.writeFileSync(
|
|
316
|
-
path.normalize(
|
|
300
|
+
path.normalize(
|
|
301
|
+
`${baseFolder}${folderDist}${fileNameSrc}${fileNameBestOfPostfix}.${outputFormat}`
|
|
302
|
+
),
|
|
317
303
|
outputString
|
|
318
304
|
);
|
|
319
305
|
}
|
|
@@ -326,7 +312,7 @@ for (const outputFormat in outputFormats) {
|
|
|
326
312
|
colorsSrc.entries.filter(
|
|
327
313
|
(val) =>
|
|
328
314
|
val[bestOfKey] &&
|
|
329
|
-
//val.name.split(" ").length === 1 &&
|
|
315
|
+
// val.name.split(" ").length === 1 &&
|
|
330
316
|
val.name.length < maxShortNameLength + 1
|
|
331
317
|
),
|
|
332
318
|
csvKeys,
|
|
@@ -336,38 +322,44 @@ for (const outputFormat in outputFormats) {
|
|
|
336
322
|
outputString = outputString.replace(/&/g, '&');
|
|
337
323
|
}
|
|
338
324
|
fs.writeFileSync(
|
|
339
|
-
path.normalize(
|
|
325
|
+
path.normalize(
|
|
326
|
+
`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.${outputFormat}`
|
|
327
|
+
),
|
|
340
328
|
outputString
|
|
341
329
|
);
|
|
342
330
|
}
|
|
343
331
|
}
|
|
344
332
|
|
|
345
333
|
// updates the color count in readme file
|
|
346
|
-
const readme = fs.readFileSync(
|
|
347
|
-
path.normalize(`${baseFolder}${readmeFileName}`),
|
|
348
|
-
'utf8'
|
|
349
|
-
).toString();
|
|
334
|
+
const readme = fs.readFileSync(path.normalize(`${baseFolder}${readmeFileName}`), 'utf8').toString();
|
|
350
335
|
fs.writeFileSync(
|
|
351
336
|
path.normalize(`${baseFolder}${readmeFileName}`),
|
|
352
|
-
readme
|
|
337
|
+
readme
|
|
338
|
+
.replace(
|
|
353
339
|
// update color count in text
|
|
354
340
|
/__\d+__/g,
|
|
355
341
|
`__${colorsSrc.entries.length}__`
|
|
356
|
-
)
|
|
342
|
+
)
|
|
343
|
+
.replace(
|
|
357
344
|
// update color count in badge
|
|
358
345
|
/\d+-colors-orange/,
|
|
359
346
|
`${colorsSrc.entries.length}-colors-orange`
|
|
360
|
-
)
|
|
347
|
+
)
|
|
348
|
+
.replace(
|
|
361
349
|
// update color count in percentage
|
|
362
350
|
/__\d+(\.\d+)?%__/,
|
|
363
351
|
`__${((colorsSrc.entries.length / (256 * 256 * 256)) * 100).toFixed(2)}%__`
|
|
364
|
-
)
|
|
352
|
+
)
|
|
353
|
+
.replace(
|
|
365
354
|
// update file size
|
|
366
355
|
/\d+(\.\d+)? MB\)__/g,
|
|
367
|
-
`${
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
356
|
+
`${(
|
|
357
|
+
fs.statSync(path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`)).size /
|
|
358
|
+
1024 /
|
|
359
|
+
1024
|
|
360
|
+
).toFixed(2)} MB)__`
|
|
361
|
+
),
|
|
362
|
+
'utf8'
|
|
371
363
|
);
|
|
372
364
|
|
|
373
365
|
/**
|
|
@@ -384,7 +376,7 @@ function showLog() {
|
|
|
384
376
|
console.log('*-------------------------*');
|
|
385
377
|
});
|
|
386
378
|
if (errorLevel) {
|
|
387
|
-
throw `⚠ failed because of the ${totalErrors} error${totalErrors > 1 ? 's' : ''} above
|
|
379
|
+
throw new Error(`⚠ failed because of the ${totalErrors} error${totalErrors > 1 ? 's' : ''} above ⚠`);
|
|
388
380
|
}
|
|
389
381
|
return totalErrors;
|
|
390
382
|
}
|
|
@@ -410,10 +402,7 @@ function log(key, value, message, errorLevel = 1) {
|
|
|
410
402
|
}
|
|
411
403
|
|
|
412
404
|
// gets SVG template
|
|
413
|
-
const svgTpl = fs.readFileSync(
|
|
414
|
-
path.normalize(__dirname + '/changes.svg.tpl'),
|
|
415
|
-
'utf8'
|
|
416
|
-
).toString();
|
|
405
|
+
const svgTpl = fs.readFileSync(path.normalize(__dirname + '/changes.svg.tpl'), 'utf8').toString();
|
|
417
406
|
|
|
418
407
|
// generates an SVG image with the new color based on the diff ot the last commit to the current
|
|
419
408
|
function diffSVG() {
|
|
@@ -421,23 +410,21 @@ function diffSVG() {
|
|
|
421
410
|
`git diff -U0 HEAD ${baseFolder}${folderDist}${fileNameSrc}.csv`,
|
|
422
411
|
function (err, stdout, stderr) {
|
|
423
412
|
const diffTxt = stdout;
|
|
424
|
-
if (!/(?<=^[
|
|
425
|
-
const changes = diffTxt.match(/(?<=^[
|
|
413
|
+
if (!/(?<=^[+])[^+].*/gm.test(diffTxt)) return;
|
|
414
|
+
const changes = diffTxt.match(/(?<=^[+])[^+].*/gm).filter((i) => i);
|
|
426
415
|
const svgTxtStr = changes.reduce((str, change, i) => {
|
|
427
|
-
const changeParts = change.split(
|
|
416
|
+
const changeParts = change.split(',');
|
|
428
417
|
return `${str}<text x="40" y="${20 + (i + 1) * 70}" fill="${
|
|
429
418
|
changeParts[1]
|
|
430
|
-
}">${changeParts[0].replace(/&/g,
|
|
431
|
-
},
|
|
419
|
+
}">${changeParts[0].replace(/&/g, '&')}</text>`;
|
|
420
|
+
}, '');
|
|
432
421
|
|
|
433
422
|
fs.writeFileSync(
|
|
434
423
|
path.normalize(`${baseFolder}changes.svg`),
|
|
435
|
-
svgTpl
|
|
436
|
-
.replace(/{height}/g, changes.length * 70 + 80)
|
|
437
|
-
.replace(/{items}/g, svgTxtStr)
|
|
424
|
+
svgTpl.replace(/{height}/g, changes.length * 70 + 80).replace(/{items}/g, svgTxtStr)
|
|
438
425
|
);
|
|
439
426
|
}
|
|
440
427
|
);
|
|
441
|
-
}
|
|
428
|
+
}
|
|
442
429
|
|
|
443
430
|
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;
|