-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathloadpalettes.js
More file actions
24 lines (23 loc) · 817 Bytes
/
Copy pathloadpalettes.js
File metadata and controls
24 lines (23 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//include fs
const fs = require('fs');
var palettes = {};
//go through all txt files in the palettes folder
fs.readdirSync('./palettes').forEach(file => {
//read the file
var data = fs.readFileSync(`./palettes/${file}`, 'utf8');
//strip all \r characters
data = data.replace(/\r/g, '');
//split newlines into an array
data = data.split('\n');
//remove empty lines
data = data.filter(line => line.trim() !== '');
//strip all lines starting with ;
data = data.filter(line => !line.startsWith(';'));
//replace first two characters of each element with #
data = data.map(line => '#' + line.substring(2));
//strip extension from file
file = file.replace('.txt', '');
//add the palette to the palettes object
palettes[file] = data;
});
console.log(palettes);