Antoine BERNIER

Antoine BERNIER

<img width="880" alt="image" src="https://user-images.githubusercontent.com/76580/269100710-c730f3b9-fa6d-4849-8477-a5fa0030215e.png">
length=12
numbers=true
symbols=true
// Generate password
import "@johnlindquist/kit";
import { generate, generateMultiple, GenerateOptions } from "generate-password";
import rc from "rc";
import omit from "lodash.omit";
import { passwordStrength } from "check-password-strength";
const config = rc("generatepassword", { length: 10 }); // create a ~/.generate-passwordrc file (see: https://www.npmjs.com/package/rc#standards)
const flags = {
copy: {
name: "copy",
shortcut: "cmd+c",
},
};
function formatVariant(o) {
if (Object.keys(o).length === 0) o = config;
const arr = [];
Object.keys(o).forEach((k) => {
if (o[k] === true) {
arr.push(`--${k}`);
} else if (o[k] === false) {
arr.push(`--no-${k}`);
}
});
return arr.join(" ");
}
function sortedObj(o) {
return Object.fromEntries(Object.entries(o).sort());
}
const chosenPass = await arg(
{
placeholder: (config.length && String(config.length)) || undefined,
description: `Length`,
flags,
},
(input) => {
const baseOpts = { ...config };
const length = (input && Number(input)) || undefined;
if (length) baseOpts.length = length;
const variants = [
{},
{ numbers: true, symbols: true },
{
numbers: true,
symbols: true,
excludeSimilarCharacters: true,
},
{ numbers: true, symbols: true, lowercase: false },
{ numbers: true, symbols: true, uppercase: false },
{ numbers: true },
{ symbols: true },
{ lowercase: false },
{ uppercase: false },
];
return variants.map((variant) => {
const opts = { ...baseOpts, ...variant };
const newPass = generate(opts);
const description =
Object.keys(variant).length === 0
? `from config: ${config.config}`
: formatVariant(variant);
return {
name: `${newPass}`,
description,
preview() {
return md(`${passwordStrength(newPass).value}
\`\`\`json
${JSON.stringify(omit(sortedObj(opts), "_", "configs", "config"), null, 4)}
\`\`\`
see [available options](https://www.npmjs.com/package/generate-password#available-options)
`);
},
value: newPass,
};
});
}
);
if (flag?.copy) {
copy(chosenPass);
} else {
setSelectedText(chosenPass);
}
// 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);
}