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

@destiny_zxj/devtools

v1.0.13

Published

前端开发工具箱

Downloads

18

Readme

前端开发工具箱

说明

  1. sessionStorage、localStorage 支持
  2. axios 支持

打包发布

yarn build
npm publish

0. Usage

import { Http, Util, Request, Response, Method, ResponseType } from '@destiny_zxj/devtools'

Http

基于 axios 实现网络请求

# Http{
##  baseUrl: axios baseUrl,用于设置服务器 api 地址

##  tokenFieldName = 'token'
#### token 字段名

##  request(request: Request, baseUrl=''): Promise<Response>
#### 发起 Http 请求
#### request: 请求,下见 [Request]
#### baseUrl: axios baseUrl
  • Example
import { Http, Response, Request, Method } from '@destiny_zxj/devtools'
Http.baseUrl = 'http://127.0.0.1:8888'

class Api{
  /**
   * 用户登录
   * @param phone 手机号
   * @param username 用户名
   * @param password 密码
   * @param code 验证码
   * @returns 
   */
  public static login(phone: string, username: string, password: string, code: string): Promise<Response> {
    const request = new Request('/user/login')
    request.method = Method.POST
    request.data = {
      phone, username, password, code
    }
    return Http.request(request)
  }
  /**
   * 请求失败
   * @param msg 失败消息
   * @returns 
   */
  public static requestFailed(msg: string): Promise<Response> {
    return new Promise((resolve, reject) => {
      reject(new Response(-1, null, msg))
    })
  }
}

export {
  Api
}

Request

# Request
##  url: 请求 url
##  method: 请求方法,下见 [Method]
##  params: 请求参数
##  data: 请求数据 (payload)
##  headers: 请求头
##  token: token 令牌
##  baseUrl: axios baseUrl
##  responseType: 响应类型,下见 [ResponseType]
##  cache: 缓存

Response

# Response
##  code: 响应码,后端自定义
##  data: 响应数据
##  msg: 响应消息

Method

# Method
##  GET: 普通 GET 请求
##  POST: 普通 POST 请求,Content-Type=application/x-www-form-urlencoded
##  FORMDATA: 自定义 POST 请求,Content-Type=multipart/form-data; boundary=-----ycst.destiny_zxj-----
##  POST_JSON: 自定义 POST 请求,Content-Type=application/json

ResponseType

# ResponseType
##  BOLB: 响应二进制

Util

工具类

  • saveLoginedData: (user_data: any) => boolean;

保存登录数据

user_data 服务端获取到的用户数据

  • getUserData: () => any;

获取本地保存的用户数据

  • logout: () => void;

注销登录,含服务器注销

  • clearData: (all?: boolean) => void;

清除存储的数据

all 全部清除

  • VerifyPhone(phone: string): boolean;

手机号校验

phone 手机号

  • VerifyUsername(username: string): boolean;

校验给定字符串长度是否为 6~11

username 用户名

  • verifyIdCard(idCard: string): boolean;

校验身份证号

idCard 身份证号

  • verifyEmail(email: string): boolean;

校验邮箱

email 邮箱

  • verifyPassword(password: string): boolean;

校验密码长度是否为 6~16

password 密码

  • verifyCode(code: string): boolean;

校验验证码长度是否为 6 位

code 验证码

  • verifyURI(uri: string): boolean;

校验 uri

uri

  • hasSpace(val: string): boolean;

校验给定字符串中是否含有空格

val 给定字符串

  • Verify(val: string, pattern: RegExp, testSpace?: boolean): boolean;

普通模式校验

val 给定字符串

pattern 匹配正则表达式

testSpace 是否检测空格(false)