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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bbtfe/utils

v1.0.7

Published

封装了公用的基础样式,及常用功能函数

Downloads

5

Readme

utils组件

封装了公用的基础样式,及常用功能函数

引用方式

文件被输出为umd格式,可以使用下面3种方式引用。

npm引用

npm i @bbtfe/utils
import utils from '@bbtfe/utils';

script引用

支持HTTPS和HTTP,建议在通常页面中使用下面去掉协议头的形式引用即可。

<script src="//static02.babytreeimg.com/img/bca/utils/1.0.7/utils.min.js"></script>

PHP引用方式

建议合并脚本

StaticFileControl::addXXX('/img/bca/utils/1.0.7/utils.min.js');

开发说明

  • 拉取源码到本地,源码目录:bbt-fe-comp/utils
  • npm i
  • 修改源码文件utils/src
  • npm run build
  • bbt-common-asset项目下对应的SDK目录(bbt-common-asset/static/utils)新建版本号文件夹
  • 将dist下文件拷至 新版本号 目录里
  • 以gittool方法提交代码, 编译后的代码bbt-common-asset,源码bbt-fe-comp, 都需要提交
  • 项目中引入验证下

API

selectText

  • Select text on an element.
  • @param {any} node Selector or element node of the target,need be unique.
selectText(node);

getTransformMatrix

  • Get transform matrix.
  • @param {any} node Selector or element node of the target.
  • @returns {Object} The matrix {a,b,c,d,e,f,m11,m12,m13,m14}.
getTransformMatrix(node);

getTransformMatrixStr

  • Get transform matrix string.
  • @param {Object} obj Matrix object.
  • @returns {String} The matrix string 'matrix(a,b,c,d,e,f,m12,m13,m14)'.
getTransformMatrixStr(obj);

getUniqueId

  • Get Unique id
  • @param {String} prefix The id's prefix.
  • @returns The Unique id with prefix.
getUniqueId(prefix);

dateToString

  • Date or datetime to pretty string.
  • @param {Date} date Optional,Date object.
  • @param {String} format Optional,date format,default is 'yyyy-MM-dd'.
  • @returns {String} Formated date string.
dateToString(date, format);

dateAddDays

  • Add days to a date.
  • @param {Number} days days count.
  • @param {Date} date Optional,date object.
  • @returns {String} Added date object.
dateAddDays(days, date);

dateAddMonths

  • Add month to a date.
  • @param {Number} months months count.
  • @param {Date} date Optional,date object.
  • @returns {String} Added date object.
dateAddMonths(months, date);

repeatExecute

  • Repeat execute a function with a timeout.
  • @param {Function} func Function needed execute.
  • @param {Number} timeOut Optional,timeout in milliseconds(ms),default is 600
  • @param {Number} interval Optional,interval in milliseconds(ms),default is 100
repeatExecute(func, timeOut, interval);

getRandomInt

  • Get random numbers with specified range
  • @param {Number} min Minimum number.
  • @param {Number} max Max number.
  • @returns {Number} random number.
getRandomInt(min, max);

getQuery

  • Get query from url by name.
  • @param {String} name Query name.
  • @param {String} url Optional,the url.
  • @returns {String} Query value.
getQuery(name, url);

addOrUpdateQuery

  • Add or update query string.
  • @param {String} name Query name.
  • @param {String} value Query value
  • @param {String} url Optional,the url.
  • @returns {String} Query value.
addOrUpdateQuery(name, value, url);

isEmpty

  • Detect whether the given value is null(undefined,null,'')
  • @param value
  • @returns
isEmpty(value);

isNumberKeyCode

  • Check is number keycode.
  • @param event The keypress/keydown/keyup event
isNumberKeyCode(event);

isNumericKeyCode

  • Check is numeric keycode.
  • @param event The keypress/keydown/keyup event
isNumericKeyCode(event);

getMobileOS

  • Determine the mobile operating system.
  • This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'.
getMobileOS();

getParent

  • get closest parent(selector) node of el.
  • @param {any} el
  • @param {any} selector
getParent(el, selector);

getQueries

  • deserialize query string.
getQueries();

serialize

  • serialize an object to url params.
  • @param {any} obj
serialize(obj);

loadScript

  • dynamic load script.
  • @param {any} src
  • @param {any} callback
loadScript(src, callback);

isInViewport

  • detect el is in viewport or not.
  • @param {any} el
isInViewport(el);