1.0.7 • Published 4 years ago

@bbtfe/utils v1.0.7

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

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);
1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago