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

lkm-tool

v1.0.54

Published

liukiaming common tool

Downloads

173

Readme

如何使用 MD5 ?

//引入
import {md5} from "lkm-tool";
//使用(注意这里的值必须是字符串)
md5("nbxng123456");

如何使用Mock ?

//引入自动生成模拟接口的Mock服务器
import {config,mockServerMsg,postAction} from "lkm-tool";
//导入配置文件
//config("Debug是否开启","开发环境接口前缀","调试环境接口前缀","正式环境接口前缀","自动生成接口分页列表数组集","自动生成接口增删改查数组集")
config(true,"/api","","",["lkm"],["lkm"]);
//启动服务器
mockServerMsg();
//看到控制台输出
// Api列表/api/lkm/query
// Api列表/api/lkm/save
// Api列表/api/lkm/remove
// Api列表/api/lkm/save
// mock服务器启动成功
//访问接口
postAction("/lkm/query",{page:1,pageSize:10}).then(res=>{
	console.log(res)
})
//也可以直接使用Mockjs原生,直接导入即可使用
import {Mock} from "lkm-tool";
Mock.mock("/api/lkm/login","post",{code:200,message:"successs"})

如何使用axios发起http请求 ?

import {getAction,postAction,requestInterceptors,editRequestHeaders,editStatusList} from "lkm-tool";

//请求头部加入参数(例如加入token和作者)
editRequestHeaders({accessToken:"******************",author:"lkm"})
//请求头拦截(如加入加载动画)
requestInterceptors(()=>{console.log("我在头部加了个加载动画")})
//响应状态拦截
editStatusList({
	200:()=>{console.log("响应回调,状态码为200")}
	401:()=>{console.log("响应回调,状态码为401,可以做退出登录或者其他处理")}
	6666:()=>{console.log("统一处理,不管回调啥都会执行,这里可以隐藏加载动画")}
});
postAction("/lkm/query",{page:1,pageSize:10}).then(res=>{
	console.log(res)
})
getAction("/lkm/query",{page:1,pageSize:10}).then(res=>{
	console.log(res)
})

如何在uni-app框架发起http请求 ?

import {uniAppHttp as http} from "lkm-tool";
http.request("/user/query",{page:1,pageSize:10},"post").then(res=>{
	console.log(res)
})
//或者同时发起多个请求
http.all(uniAppHttp.request('/user/query', {page: 1, pageSize: 10}),uniAppHttp.request('/user/save', {page: 1, pageSize: 10},"post")).then(res => {
console.log(res);
});

如何在使用字符串处理方法 ?

import {
	validatorIdCard,
	social_uni_code,
	validatorPhone,
	validatorBirth,
	validatorEmail,
	validatePassword,
	isRequired,
	isInteger,
	isIp,
	isPort,
	isInRange,
	stringHandleOne,
	stringHandleTwo
} from "lkm-tool";
//身份证校验
let id_card=validatorIdCard('111');
console.log(id_card)
//{code:false,data:false,message:"身份证长度错误"}
   
//通一社会信用代码校验
let social_uni_code=validatorSocialUniCode('111');
console.log(social_uni_code)
//{code:false,data:false,message:"统一社会信用代码为18位"}

//手机号校验
console.log(validatorPhone("18059662278"));
//true

//生日校验
console.log(validatorBirth("19900805"));
//true

//邮箱校验
console.log(validatorEmail("[email protected]"));
//true

//密码校验
console.log(validatePassword("Lkm668226214."));
//{code:true,data:false,message:"密码通过校验"}

//判断是否为空
console.log(isRequired(""));
//false

//判断是否整数
console.log(isInteger(1));
//true

//判断是否为IP
console.log(isIp(1));
//false

//判断是否是端口
console.log(isPort(1001));
//true

//判断字符串是否在整数范围内(value: number, max: number = 20, min: number = -10)
console.log(isInRange(1,20,1));
//true

//字符串超出多少位后变成...(value: string, num: number = 4, str: string = "...")
console.log(stringHandleOne("adfdfdfsdfsdfdsfsd57575665568",5,"********"));  
//adfdf********

//字符串中间变成...(value: string, start: number = 4, end: number = 4, str: string = "...")
console.log(stringHandleTwo("1805df8952333331df",4,2,"---"));
// 1805---31df

如何在使用日期处理 ?

import { getDate } from 'lkm-tool'
//转换为Date类型
console.log(getDate('2021-8-5'))
//Thu Aug 05 2021 00:00:00 GMT+0800 (中国标准时间)

//获得两个日期区间所有的日期(start: 开始时间, end: 结束时间, Spacer = '/')
console.log(getDiffDate("2023/2/21","2023/2/23","-"))