npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cake-futil

v1.0.11

Published

简单说明:

Downloads

2

Readme

蛋糕英语 前端Util

简单说明:

  • 下面的区分是按照lib里面的源文件名进行分类
  • 导出的interface可以简单的看出具体的内容

env

import { UA } from 'cake-futil'

// UA的包含内容
export interface UAType {
  isDev: boolean     // 是否是本地开发
  isDebug: boolean   // 是否处于debug模式
  isAndroid: boolean    // 是否是安卓
  isSafari: boolean     // 是否是Safari
  isIos: boolean        // 是否是IOS
  isWeiXin: boolean     // 是否是微信
  isMobile: boolean     // 是否是手机
  isBCZ: boolean        // 是否是百词斩APP 
  isCake: boolean       // 是否是蛋糕APP
}

helper

copy.ts

import { copyClipboard } from 'cake-futil'

// 复制到剪切板
export function copyClipboard(text: string, callback?: (resulut: boolean) => void): void

func.ts

import { throttle, debounce } from 'cake-futil'

// 函数节流
export function throttle(fn: Function, interval: number = 300): Function

// 函数防抖
export function debounce(fn: Function, interval = 300): Function

is.ts

import { 
  isPlainObject,
  isQuoteType,
  isString,
  isNumber,
  isArray,
  isObject
} from 'cake-futil'

// 是否是简单对象
export function isPlainObject(obj: any): boolean

// 是否是引用类型(数组或对象)
export function isQuoteType(input: any): boolean 

export function isString(input: any): boolean // 是否是string

export function isNumber(input: any): boolean // 是否是number

export function isObject(input: any): boolean // 是否是object

export function isArray(input: any): boolean // 是否是array

hash.ts

import { hash } from 'cake-futil'

/**
 * @name hash
 * @param min 最小位数
 * @param max 最大位数
 * @description 生成一个随机字符串,传入一个参数生成固定位数的字符串
 * @description 传入两个参数,生成位于两者之间位数的字符串
 */
export function hash(min: number, max?: number): string

loading

import { Loading } from 'cake-futil'

/**
 * @description 生成loading的构造函数
 * @param { color, size, bg } size为loading大小,color为loading的颜色,bg为loading的背景色
 * @returns void
 */

// 此处展示的参数为默认值参数,请酌情修改
const config = {
  size: 1, 
  color: '#e66c5f'
  bg: 'transparent'
}

const loading = new Loading(config)

// 使用api 列表
loading.stAPILd   // 设置一个loading
loading.rmAPIld   // 去除loading

request

import { Request } from 'cake-futil'

/**
 * @name Request
 * @description request构造函数
 * @description 集成自axios,参数可参考axios的官方文档
 * @param config axios构造配置
 * @param interceptorsConfig axios的拦截器配置
 */
const apiConfig: Partial<AxiosRequestConfig> = {
  timeout: 5000,
  withCredentials: true,
  headers: {}
}

const defaultInterceptors = {
  // 请求的resolve拦截器
  reqResolver: (param: AxiosRequestConfig) => ({
    ...param
  }),

  // 请求的reject拦截器
  reqRejecter: (err: AllType) => Promise.reject(err),

  // 返回的resolve拦截器
  resReslover: (value: AxiosResponse<AllType>) => value.data,

  // 返回的reject拦截器
  resRejecter: (err: AllType) => Promise.reject(err)
}

// 构造函数的参数可以不传,默认为上述值
epxort const request = new Request()
// 也可以自己override
export const request = new Request(custom1, custom2)

toast

import { Toast } from 'cake-futil'


 /**
   * @name info
   * @description 消息提示
   * @param txt 消息提示内容
   * @param time 消息提示持续时间,默认1s
   */
Toast.info(txt: string, time = 1000)

-------------------------------------------------------

/**
  * @name loading提示
  * @description 弹出一个loading
  * @param txt loading的内容
  * @param wrapStyle loading的container样式
  * @returns void
  */
Toast.loading(txt: string = '正在加载中', wrapStyle={})

-------------------------------------------------------

/**
   * @name rmloading
   * @description 去掉弹出loading,与loading方法配套使用
   * @returns void
   */
Toast.rmloading() // 去除加载提示

url

import { 
  getQuery,
  makeSearch,
  makeObject
} from 'cake-futil'

/**
 * @name getQuery
 * @description 查询url参数
 * @param name 想要查询的参数名
 * @param url 选填,从哪个url中查询
 * @returns 返回查询到的结果,如果没查到,返回null
 * @author zaiyong
 */
export function getQuery(name: string, url: string = window.location.search.substr(1)): string | null

/**
 * @name makeSearchByObject
 * @description 根据对象生成url参数
 * @param obj 必需,简单对象
 * @param url 要拼接的url,生成search后自动拼接到url上
 * @returns 返回生成的search字符串
 * @author zaiyong
 */
export function makeSearchByObject(obj: PlainObject, url: string = ''): string 


/**
 * @name makeObjectBySearch
 * @description 根据url参数,生成对象
 * @param search 字符串,url参数
 * @returns 返回生成的对象
 * @author zaiyong
 */
export function makeObjectBySearch(search: string = window.location.search.substr(1)): PlainObject

location

/**
 * @name locationWithDelay
 * @description 延迟跳转url,多用于send log和页面跳转配合,不然log有时可能会丢失
 * @param url  跳转的路径
 * @param delay 跳转的延迟,默认250ms
 */
export const locationWithDelay = (url: string, delay: number = 250): void

/**
 * @name locationWithSearch
 * @description 跳转页面,并且携带当前页面参数
 * @param pathname 跳转的路径
 * @param extraParams 除了本身的路由,还需要额外携带的参数,为简单对象
 */
export const locationWithSearch = (pathname: string, extraParams: PlainObject = {})