UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

39 lines 1.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.randomCharacters = randomCharacters; exports.shortHash = shortHash; const crypto_1 = __importDefault(require("crypto")); const characters = '0123456789abcdefghijklmnopqrstuvwxyz'; /** * Generates a random string of a given length * * @param length The length of the string you would like to generate * @returns */ function randomCharacters(length = 5) { let result = ''; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * characters.length); result += characters[randomIndex]; } return result; } /** * Generate a short hash of the input string using SHA-256. * The resulting hash is truncated to 8 characters. * * @param input The input string to hash. * @returns A short hash string. */ async function shortHash(input) { const encoder = new TextEncoder(); const data = encoder.encode(input); const hashBuffer = await crypto_1.default.subtle.digest('SHA-256', data); const hashArray = new Uint8Array(hashBuffer); let base64 = Buffer.from(hashArray).toString('base64'); return base64.slice(0, 8); } //# sourceMappingURL=strings.js.map