canihazusername/generate/wordlist.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-02-05 21:21:51 +01:00
const fs = require('fs')
const path = require('path')
const util = require('util')
const endsWithTxt = /^.*\.txt$/
function walkDir(dir, callback) {
2021-03-15 18:14:19 +01:00
fs.readdirSync(dir).forEach((f) => {
const dirPath = path.join(dir, f)
const isDirectory = fs.statSync(dirPath).isDirectory()
isDirectory ? walkDir(dirPath, callback) : callback(path.join(dir, f))
})
2020-02-05 21:21:51 +01:00
}
function convertAndSaveWordlistAsJSON() {
2021-03-15 18:14:19 +01:00
const wordlist = {}
2020-02-05 21:21:51 +01:00
2021-03-15 18:14:19 +01:00
walkDir('./generate/wordlist', (filename) => {
// Not a txt file
if (!endsWithTxt.test(filename)) return
2020-02-05 21:21:51 +01:00
2021-03-15 18:14:19 +01:00
// Read the file
const file = fs.readFileSync(filename, 'utf-8')
2020-02-05 21:21:51 +01:00
2021-03-15 18:14:19 +01:00
// Each line of the file to an array removing the empty lines
const lines = file
.split('\n')
.filter((entry) => entry !== '')
.map((entry) => entry.trim())
2020-02-05 21:21:51 +01:00
2021-03-15 18:14:19 +01:00
// Remove duplicates
const set = new Set(lines)
const name = path.basename(filename, 'utf-8').slice(0, -4)
wordlist[name] = [...set]
})
2020-02-05 21:21:51 +01:00
2021-03-15 18:14:19 +01:00
fs.writeFileSync('./src/wordlist.json', JSON.stringify(wordlist))
2020-02-05 21:21:51 +01:00
}
2021-03-15 18:14:19 +01:00
convertAndSaveWordlistAsJSON()