Download wp-calypso/client/signup/storageUtils.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 5.1 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/signup/storageUtils.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/signup/storageUtils.js
-
curl -L -o storageUtils.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/signup/storageUtils.js
5.1 kB
| import cookie from 'cookie'; | |
| export const persistSignupDestination = ( url ) => { | |
| const DAY_IN_SECONDS = 3600 * 24; | |
| const expirationDate = new Date( new Date().getTime() + DAY_IN_SECONDS * 1000 ); | |
| const options = { path: '/', expires: expirationDate, sameSite: 'strict' }; | |
| document.cookie = cookie.serialize( 'wpcom_signup_complete_destination', url, options ); | |
| }; | |
| export const retrieveSignupDestination = () => { | |
| const cookies = cookie.parse( document.cookie ); | |
| return cookies.wpcom_signup_complete_destination; | |
| }; | |
| export const clearSignupDestinationCookie = () => { | |
| // Set expiration to a random time in the past so that the cookie gets removed. | |
| const expirationDate = new Date( new Date().getTime() - 1000 ); | |
| const options = { path: '/', expires: expirationDate }; | |
| document.cookie = cookie.serialize( 'wpcom_signup_complete_destination', '', options ); | |
| }; | |
| /** | |
| * Ignore fatals when trying to access window.sessionStorage so that we do not | |
| * see them logged in Sentry. Please don't use this for anything else. | |
| */ | |
| function ignoreFatalsForStorage( callback ) { | |
| try { | |
| return callback(); | |
| } catch { | |
| // Do nothing. | |
| return undefined; | |
| } | |
| } | |
| export const getSignupCompleteSlug = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'wpcom_signup_complete_site_slug' ) ); | |
| export const setSignupCompleteSlug = ( value ) => | |
| ignoreFatalsForStorage( () => | |
| sessionStorage?.setItem( 'wpcom_signup_complete_site_slug', value ) | |
| ); | |
| export const clearSignupCompleteSlug = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.removeItem( 'wpcom_signup_complete_site_slug' ) ); | |
| export const getSignupCompleteSiteID = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'wpcom_signup_complete_site_id' ) ); | |
| export const setSignupCompleteSiteID = ( value ) => | |
| ignoreFatalsForStorage( () => sessionStorage?.setItem( 'wpcom_signup_complete_site_id', value ) ); | |
| export const setDomainsDependencies = ( dependencies ) => { | |
| ignoreFatalsForStorage( () => | |
| sessionStorage.setItem( 'wpcom_domains_dependencies', JSON.stringify( dependencies ) ) | |
| ); | |
| }; | |
| export const getDomainsDependencies = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'wpcom_domains_dependencies' ) ); | |
| export const clearDomainsDependencies = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.removeItem( 'wpcom_domains_dependencies' ) ); | |
| export const wasSignupCheckoutPageUnloaded = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'was_signup_checkout_page_unloaded' ) ); | |
| export const setSignupCheckoutPageUnloaded = ( value ) => | |
| ignoreFatalsForStorage( () => | |
| sessionStorage?.setItem( 'was_signup_checkout_page_unloaded', value ) | |
| ); | |
| export const getSignupCompleteFlowName = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'wpcom_signup_complete_flow_name' ) ); | |
| export const setSignupCompleteFlowName = ( value ) => | |
| ignoreFatalsForStorage( () => | |
| sessionStorage?.setItem( 'wpcom_signup_complete_flow_name', value ) | |
| ); | |
| export const clearSignupCompleteFlowName = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.removeItem( 'wpcom_signup_complete_flow_name' ) ); | |
| export const getSignupCompleteFlowNameAndClear = () => { | |
| const value = getSignupCompleteFlowName(); | |
| clearSignupCompleteFlowName(); | |
| return value; | |
| }; | |
| export const getSignupCompleteStepName = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'wpcom_signup_complete_step_name' ) ); | |
| export const setSignupCompleteStepName = ( value ) => | |
| ignoreFatalsForStorage( () => | |
| sessionStorage?.setItem( 'wpcom_signup_complete_step_name', value ) | |
| ); | |
| export const clearSignupCompleteStepName = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.removeItem( 'wpcom_signup_complete_step_name' ) ); | |
| export const getSignupCompleteStepNameAndClear = () => { | |
| const value = getSignupCompleteStepName(); | |
| clearSignupCompleteStepName(); | |
| return value; | |
| }; | |
| export const setSignupStartTime = () => | |
| ignoreFatalsForStorage( () => | |
| sessionStorage?.setItem( 'wpcom_signup_start_time', performance.now() ) | |
| ); | |
| export const getSignupStartTime = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.getItem( 'wpcom_signup_start_time' ) ); | |
| export const clearSignupStartTime = () => | |
| ignoreFatalsForStorage( () => sessionStorage?.removeItem( 'wpcom_signup_start_time' ) ); | |
| export const getSignupCompleteElapsedTime = () => { | |
| const startTime = getSignupStartTime(); | |
| if ( startTime == null ) { | |
| return null; | |
| } | |
| clearSignupStartTime(); | |
| return Math.floor( performance.now() - startTime ); | |
| }; | |
| export const setSignupIsNewUser = ( userId ) => | |
| ignoreFatalsForStorage( () => | |
| localStorage?.setItem( `wpcom_signup_is_new_user_${ userId }`, true ) | |
| ); | |
| export const getSignupIsNewUser = ( userId ) => | |
| ignoreFatalsForStorage( () => localStorage?.getItem( `wpcom_signup_is_new_user_${ userId }` ) ); | |
| export const clearSignupIsNewUser = ( userId ) => | |
| ignoreFatalsForStorage( () => | |
| localStorage?.removeItem( `wpcom_signup_is_new_user_${ userId }` ) | |
| ); | |
| export const getSignupIsNewUserAndClear = ( userId ) => { | |
| const value = getSignupIsNewUser( userId ); | |
| clearSignupIsNewUser( userId ); | |
| return value; | |
| }; | |