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

gree-miniprogram-h5-utils

v0.0.6

Published

格力+小程序h5的工具包,不依赖于任何框架,可在任何项目中安装使用。

Downloads

15

Readme

gree-miniprogram-h5-utils

格力+小程序h5的工具包,不依赖于任何框架,可在任何项目中安装使用。

安装

1、Using npm

npm i -S gree-miniprogram-h5-utils

2、Using yarn

yarn add gree-miniprogram-h5-utils

使用方式:

1、ES6模块引入


第一种:(推荐使用此方式)
  // 引入
  import { isGreeMiniProgram } from 'gree-miniprogram-h5-utils';
  // 使用
  const isInGreeMiniProgramEnv = isGreeMiniProgram();
  if (isInGreeMiniProgramEnv) {
    // ...
  } else {
    // ...
  }


第二种:
  // 引入
  import greeMiniprogramH5Utils from 'gree-miniprogram-h5-utils';
  // 或者 import * as greeMiniprogramH5Utils from 'gree-miniprogram-h5-utils';
  // 使用
  greeMiniprogramH5Utils.isGreeMiniProgram();

2、CommonJS模块引入

  const { isGreeMiniProgram } = require('gree-miniprogram-h5-utils')



当前支持的工具函数

boolean isGreeMiniProgram(url?:string = window.location.href, queryKey?:string = 'passthrough', customKey?:string = 'origin', customVal?:string = 'greeapp') ——判断当前h5是否在gree+小程序主体中加载。

  url(非必填):字符串类型;h5的访问地址,若不填写该参数时,将window.location.href作为判断的url;若不填写该参数且window.location.href属性不存在时,会抛出一个异常。

  queryKey(非必填):字符串类型;指定url中的query的具体key为存放自定义数据的key,默认为 passthrough

  customKey(非必填):字符串类型;自定义数据中表示是否在格力+主体中的key,默认为origin

  customVal(非必填):字符串类型;自定义数据中表示是否在格力+主体中的key对应的值,默认为greeapp


object getParams(url?: string = window.location.href) ——获取当前url的所有参数


object getGreeParams(url?: string = window.location.href, key?: string = 'passthrough') ——获取格力侧自定义参数


object merge(obj1: object, obj2: object) ——合并两个对象的内容


Pormise untilFinished(promise: Promise | Promise[], millisecond: number) ——至少millisecond毫秒后才完成(可以用在loading状态处理:获取后端数据时显示loading状态,获取完成后取消显示loading状态,但如果后端返回较快,loading会闪一下立马消失)


any deepClone(original: any) ——深拷贝(真正意义上的深拷贝,可以弥补用JSON.parse和JSON.stringify来拷贝的局限性)


function debounce(fn: function, wait: number, immediate?: boolean) ——防抖函数,返回一个经过封装后的函数;

wait:设置防抖的时间周期,如果下一次触发离上一次触发的时间小于时间周期,那么上一次触发的函数不会执行;也就是说,存在N * wait 时间内只会执行一次函数的情况:函数每次触发都离上一次触发的时间小于wait。

immediate:可选,是否在第一次触发时执行函数。(默认为false,即延迟到最后一次触发后的wait时间后执行函数)


function throttle(func: function, wait: number) ——节流函数,返回一个经过封装后的函数;

wait:设置节流的时间周期,在这个周期内触发多次事件时,一定会执行一次。


function groupArray(arr: Array, groupSize?: number) ——将一维数组中的元素,每 groupSize 个为一组,转换为二维数组;

groupSize:分组后每个分组中的数组长度,如果设置为0,则返回原数组的浅拷贝;如果 < 0或者不传该参数,重置为0