source: trip-planner-front/node_modules/mime/src/build.js@ 1ad8e64

Last change on this file since 1ad8e64 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#!/usr/bin/env node
2
3'use strict';
4
5const fs = require('fs');
6const path = require('path');
7const mimeScore = require('mime-score');
8
9let db = require('mime-db');
10let chalk = require('chalk');
11
12const STANDARD_FACET_SCORE = 900;
13
14const byExtension = {};
15
16// Clear out any conflict extensions in mime-db
17for (let type in db) {
18 let entry = db[type];
19 entry.type = type;
20
21 if (!entry.extensions) continue;
22
23 entry.extensions.forEach(ext => {
24 if (ext in byExtension) {
25 const e0 = entry;
26 const e1 = byExtension[ext];
27 e0.pri = mimeScore(e0.type, e0.source);
28 e1.pri = mimeScore(e1.type, e1.source);
29
30 let drop = e0.pri < e1.pri ? e0 : e1;
31 let keep = e0.pri >= e1.pri ? e0 : e1;
32 drop.extensions = drop.extensions.filter(e => e !== ext);
33
34 console.log(`${ext}: Keeping ${chalk.green(keep.type)} (${keep.pri}), dropping ${chalk.red(drop.type)} (${drop.pri})`);
35 }
36 byExtension[ext] = entry;
37 });
38}
39
40function writeTypesFile(types, path) {
41 fs.writeFileSync(path, JSON.stringify(types));
42}
43
44// Segregate into standard and non-standard types based on facet per
45// https://tools.ietf.org/html/rfc6838#section-3.1
46const types = {};
47
48Object.keys(db).sort().forEach(k => {
49 const entry = db[k];
50 types[entry.type] = entry.extensions;
51});
52
53writeTypesFile(types, path.join(__dirname, '..', 'types.json'));
Note: See TracBrowser for help on using the repository browser.