Created
September 17, 2023 14:47
-
-
Save abernier/e1cf65595f69eb8a0e59eeecd78f070c to your computer and use it in GitHub Desktop.
This file contains 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
// Name: Lorem ipsum | |
import "@johnlindquist/kit"; | |
import { loremIpsum, ILoremIpsumParams } from "lorem-ipsum"; | |
let ret: ReturnType<typeof loremIpsum>; | |
const DEFAULTS = { | |
count: 1, | |
}; | |
let count: ILoremIpsumParams["count"]; | |
let units: ILoremIpsumParams["units"]; | |
const flags = { | |
html: { | |
name: "html", | |
shortcut: "cmd+h", | |
}, | |
copy: { | |
name: "copy", | |
shortcut: "cmd+c", | |
}, | |
}; | |
function myLoremIpsum({ ...args }: Parameters<typeof loremIpsum>[0] = {}) { | |
const format = flag?.html ? "html" : "plain"; | |
// say(`generating ${count} ${units} of ${format} text`); | |
return loremIpsum({ count, units, format, ...args }); | |
} | |
await arg( | |
{ | |
placeholder: String(DEFAULTS.count), | |
description: `Generate lorem ipsum text...`, | |
flags, | |
}, | |
(input) => { | |
count = (input && Number(input)) || undefined; | |
return ["paragraphs", "sentences", "words"].map((el) => ({ | |
name: el, | |
preview: () => { | |
units = el as ILoremIpsumParams["units"]; | |
return myLoremIpsum(); | |
}, | |
})); | |
} | |
); | |
const loremText = myLoremIpsum(); | |
if (flag?.copy) { | |
copy(loremText); | |
} else { | |
setSelectedText(loremText); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment