mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
🔨 Refactor: refactor some util func
This commit is contained in:
parent
80057c8561
commit
12be9d5802
@ -11,14 +11,6 @@ export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const trimValues = (obj: IStringKeyMap) => {
|
||||
const newObj = {} as IStringKeyMap
|
||||
Object.keys(obj).forEach(key => {
|
||||
newObj[key] = typeof obj[key] === 'string' ? obj[key].trim() : obj[key]
|
||||
})
|
||||
return newObj
|
||||
}
|
||||
|
||||
/**
|
||||
* get raw data from reactive or ref
|
||||
*/
|
||||
|
@ -4,16 +4,9 @@ import { v4 as uuid } from 'uuid'
|
||||
import { IRPCActionType } from '~/universal/types/enum'
|
||||
import { getRawData } from './common'
|
||||
|
||||
export function saveConfig (_config: IObj | string, value?: any) {
|
||||
let config
|
||||
if (typeof _config === 'string') {
|
||||
config = {
|
||||
[_config]: value
|
||||
}
|
||||
} else {
|
||||
config = getRawData(_config)
|
||||
}
|
||||
ipcRenderer.send(PICGO_SAVE_CONFIG, config)
|
||||
export function saveConfig (config: IObj | string, value?: any) {
|
||||
const configObject = typeof config === 'string' ? { [config]: value } : getRawData(config)
|
||||
ipcRenderer.send(PICGO_SAVE_CONFIG, configObject)
|
||||
}
|
||||
|
||||
export function getConfig<T> (key?: string): Promise<T | undefined> {
|
||||
|
@ -20,12 +20,7 @@ export const isUrlEncode = (url: string): boolean => {
|
||||
}
|
||||
}
|
||||
|
||||
export const handleUrlEncode = (url: string): string => {
|
||||
if (!isUrlEncode(url)) {
|
||||
url = encodeURI(url)
|
||||
}
|
||||
return url
|
||||
}
|
||||
export const handleUrlEncode = (url: string): string => isUrlEncode(url) ? url : encodeURI(url)
|
||||
|
||||
/**
|
||||
* streamline the full plugin name to a simple one
|
||||
@ -47,17 +42,13 @@ export const simpleClone = (obj: any) => {
|
||||
}
|
||||
|
||||
export const enforceNumber = (num: number | string) => {
|
||||
return isNaN(Number(num)) ? 0 : Number(num)
|
||||
return isNaN(+num) ? 0 : +num
|
||||
}
|
||||
|
||||
export const isDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
export const trimValues = (obj: IStringKeyMap) => {
|
||||
const newObj = {} as IStringKeyMap
|
||||
Object.keys(obj).forEach(key => {
|
||||
newObj[key] = typeof obj[key] === 'string' ? obj[key].trim() : obj[key]
|
||||
})
|
||||
return newObj
|
||||
export const trimValues = <T extends IStringKeyMap>(obj: T): {[K in keyof T]: T[K] extends string ? string : T[K]} => {
|
||||
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])) as {[K in keyof T]: T[K] extends string ? string : T[K]}
|
||||
}
|
||||
|
||||
const c1nApi = 'https://c1n.cn/link/short'
|
||||
|
Loading…
Reference in New Issue
Block a user