1.0.2 • Published 5 years ago

roo-tool v1.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

roo-tool

袋鼠云前端工具函数

Install

npm install roo-tool

使用

<script src="/path/to/roo-tool.js">
//或
</script><script src="/path/to/roo-tool.min.js"></script>

Package Managers

JavaScript RooTool supports npm and yarn under the name roo-tool. Module Loaders

Module Loaders

JavaScript RooTool can also be loaded as an AMD, CommonJS or ES6 module.

集成模块

集成npm第三方依赖包,包含其所有功能。

js-cookie //最新版本
urijs   //最新版本

Basic Usage

cosnt {LocalDb,URI,Cookie,Tool} from 'roo-tool';
localDb.set('dux','nblt');
localDb.get('dux');
localDb.clear();

Cookies.set('name', 'value', { path: '' });
Cookies.remove('name'); // fail!
Cookies.remove('name', { path: '' }); // removed!

// URI基本操作api
var url = new URI();
// return http://smoothprogramming.com/tutorials/get-set-query-string-values-from-url-using-uri-js
// This is equivalent to window.location.href command in js.

url = new URI("http://www.smoothprogramming.com:80/tutorials/get-set-query-string-values-from-url-using-uri-js.html");
// Sets URL to http://www.smoothprogramming.com:80/tutorials/get-set-query-string-values-from-url-using-uri-js.html

url;
// return "http://www.smoothprogramming.com:80/tutorials/get-set-query-string-values-from-url-using-uri-js.html"

url.protocol());
// return "http"

url.origin();
// return "http://www.smoothprogramming.com:80"

url.hostname());
// return "www.smoothprogramming.com"

url.host());
// return "www.smoothprogramming.com:80"

url.port());
// return "80"

url.path());
// return "/tutorials/get-set-query-string-values-from-url-using-uri-js.html"

url.directory());
// return "/tutorials"

url.filename());
// return "get-set-query-string-values-from-url-using-uri-js.html"

更多URI及Cookie的信息请查看

Cookie操作相关api: https://www.npmjs.com/package/js-cookie

URI操作相关apI: https://www.npmjs.com/package/urijs


localDb.js相关API

方法说明参数返回值
set按key存贮数据value到localStorage(key,value),key存贮数据的唯一标识,value 所要存贮的数据null
get通过key从localStorage获取数据key(获取数据的可以标识)null/string/object
clear清空localStorage--

Tool.js相关API
方法说明参数返回值
trim去除空串stringstring
getDocumentTop获取文档高度number
getWindowHeight可视窗口高度number
getScrollHeight滚动条滚动高度number
getObjectURL自定义上传事件获取文件URl方法filestring
getStrlen计算字符串长度(英文占1个字符,中文汉字占2个字符)stringnumber
isRealUrl校验Url的有效性urlbool
isJSONStr判断是否是JSONstringbool
isFunction判断是否是函数functionbool
isPhoneNumber校验手机号格式stringbool
toThousands分隔数值千分位符numbernumber
debounceFunc防抖函数func,wait,immediatenull

####Changelog

moved to Changelog

如果封装好更加好用的方法函数,欢迎联系补充

linhe@dtstack.com

1.0.2

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago