Skip to content

Commit

Permalink
chore: 移除无用文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanzhaoyu committed Apr 26, 2023
1 parent 838679f commit dd20e9a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 150 deletions.
1 change: 0 additions & 1 deletion config/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions config/proxy.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/utils/crypto/index.ts

This file was deleted.

44 changes: 0 additions & 44 deletions src/utils/format/index.ts

This file was deleted.

58 changes: 57 additions & 1 deletion src/utils/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
export * from './local'
interface StorageData<T = any> {
data: T
expire: number | null
}

export function createLocalStorage(options?: { expire?: number | null }) {
const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7

const { expire } = Object.assign({ expire: DEFAULT_CACHE_TIME }, options)

function set<T = any>(key: string, data: T) {
const storageData: StorageData<T> = {
data,
expire: expire !== null ? new Date().getTime() + expire * 1000 : null,
}

const json = JSON.stringify(storageData)
window.localStorage.setItem(key, json)
}

function get(key: string) {
const json = window.localStorage.getItem(key)
if (json) {
let storageData: StorageData | null = null

try {
storageData = JSON.parse(json)
}
catch {
// Prevent failure
}

if (storageData) {
const { data, expire } = storageData
if (expire === null || expire >= Date.now())
return data
}

remove(key)
return null
}
}

function remove(key: string) {
window.localStorage.removeItem(key)
}

function clear() {
window.localStorage.clear()
}

return { set, get, remove, clear }
}

export const ls = createLocalStorage()

export const ss = createLocalStorage({ expire: null })
70 changes: 0 additions & 70 deletions src/utils/storage/local.ts

This file was deleted.

0 comments on commit dd20e9a

Please sign in to comment.