color-name-list 10.24.2 → 10.25.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "color-name-list",
3
- "version": "10.24.2",
3
+ "version": "10.25.0",
4
4
  "description": "long list of color names",
5
5
  "main": "dist/colornames.json",
6
6
  "browser": "dist/colornames.umd.js",
package/scripts/build.js CHANGED
@@ -26,6 +26,9 @@ const fileNameSrc = 'colornames';
26
26
  const fileNameBestOfPostfix = '.bestof';
27
27
  const readmeFileName = 'README.md';
28
28
 
29
+ const fileNameShortPostfix = '.short';
30
+ const maxShortNameLength = 12;
31
+
29
32
  const sortBy = 'name';
30
33
  const csvKeys = ['name', 'hex'];
31
34
  const bestOfKey = 'good name';
@@ -118,6 +121,24 @@ const JSONExportStringBestOf = JSON.stringify(
118
121
  )
119
122
  );
120
123
 
124
+ const JSONExportStringShort = JSON.stringify(
125
+ [...colorsSrc.entires]
126
+ .filter(
127
+ // make sure its only one word long
128
+ (val) =>
129
+ val[bestOfKey] &&
130
+ val.name.split(" ").length === 1 &&
131
+ val.name.length < maxShortNameLength
132
+ )
133
+ .map(
134
+ // removes good name attributes
135
+ (val) => ({
136
+ name: val.name,
137
+ hex: val.hex,
138
+ })
139
+ )
140
+ );
141
+
121
142
  fs.writeFileSync(
122
143
  path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`),
123
144
  JSONExportString
@@ -128,6 +149,11 @@ fs.writeFileSync(
128
149
  JSONExportStringBestOf
129
150
  );
130
151
 
152
+ fs.writeFileSync(
153
+ path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.json`),
154
+ JSONExportStringShort
155
+ );
156
+
131
157
  // creates a more compact JSON file, where the HEX color serves as an id
132
158
  const miniJSONExportObj = colorsSrc.entires.reduce((obj, entry) => {
133
159
  obj[entry.hex.replace('#', '')] = entry.name;
@@ -141,6 +167,17 @@ const miniJSONExportObjBestOf = colorsSrc.entires.reduce((obj, entry) => {
141
167
  return obj;
142
168
  }, {});
143
169
 
170
+ const miniJSONExportObjShort = colorsSrc.entires.reduce((obj, entry) => {
171
+ if (
172
+ entry[bestOfKey] &&
173
+ entry.name.split(" ").length === 1 &&
174
+ entry.name.length < maxShortNameLength
175
+ ) {
176
+ obj[entry.hex.replace("#", "")] = entry.name;
177
+ }
178
+ return obj;
179
+ }, {});
180
+
144
181
  fs.writeFileSync(
145
182
  path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.min.json`),
146
183
  JSON.stringify(miniJSONExportObj)
@@ -151,6 +188,11 @@ fs.writeFileSync(
151
188
  JSON.stringify(miniJSONExportObjBestOf)
152
189
  );
153
190
 
191
+ fs.writeFileSync(
192
+ path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.min.json`),
193
+ JSON.stringify(miniJSONExportObjShort)
194
+ );
195
+
154
196
  // gets UMD template
155
197
  const umdTpl = fs.readFileSync(
156
198
  path.normalize(__dirname + '/umd.js.tpl'),
@@ -168,6 +210,11 @@ fs.writeFileSync(
168
210
  umdTpl.replace('"{{COLORS}}"', JSONExportStringBestOf)
169
211
  );
170
212
 
213
+ fs.writeFileSync(
214
+ path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.umd.js`),
215
+ umdTpl.replace('"{{COLORS}}"', JSONExportStringShort)
216
+ );
217
+
171
218
  // gets ESM template
172
219
  const esmTpl = fs.readFileSync(
173
220
  path.normalize(__dirname + '/esm.js.tpl'),
@@ -193,6 +240,15 @@ fs.writeFileSync(
193
240
  esmTpl.replace('"{{COLORS}}"', JSONExportStringBestOf)
194
241
  );
195
242
 
243
+ fs.writeFileSync(
244
+ path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.esm.js`),
245
+ esmTpl.replace('"{{COLORS}}"', JSONExportStringShort)
246
+ );
247
+ fs.writeFileSync(
248
+ path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.esm.mjs`),
249
+ esmTpl.replace('"{{COLORS}}"', JSONExportStringShort)
250
+ );
251
+
196
252
  // create foreign formats
197
253
  // configuration for the file outputs
198
254
  const outputFormats = {
@@ -264,6 +320,29 @@ for (const outputFormat in outputFormats) {
264
320
  }
265
321
  }
266
322
 
323
+ // short files
324
+ for (const outputFormat in outputFormats) {
325
+ if (outputFormats[outputFormat]) {
326
+ let outputString = objArrToString(
327
+ colorsSrc.entires.filter(
328
+ (val) =>
329
+ val[bestOfKey] &&
330
+ val.name.split(" ").length === 1 &&
331
+ val.name.length < maxShortNameLength
332
+ ),
333
+ csvKeys,
334
+ outputFormats[outputFormat]
335
+ );
336
+ if (outputFormat === 'html' || outputFormat === 'xml') {
337
+ outputString = outputString.replace(/&/g, '&amp;');
338
+ }
339
+ fs.writeFileSync(
340
+ path.normalize(`${baseFolder}${folderDist}${fileNameSrc}${fileNameShortPostfix}.${outputFormat}`),
341
+ outputString
342
+ );
343
+ }
344
+ }
345
+
267
346
  // updates the color count in readme file
268
347
  const readme = fs.readFileSync(
269
348
  path.normalize(`${baseFolder}${readmeFileName}`),