-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_speed.js
More file actions
82 lines (63 loc) · 3.37 KB
/
Copy pathadd_speed.js
File metadata and controls
82 lines (63 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from 'fs';
function estimateSpeed(name, description, connections) {
const text = (name + ' ' + description + ' ' + connections).toLowerCase();
// Very fast / Systems / Compiled
if (name === 'Assembly' || name === 'C' || name === 'C++' || name === 'Rust' || name === 'Zig' || name === 'Nim') return 100;
if (text.includes('systems programming') || text.includes('high performance') || text.includes('machine code') || text.includes('compiled to c') || text.includes('compiles to c')) return 90 + Math.floor(Math.random() * 10);
// Fast compiled / JIT
if (name === 'Go' || name === 'Java' || name === 'C#' || name === 'Swift' || name === 'Kotlin' || name === 'Julia' || name === 'Scala') return 85;
if (text.includes('compiled') || text.includes('jvm') || text.includes('.net') || text.includes('bytecode')) return 75 + Math.floor(Math.random() * 15);
// JIT / Fast dynamic
if (name === 'JavaScript' || name === 'TypeScript' || name === 'Dart' || name === 'Lua') return 70;
if (text.includes('javascript engine') || text.includes('jit') || text.includes('webassembly')) return 65 + Math.floor(Math.random() * 15);
// Interpreted / Scripting
if (name === 'Python' || name === 'Ruby' || name === 'PHP' || name === 'Perl' || name === 'R') return 30;
if (text.includes('scripting') || text.includes('interpreted') || text.includes('dynamic')) return 25 + Math.floor(Math.random() * 20);
// Shell / Slow
if (text.includes('shell') || text.includes('bash') || text.includes('command-line')) return 15 + Math.floor(Math.random() * 10);
// Esoteric
if (text.includes('esoteric')) return 5 + Math.floor(Math.random() * 5);
// Default fallback (average)
return 50 + Math.floor(Math.random() * 20);
}
function processFile(filePath) {
console.log(`Processing ${filePath}...`);
let content = fs.readFileSync(filePath, 'utf-8');
// Add speed to Language interface if it's the main file
if (content.includes('export interface Language {') && !content.includes('speed: number;')) {
content = content.replace(
/category\?: Category;\n\}/,
`category?: Category;\n speed: number; // 1 to 100\n}`
);
}
// Split content by "id: '" to process each language block
const parts = content.split(/id:\s*'/);
let newContent = parts[0];
for (let i = 1; i < parts.length; i++) {
let part = parts[i];
// Check if speed is already there
if (!part.includes('speed:')) {
// Extract name, description, connections
let nameMatch = part.match(/name:\s*'((?:[^'\\]|\\.)*)'/);
let descMatch = part.match(/description:\s*'((?:[^'\\]|\\.)*)'/);
let connMatch = part.match(/connectionsExplanation:\s*'((?:[^'\\]|\\.)*)'/);
if (nameMatch && descMatch && connMatch) {
const name = nameMatch[1];
const desc = descMatch[1];
const conn = connMatch[1];
const speed = estimateSpeed(name, desc, conn);
// Insert speed before category or angle
part = part.replace(/(angle:\s*\d+,)/, `$1 speed: ${speed},`);
}
}
newContent += `id: '${part}`;
}
fs.writeFileSync(filePath, newContent, 'utf-8');
console.log(`Updated ${filePath}`);
}
const files = ['src/data/languages.ts', 'src/data/languages2.ts', 'src/data/languages3.ts', 'src/data/languages4.ts'];
for (const file of files) {
if (fs.existsSync(file)) {
processFile(file);
}
}