1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-18 00:56:00 +07:00

fix: added packageMeta type

This commit is contained in:
Griffith Tchen Pan
2019-06-22 10:43:59 +01:00
committed by Griffithtp
parent c0b0189cc6
commit 3c54b116c9
16 changed files with 83 additions and 65 deletions

View File

@@ -6,9 +6,9 @@ import '../../types';
* @param {object} response
* @returns {promise}
*/
function handleResponseType(response): Promise<any> {
function handleResponseType(response: Response): Promise<[boolean, Blob | string]> | Promise<void> {
if (response.headers) {
const contentType = response.headers.get('Content-Type');
const contentType = response.headers.get('Content-Type') as string;
if (contentType.includes('application/pdf')) {
return Promise.all([response.ok, response.blob()]);
}

View File

@@ -1,8 +1,9 @@
import API from './api';
import { PackageMetaInterface } from 'types/packageMeta';
export interface DetailPage {
readMe: any;
packageMeta: any;
readMe: string;
packageMeta: PackageMetaInterface;
}
export async function callDetailPage(packageName): Promise<DetailPage> {

View File

@@ -1,3 +1,4 @@
/* tslint:disable */
export default function fileSizeSI(a?: any, b?: any, c?: any, d?: any, e?: any) {
return ((b = Math), (c = b.log), (d = 1e3), (e = (c(a) / c(d)) | 0), a / b.pow(d, e)).toFixed(2) + ' ' + (e ? 'kMGTPEZY'[--e] + 'B' : 'Bytes');
}

View File

@@ -5,30 +5,34 @@ import { Base64 } from 'js-base64';
import API from './api';
import { HEADERS } from '../../lib/constants';
export function isTokenExpire(token?: any) {
interface PayloadInterface {
exp: number;
}
export function isTokenExpire(token?: string): boolean {
if (!isString(token)) {
return true;
}
let [, payload]: any = token.split('.');
const [, payload] = token.split('.');
if (!payload) {
return true;
}
let exp: number;
try {
payload = JSON.parse(Base64.decode(payload));
exp = JSON.parse(Base64.decode(payload)).exp;
} catch (error) {
// eslint-disable-next-line
console.error('Invalid token:', error, token);
console.error('Invalid token:', error, token);
return true;
}
if (!payload.exp || !isNumber(payload.exp)) {
if (!exp || !isNumber(exp)) {
return true;
}
// Report as expire before (real expire time - 30s)
const jsTimestamp = payload.exp * 1000 - 30000;
const jsTimestamp = exp * 1000 - 30000;
const expired = Date.now() >= jsTimestamp;
return expired;

View File

@@ -1,6 +1,6 @@
import parseXSS from 'xss';
export function preventXSS(text: string) {
export function preventXSS(text: string): string {
const encodedText = parseXSS.filterXSS(text);
return encodedText;

View File

@@ -1,7 +1,7 @@
/**
* CSS to represent truncated text with an ellipsis.
*/
export function ellipsis(width: string | number) {
export function ellipsis(width: string | number): {} {
return {
display: 'inline-block',
maxWidth: width,
@@ -24,7 +24,7 @@ interface SpacingShortHand<type> {
const positionMap = ['Top', 'Right', 'Bottom', 'Left'];
export function spacing(property: 'padding' | 'margin', ...values: SpacingShortHand<number | string>[]) {
export function spacing(property: 'padding' | 'margin', ...values: SpacingShortHand<number | string>[]): {} {
const [firstValue = 0, secondValue = 0, thirdValue = 0, fourthValue = 0] = values;
const valuesWithDefaults = [firstValue, secondValue, thirdValue, fourthValue];
let styles = {};