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 🙏

© 2026 – Pkg Stats / Ryan Hefner

h5-api

v1.2.0

Published

h5工具类集合

Downloads

57

Readme

h5通用api

使用方法

npm i h5-api --save

引入

import { h5Api } from "h5-api";
  • ts项目需要声明类型

方法

1. isFirstEntryEdge()

介绍: 判断是否首次进入页面

参数:

返回值: 首次进入返回true,否则返回false

例子:

    if ( isFirstEntryEdge() ) {
        do something...
    }

2. isPc()

介绍: 判断设备是否为电脑

参数:

返回值: 如果是pc端返回true,否则返回false

例子:

    if ( isPc() ) {
        do something...
    }

3. pageJump( url, blank )

介绍: 跳转页面

参数:

  • url 跳转的地址 string类型(开头必须包含http或者https)
  • blank 是否在新页面打开 boolean类型 默认值: true

返回值:

例子:

    pageJump("https://www.liuguisheng.vip", true);

4. prodeceRandomString( length, isDate )

介绍: 生成一个随机字符串

参数:

  • length 随机数长度 number类型
  • isDate 是否添加时间戳 boolean类型 默认值: false

返回值: 生成的字符串

例子:

    let str =  prodeceRandomString( 10, true );
    
    console.log(str);

5. moneyToCapitals( n )

介绍: 金额小写转大写

参数:

  • n 小写金额 number类型

返回值: 返回生成的大写金额

例子:

    let capitalizeMoney =  prodeceRandomString( 10, true );
    
    console.log(capitalizeMoney);

6. getCurrentUrl ()

介绍: 获取地址栏url

参数:

返回值: 地址栏的url

例子:

    let url = getCurrentUrl();
    
    console.log(url);

7. deepCopy ( value )

介绍: 深拷贝方法

参数:

  • value 需要拷贝的值 任意类型

返回值: 深拷贝后的值

例子:

    let obj = {
        name: "liu",
        home: "https://www.liuguisheng.vip"
    }
    let result = deepCopy(obj);
    
    console.log(obj === result);

8. emptyCheck

介绍: 校验一个对象是否有空值

参数: 每个方法的传参有所区别

内置方法:

  • emptyCheck.checkObject( obj, unInclude ) 校验对象, obj为需要校验的对象,unInclude为不需要校验的key
  • emptyCheck.checkNumber ( num ) 校验数字
  • emptyCheck.checkString ( str ) 校验字符串
  • emptyCheck.checkArray ( arr ) 校验数组

返回值: 如果有空值返回true, 否则返回false

例子:

    let obj = {
        name: "liu",
        home: "https://www.liuguisheng.vip",
        info: {
            age: 27,
            idCard: '',
            girlFriend: ''
        }
    }

    let unInclude = ['girlFriend'];

    let check = new emptyCheck();

    let result = check.checkObject(obj, unInclude);
    
    console.log(result);

9. charToPx ( length, fontSize )

介绍: 字符转像素

参数:

  • length 字符长度 number类型
  • fontSize 字体大小 number类型

返回值: 生成的像素值

例子:

    let result = charToPx ( 30, 14 );
    console.log( result );

10. cmToPx ( cm )

介绍: 厘米转像素

参数:

  • cm 厘米 number类型

返回值: 生成的像素值

例子:

    let result = cmToPx ( 30 );
    console.log( result );

11. arrayIntersection ( arr1, arr2 )

介绍: 两个数组取交集

参数:

  • arr1 数组1 any[] 类型
  • arr2 数组1 any[] 类型

返回值: 生成的新数组

例子:

    let arr1 = [1,2,3,4];
    let arr2 = [3,4,5,6];
    let result = arrayIntersectionFun ( arr1, arr2 );
    console.log( result );

12. arraySubtraction ( arr1, arr2 )

介绍: 两个数组取交集

参数:

  • arr1 数组1 any[] 类型
  • arr2 数组1 any[] 类型

返回值: 生成的新数组

例子:

    let arr1 = [1,2,3,4];
    let arr2 = [3,4,5,6];
    let result = arraySubtractionFun ( arr1, arr2 );
    console.log( result );

13. keyNameMapping ( obj, config )

介绍: 对象键名映射(只支持简单对象)

参数:

  • obj 原对象 object类型
  • config 映射配置 object类型

返回值: 生成的新对象

例子:

    let obj = {
        name: "liu",
        home: "https://www.liuguisheng.vip",
        age: 27
    };
    let config = {
        name: "id",
        home: "index",
        info: "message"
    }

    let result = keyNameMapping ( obj, config );
    console.log( result );

14. telMosaic ( tel )

介绍: 手机号打码

参数:

  • tel 手机号码 number|字符串类型

返回值: 生成的新手机号

例子:

    let result = telMosaic ( 17600000000 );
    console.log( result );

15. idCardMosaic ( idCard )

介绍: 身份证号打码

参数:

  • idCard 身份证号码 number|字符串类型

返回值: 生成的身份证

例子:

    let result = idCardMosaic ( 130282199508145154 );
    console.log( result );

16. judgeValueType ( value )

介绍: 判断某个值的类型

参数:

  • value 值 任意类型

返回值: 类型

例子:

    let result = judgeValueType ( [1,2,3,4] );
    console.log( result );

开源协议

MIT License

开个不易,给个star吧

源码地址

地址

个人博客地址

传送