front end developer toolkit
browser
npm install @fdutil/core
yarn add @fdutil/core
pnpm install @fdutil/core
import { baseStorage, getStorageData, initLFInstance } from '@fdutil/core'
interface UserInfoInterface {
name: string
age: number
// ...
}
enum StorageKeys {
USER = 'user'
// ...
}
const AppKey = 'your app key'
initLFInstance(AppKey)
baseStorage<StorageKeys, UserInfoInterface>(storageKey, { name: 'Jeff', age: 18 })
getStorageData('item', { default: true })
import { getImgOpaqueOffsets, getImgOriginUrls } from '@fdutil/core'
getImgOpaqueOffsets(imgUrl).then(({ x, y, w, h }) => {
console.log('your img\'s opaque part offsets: ', x, y, w, h)
})
const urls = getImgOriginUrls('sadhihttp://a.g*o 32 \^!.webp*.jpg)w \\nebpd https:// sahttps://% ^& *.png(*&^')
console.log(urls) // ['http://a.g*o32^!.webp', 'https://%^&*.png']
import { paramsToQuery, paramsToFormData } from '@fdutil/core'
const params = {
a: 1,
b: 2,
c: 3,
}
const url = '/example.com'
paramsToQuery(url, params) // '/example.com?a=1&b=2&c=3'
paramsToFormData(params) // to be FormData
import { PlaceholderImg } from '@fdutil/components'
<PlaceholderImg :wh="300" bghex="0000FF" texthex="FFFFFF" text="Hello, I'm PlaceholderImg text." />
web request with abort
import { getJSONReq, postJSONReq, uniRequest } from '@fdutil/request'
const url = 'https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=7'
let ac = null, pac = null
getJSONReq(url, { ac })
postJSONReq(url, body, { pac })
// abort request
ac.abort()
pac.abort()
uni-app request
uniRequest(url, {
method: 'GET' // 'GET' | 'POST',
body, // post body,
headers // request headers
})
MIT License © 2022 Senar