mirror of
https://github.com/cupcakearmy/canihazusername.git
synced 2024-11-16 18:11:39 +01:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import { readFileSync, readdirSync, statSync, writeFileSync } from 'fs'
|
|
import { basename, join } from 'path'
|
|
|
|
const endsWithTxt = /^.*\.txt$/
|
|
|
|
function walkDir(dir, callback) {
|
|
readdirSync(dir).forEach((f) => {
|
|
const dirPath = join(dir, f)
|
|
const isDirectory = statSync(dirPath).isDirectory()
|
|
isDirectory ? walkDir(dirPath, callback) : callback(join(dir, f))
|
|
})
|
|
}
|
|
|
|
function convertAndSaveWordlistAsJSON() {
|
|
const wordlist = {}
|
|
|
|
walkDir('./generate/wordlist', (filename) => {
|
|
// Not a txt file
|
|
if (!endsWithTxt.test(filename)) return
|
|
|
|
// Read the file
|
|
const file = readFileSync(filename, 'utf-8')
|
|
|
|
// Each line of the file to an array removing the empty lines
|
|
const lines = file
|
|
.split('\n')
|
|
.filter((entry) => entry !== '')
|
|
.map((entry) => entry.trim())
|
|
|
|
const set = new Set(lines) // remove duplicates
|
|
const name = basename(filename, 'utf-8').slice(0, -4) // trim .txt
|
|
wordlist[name] = [...set]
|
|
})
|
|
|
|
writeFileSync('./src/wordlist.json', JSON.stringify(wordlist), 'utf-8')
|
|
}
|
|
|
|
convertAndSaveWordlistAsJSON()
|