Line data Source code
1 : import { StringDistribution } from "../types.ts"; 2 1 : import { string } from "./string.ts"; 3 : 4 1 : const LOWER_HEX_POOL = "0123456789abcdef"; 5 1 : const lowerHex = string(LOWER_HEX_POOL); 6 1 : const upperHex = string(LOWER_HEX_POOL.toUpperCase()); 7 : 8 : /** 9 : * Returns a Distribution that returns a random string comprised of numbers 10 : * or the characters `abcdef` (or `ABCDEF`) of length `length`. 11 : * @param length Length of the result string 12 : * @param uppercase Whether the string should use `ABCDEF` instead of `abcdef` 13 : */ 14 0 : export function hex(uppercase?: boolean): StringDistribution { 15 0 : if (uppercase) { 16 0 : return upperHex; 17 0 : } else { 18 0 : return lowerHex; 19 0 : } 20 0 : }