First Committ
This commit is contained in:
15
src/utils/auth.ts
Executable file
15
src/utils/auth.ts
Executable file
@@ -0,0 +1,15 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const TokenKey = 'Admin-Token'
|
||||
|
||||
export function getCookie() {
|
||||
return Cookies.get(TokenKey)
|
||||
}
|
||||
|
||||
export function setCookie(token: string) {
|
||||
return Cookies.set(TokenKey, token)
|
||||
}
|
||||
|
||||
export function removeCookie() {
|
||||
return Cookies.remove(TokenKey)
|
||||
}
|
||||
21
src/utils/config.ts
Executable file
21
src/utils/config.ts
Executable file
@@ -0,0 +1,21 @@
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
dotenv.config()
|
||||
let path
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'test':
|
||||
path = `${__dirname}/../../.env.test`
|
||||
break
|
||||
case 'development':
|
||||
path = `${__dirname}/../../.env.development`
|
||||
break
|
||||
default:
|
||||
path = `${__dirname}/../../.env.production`
|
||||
}
|
||||
dotenv.config({ path })
|
||||
|
||||
console.log('path', path)
|
||||
console.log('process.env.APP_ID', process.env.APP_ID)
|
||||
|
||||
export const { APP_ID } = process.env
|
||||
export const { LOG_LEVEL } = process.env
|
||||
11
src/utils/methods.ts
Executable file
11
src/utils/methods.ts
Executable file
@@ -0,0 +1,11 @@
|
||||
export function timeout(duration: number): Promise<{}> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => { // @ts-ignore
|
||||
resolve()
|
||||
}, duration);
|
||||
})
|
||||
}
|
||||
|
||||
export function randomNumber(min: number, max: number) : number {
|
||||
return Math.floor((Math.random() * max) + min);
|
||||
}
|
||||
8
src/utils/validators.ts
Executable file
8
src/utils/validators.ts
Executable file
@@ -0,0 +1,8 @@
|
||||
export namespace Validators {
|
||||
const Regs = {
|
||||
link: /(https?|ftp):\/\/(-\.)?([^\s/?#-]+\.?)+(\/[^\s]*)?@iS/,
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export const LinkValidator = (value, component) => Regs.link.test(value)
|
||||
}
|
||||
Reference in New Issue
Block a user