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

@jdplus/tools

v2.0.7

Published

通用方法

Downloads

3

Readme

@jdplus/tools组件

通用方法整理

引用方式


/**  es6引用 **/
	import {checkISSupportWebp,checkImageCanUseWebp,calcRem,osInfo,getRequestUrl,getCookie,lt,
    sendError,
    getJsonValue,
    openUrl,
    dateFormat} from '@jdplus/tools'

使用方法


	/** checkISSupportWebp 检查当前环境是否支持webp,需要在入口文件中初始化 **/
	checkISSupportWebp();
    
    /** checkImageCanUseWebp 此方法需要配合checkISSupportWebp使用 判断图片链接是否能使用webp **/
    <img src={checkImageCanUseWebp(elem.image || "")}  />
    
    /** calcRem px转rem转换方法 **/
	calcRem();
    
    /** osInfo 对newOS的进一步封装  
     * 打印查看 console.log("osInfo", osInfo) 
     * ua所有信息:可以通过  uaResult 来解析
     * **/
    let isWeixin  = osInfo.isWeixin

    /** getRequestUrl  获取当前URL中 ?后边的参数集合,如:https://x.x.com/index?needHash=a&checkLogin=true ,getRequestUrl()返回对象{"needHash":"a","checkLogin":true} **/    
    let value = getRequestUrl().key || '';

    /** getCookie 获取cookie中存放的值 **/    
    let value = getCookie(key);

    /** lt 获取登录态类型 **/    
    let currentLt = lt();
   
    /** 
     * sendError 监控日志上报
     * canSendMsg : 是否允许上报,默认不上报;可根据环境自由配置
     * errorInfo : { 'l': '日志等级', 'd': `描述`, 'f': 'function描述', 'e': '需要上报的错误信息' }
     * alarmLevel : 等级参数存在且小于alarmLevel,则上报
     * 
     * */
    sendError(canSendMsg,errorInfo,alarmLevel)   

    /**
     * 获取多层嵌套json值
     * 1.path参数为字符串,如'a.b.c',层级使用'.'隔开
     * 2.json为需要处理的json数据
     * 3.返回如:a.b.c的值
     * 
     * eg :
    let outData = {
        "config":{"cache":false,"data": undefined,"mark":false},
        "data":{"message": "成功","result": {skuRecommendVo: Array(8), plusUserExportInfo: {…},   plusQualificationVo: {…}, plusQualificationResult: {…}, plusUserBaseInfo: {…}},"resultCode": """success": true},
        "status": 200,
        "statusText": "OK",
        "headers": {content-type: "application/json"}
        }
     let path = 'outData.data.result.plusUserBaseInfo'; 
    */
   let plusUserBaseInfo = getJsonValue(path,outData);

    /** 
     * 跳转链接通用方法
     * 内部方法中判断了jdApp环境
     * jumpLink:需要跳转的链接
     * isShieldOpenAppSwitch : 是否屏蔽openApp协议
     * 
    */
    openUrl(jumpLink, isShieldOpenAppSwitch)

    /** 
     * 时间戳转日期格式 
     * timestamp : 时间戳  eg: 1595413047810
     * expectFormat : 期望转换的日期格式  eg: 'yyyy-MM-dd hh:mm:ss'  |  'yyyy.MM.dd'  | 'yyyy年MM月dd日'
     * eg : console.log(dateFormat(1595413047810, "yyyy年MM月dd日"));   ---> 2020年07月22日
     */
    let resultDate = dateFormat(timestamp,expectFormat)