Created
February 18, 2026 09:31
-
-
Save aulisius/72033116a84260abaaff6093fd270a76 to your computer and use it in GitHub Desktop.
Tiny useful scripts
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
| #! node | |
| let [epoch = Date.now()] = process.argv.slice(2); | |
| let date = new Date(+epoch); | |
| if (date.toString() === "Invalid Date" || date.getFullYear() === 1970) { | |
| epoch = +epoch * 1000; | |
| date = new Date(epoch); | |
| } | |
| let difference = Math.ceil((epoch - Date.now()) / (1000 * 60)); | |
| console.log( | |
| JSON.stringify( | |
| { | |
| epoch, | |
| utcTime: date.toUTCString(), | |
| localTime: date.toString(), | |
| relative: isNaN(difference) | |
| ? "-" | |
| : new Intl.RelativeTimeFormat().format(difference, "minutes"), | |
| }, | |
| null, | |
| 2 | |
| ) | |
| ); |
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
| #! node | |
| // Tested with v16.17.1 | |
| import process from "node:process"; | |
| import { text } from "node:stream/consumers"; | |
| let [flag = "--help", ...args] = process.argv.slice(2); | |
| /** | |
| * | |
| * @param token {string} | |
| * @param mode {string} | |
| */ | |
| function parse(token, mode) { | |
| const [header, payload, sign] = token.trim().replace("Bearer", "").split("."); | |
| if (mode === "--full") { | |
| console.log( | |
| JSON.stringify( | |
| { | |
| header: JSON.parse(Buffer.from(header, `base64`).toString()), | |
| payload: JSON.parse(Buffer.from(payload, `base64`).toString()), | |
| sign, | |
| }, | |
| null, | |
| 2 | |
| ) | |
| ); | |
| } else { | |
| console.log( | |
| JSON.stringify( | |
| JSON.parse(Buffer.from(payload, `base64`).toString()), | |
| null, | |
| 2 | |
| ) | |
| ); | |
| } | |
| } | |
| if (!process.stdin.isTTY) { | |
| await text(process.stdin).then((token) => parse(token, flag)); | |
| } else { | |
| if (flag === "--help") { | |
| console.log(` | |
| JWT Inspector | |
| Usage | |
| # Parse JWT | |
| ~ jwt --full <token> | |
| # View payload (default) | |
| ~ jwt <token> | |
| `); | |
| } else if (flag === "--payload" || flag === "--full") { | |
| parse(args.join(""), flag); | |
| } else { | |
| parse([flag, ...args].join(""), "--payload"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment