Skip to content

Commit a8b9d8e

Browse files
authored
Merge pull request #1612 from matrix-org/dbkr/jitsi_conference_captialised
Add functions for upper & lowercase random strings
2 parents f547fa7 + 83d1e61 commit a8b9d8e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/randomstring.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18+
const LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
19+
const UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
20+
const DIGITS = "0123456789";
21+
1822
export function randomString(len: number): string {
23+
return randomStringFrom(len, UPPERCASE + LOWERCASE + DIGITS);
24+
}
25+
26+
export function randomLowercaseString(len: number): string {
27+
return randomStringFrom(len, LOWERCASE);
28+
}
29+
30+
export function randomUppercaseString(len: number): string {
31+
return randomStringFrom(len, UPPERCASE);
32+
}
33+
34+
function randomStringFrom(len: number, chars: string): string {
1935
let ret = "";
20-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
2136

2237
for (let i = 0; i < len; ++i) {
2338
ret += chars.charAt(Math.floor(Math.random() * chars.length));

0 commit comments

Comments
 (0)