fepper-ui
Version:
The client-side package that powers the Fepper UI
37 lines (30 loc) • 941 B
JavaScript
export default class Timestamper {
// Private class fields.
constructor(fepperUi, root) {
this.
this.
}
// In case fepperUi.cookies is undefined at instantiation.
get cookies() {
return this.
}
stoke() {
const fepperTs = Number(this.cookies.get('fepper_ts') || '0');
const paramsStr = this.
let timestamp = 0;
if (paramsStr) {
const paramsObj = new URLSearchParams(paramsStr.slice(1));
timestamp = parseInt(paramsObj.get('ts'));
}
/* istanbul ignore if */
if (!timestamp || Number.isNaN(timestamp)) {
return;
}
// Only write timestamp to cookie if the cookie doesn't exist or if timestamp > cookie value.
if (timestamp > fepperTs) {
this.cookies.set('fepper_ts', timestamp.toString(), {maxAge: 31536000, path: '/', sameSite: 'strict'});
}
}
}