Skip to content

luvletterldl/fdutil

Repository files navigation

@fdutil

front end developer toolkit

build version issues forks stars license download

env

browser

install

npm install @fdutil/core
yarn add @fdutil/core
pnpm install @fdutil/core

usage

core

better storage

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 })

image

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']

net

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

components

import { PlaceholderImg } from '@fdutil/components'
<PlaceholderImg :wh="300" bghex="0000FF" texthex="FFFFFF" text="Hello, I'm PlaceholderImg text." />

request

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
})

Alt

License

MIT License © 2022 Senar