Skip to content

Commit

Permalink
fix(utils): stop depending on moment
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhaenisch committed Jun 1, 2020
1 parent 84874b1 commit 8066265
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Moment } from 'moment-timezone';
import { removeDataUrlPrefix } from '../strings';

declare const moment: typeof import('moment-timezone');

/**
* Wait for a given amount of time.
*
Expand Down Expand Up @@ -91,10 +88,9 @@ export const downloadFile = (data: string, mimeType: 'text/csv', fileName: strin
'text/csv': '.csv',
};

const fullName = [
addTimestamp ? [fileName, moment().format('YYYY-MM-DD-HHmmss')].join('_') : fileName,
fileExtensions[mimeType],
].join('.');
const timestamp = new Date().toISOString().slice(0, 19).replace('T', '-').replace(/:/g, '');

const fullName = [addTimestamp ? [fileName, timestamp].join('_') : fileName, fileExtensions[mimeType]].join('.');

const link = document.createElement('a');

Expand All @@ -112,11 +108,17 @@ export const downloadFile = (data: string, mimeType: 'text/csv', fileName: strin
export const parseJsonWebToken = (jwt: string): TokenPayload => {
const payload = JSON.parse(window.atob(jwt.split('.')[1].replace(/-/g, '+').replace(/_/g, '/')));

return { expires: moment(payload.exp * 1000), uid: JSON.parse(payload.uid) };
return { expires: payload.exp * 1000, uid: JSON.parse(payload.uid) };
};

export interface TokenPayload {
expires: Moment;
/**
* Expiry date in ms since Unix Epoch.
*/
expires: number;
/**
* User id that the token belongs to.
*/
uid: string;
}

Expand Down

0 comments on commit 8066265

Please sign in to comment.