Created
September 19, 2023 20:02
-
-
Save abernier/00cc7ca5f0a10ae2f0029e0e39ad3b62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "@johnlindquist/kit"; | |
import { generateMultiple, GenerateOptions } from "generate-password"; | |
import rc from "rc"; | |
const defaultConfig = {}; | |
const config: GenerateOptions = rc("generate-password", defaultConfig); | |
const flags = { | |
copy: { | |
name: "copy", | |
shortcut: "cmd+c", | |
}, | |
}; | |
const chosenPass = await arg( | |
{ | |
description: `Length`, | |
flags, | |
}, | |
(input) => { | |
const options = { ...config }; | |
const length = (input && Number(input)) || undefined; | |
if (length) options.length = length; | |
const newPasses = generateMultiple(10, options); | |
return newPasses.map((newPass) => ({ | |
name: newPass, | |
// preview: () => { | |
// return md(`\`${newPass}\``); | |
// }, | |
value: newPass, | |
})); | |
} | |
); | |
if (flag?.copy) { | |
copy(chosenPass); | |
} else { | |
setSelectedText(chosenPass); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment