Created
February 21, 2024 20:32
-
-
Save colelawrence/ddb059307b8c256973f22cc4456dc72e to your computer and use it in GitHub Desktop.
Obfuscate secure tokens retaining the shape and scale (Raycast)
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
#!/usr/bin/env node | |
// Required parameters: | |
// @raycast.schemaVersion 1 | |
// @raycast.title Obfuscate | |
// @raycast.mode compact | |
// Optional parameters: | |
// @raycast.icon 🤖 | |
// @raycast.argument1 { "type": "text", "placeholder": "Original" } | |
// @raycast.packageName Developer Utils | |
// Documentation: | |
// @raycast.description Create a real-ish looking version of the string provided | |
// @raycast.author Cole Lawrence | |
// @raycast.authorURL https://github.com/colelawrence | |
/** @type {string} */ | |
const arg = process.argv.slice(2)[0]; | |
const hex = "abcdef"; | |
const alpha = "abcdefghijklmnopqrstuvwxyz"; | |
const nums = "0123456789"; | |
const pickFrom = [ | |
/A-F/.test(arg) ? hex.toUpperCase() : "", | |
/a-f/.test(arg) ? hex.toLowerCase() : "", | |
/G-Z/.test(arg) ? alpha.toUpperCase() : "", | |
/g-z/.test(arg) ? alpha.toLowerCase() : "", | |
// other symbols | |
arg.replace(/[^0-9a-zA-Z]+/g, ""), | |
]; | |
const choices = [...new Set(pickFrom.join("").split(""))]; | |
const randomChoice = () => choices[Math.floor(Math.random() * choices.length)]; | |
const obfuscate = (str) => | |
new Array(str.length).fill(0).map(randomChoice).join(""); | |
console.log(obfuscate(arg)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment