diff --git a/src/randomstring.ts b/src/randomstring.ts index 3362c0b02..0ed46fb38 100644 --- a/src/randomstring.ts +++ b/src/randomstring.ts @@ -15,9 +15,24 @@ See the License for the specific language governing permissions and limitations under the License. */ +const LOWERCASE = "abcdefghijklmnopqrstuvwxyz"; +const UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const DIGITS = "0123456789"; + export function randomString(len: number): string { + return randomStringFrom(len, UPPERCASE + LOWERCASE + DIGITS); +} + +export function randomLowercaseString(len: number): string { + return randomStringFrom(len, LOWERCASE); +} + +export function randomUppercaseString(len: number): string { + return randomStringFrom(len, UPPERCASE); +} + +function randomStringFrom(len: number, chars: string): string { let ret = ""; - const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (let i = 0; i < len; ++i) { ret += chars.charAt(Math.floor(Math.random() * chars.length));