Download wp-calypso/packages/calypso-analytics/src/utils/current-user.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/calypso-analytics/src/utils/current-user.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/calypso-analytics/src/utils/current-user.ts
-
curl -L -o current-user.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/calypso-analytics/src/utils/current-user.ts
1.42 kB
| import hashPii from './hash-pii'; | |
| /** | |
| * Module variables | |
| */ | |
| let _currentUser: CurrentUser; | |
| export interface SetCurrentUserParams { | |
| ID: string; | |
| username: string; | |
| email: string; | |
| localeSlug: string; | |
| } | |
| export interface CurrentUserHashedPii { | |
| ID: string; | |
| username: string; | |
| email: string; | |
| } | |
| export interface CurrentUser { | |
| ID: number; | |
| username: string; | |
| email: string; | |
| hashedPii: CurrentUserHashedPii; | |
| localeSlug: string; | |
| } | |
| /** | |
| * Gets current user. | |
| * @returns Current user. | |
| */ | |
| export function getCurrentUser(): CurrentUser { | |
| return _currentUser; | |
| } | |
| /** | |
| * Sets current user, (stored in javascript memory). | |
| * @param currentUser the user data for the current user | |
| * @returns Current user. | |
| */ | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| export function setCurrentUser( currentUser: SetCurrentUserParams ): CurrentUser | undefined { | |
| if ( | |
| ! currentUser.ID || | |
| isNaN( parseInt( currentUser.ID, 10 ) ) || | |
| ! currentUser.username || | |
| ! currentUser.email | |
| ) { | |
| return; // Invalid user data. | |
| } | |
| _currentUser = { | |
| ID: parseInt( currentUser.ID, 10 ), | |
| username: currentUser.username, | |
| email: currentUser.email, | |
| localeSlug: currentUser.localeSlug, | |
| hashedPii: { | |
| ID: hashPii( currentUser.ID ), | |
| username: hashPii( currentUser.username.toLowerCase().replace( /\s/g, '' ) ), | |
| email: hashPii( currentUser.email.toLowerCase().replace( /\s/g, '' ) ), | |
| }, | |
| }; | |
| return _currentUser; | |
| } | |