react-code-dataset / wp-calypso /client /landing /stepper /declarative-flow /internals /state-manager /create-session-id.ts
react-code-dataset / wp-calypso /client /landing /stepper /declarative-flow /internals /state-manager /create-session-id.ts
Download wp-calypso/client/landing/stepper/declarative-flow/internals/state-manager/create-session-id.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 921 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/declarative-flow/internals/state-manager/create-session-id.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/landing/stepper/declarative-flow/internals/state-manager/create-session-id.ts
-
curl -L -o create-session-id.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/declarative-flow/internals/state-manager/create-session-id.ts
921 Bytes
| const BASE62_ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
| /** | |
| * Convert a base 10 integer to a base 62 string. | |
| * @param num - The base 10 integer to convert. | |
| * @returns The base 62 string representation of the number. | |
| */ | |
| function base10ToBase62( num: number ) { | |
| let result = ''; | |
| while ( num > 0 ) { | |
| result = BASE62_ALPHABET[ num % 62 ] + result; | |
| num = Math.floor( num / 62 ); | |
| } | |
| return result || '0'; | |
| } | |
| /** | |
| * Create a two-character long alphanumerical unique session ID. | |
| * Two characters is short enough to not be ugly and create accidental offensive words, but long enough to contain 3782 enumerations. | |
| */ | |
| export function createSessionId() { | |
| const minNumberForTwoLettersBase62 = 62; | |
| const maxNumberForTwoLettersBase62 = 3844; | |
| const seed = | |
| minNumberForTwoLettersBase62 + Math.floor( Math.random() * maxNumberForTwoLettersBase62 ); | |
| return base10ToBase62( seed ); | |
| } | |