0.1.6 • Published 4 years ago

pure-funs v0.1.6

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

pure-funs

一个纯函数库

API

曲线 (curve)

linear   linear(percent)
获取线性直线的百分比值,percent代表线性上的百分比;

linear(0.5);  //0.5

easeout   easeout(percent)
得出缓出曲线百分比的值, percent代表点在线性上百分比

easeout(0.5) //0.75

easein easein(percent)
得出缓入曲线百分比的值, percent代表点在线性上百分比

easeout(0.5) //0.75

easeinout easeinout(percent)
得出缓入缓出百分比的值,percent代表点在线性上百分比

easeinout(0.5) //0.75

数组 (array)

asc asc(arr) 数组升序

asc([0, 3, 1])  //[0, 1, 3];

desc desc(arr) 数组降序

asc([3, 1, 0])  //[0, 1, 3];

distance distance(arr) 数组去重

distance([0, 0, 1, 1, 2, 3]) //[0, 1, 2]

集合(collections)

sort   sort(collections, key, asc|desc) 按照某个key进行排序

var objArr = [{index: 1}, {index: 3}, {index: 2}, {index: 0}];
sort(objArr, "index", "asc"); //[{index: 0}, {index: 1}, {index: 2}, {index: 3}]

deepSearch   deepSearch(collections, key, value) 根据keyvalue进行查找

var objArr = [{index: 1}, {index: 3}, {index: 2}, {index: 0}];
sort(objArr, "index", "asc"); //[{index: 0}, {index: 1}, {index: 2}, {index: 3}]

cookie

getCookie   getCookie(key) 获得key的值

//document.cookie = "name=123&index=1";
getCookie("name") //123

setCookie   setCookie(key, val) 给key设置值

//document.cookie = "name=123&index=1";
setCookie("name", 1234) ////document.cookie = "name=1234&index=1";

delCookie   delCookie(key) 删除key的值

//document.cookie = "name=123&index=1";
delCookie("name") ////document.cookie = "index=1";

日期时间(date)

getDateTime   getDateTime(dateFormate, millisecond) 根据特定的时间格式获取时间。dateFormat是时间格式:

  • Y: 四位年份,如2019;
  • y: 两位年份, 如19;
  • M: 两位月份, 如01;
  • m: 一位月份,如1;
  • D: 两位日期, 如01;
  • d: 一位日期,如1;
  • H: 两位小时, 如01;
  • h: 一位小时,如1;
  • I: 两位分钟, 如01;
  • i: 一位分钟,如1;
  • S: 两位秒数, 如01;
  • s: 一位秒数,如1;
  • N: 两位毫秒数, 如10;
  • n: 一位毫秒数, 如1
getDateTime("Y-M-D H:I:S", new Date().getTime()) // 2019-04-29 14:31:41
getDateTime("y/m/d h:i:s", new Date().getTime()) // 19/4/29 14:31:4

getDateTime("y/m/d h:i:s:n", new Date().getTime()) // 19/4/29 14:31:4:9

getTime   getTime(dateFormate) 根据时间字符串获取秒数

getTime("2019-04-29 14:31:41") //1556519501227

countdown   countdown(dateFormate, millisecond) 显示特定时间格式的倒计时

countdown("H:I:S", 20000); //00:00:20
countdown("H:I:S:N", 999985); //00:16:39:98
countdown("H:I:S:n", 999985); //00:16:39:9

节点(dom)

$   $(selector) 模仿jquery选择器

$("p");

getElementByClass   getElementByClass(classname) 获取类名

getElementByClass(".list") 

duration

获取持续的时间

var time = duration();  //获取当前时间
time() //返回持续的秒数;

createTimer createTimer(seconds) 可暂定的计时器, 如果seconds有值则是倒计时

const timer = createTimer(15); //倒计时15秒
timer.stop();
timer.seconds(); //显示秒数

数字(number)

isInt   isInt(num) 是否是整数

isFloat   isFloat(num) 是否是浮点数

toDecimal   isDecimal(float, digit) 给数设置特定位数的小数,返回值number

isDecimal(12.333, 2)    // 12.22

toFixed   toFixed() 给数设置特定位数的小数,返回值String;

toFixed(8, 2); //“8.00”

object

安全(safe)

filterXss    filterXss(str) 将字符串的<>分别转义成&lt&gt;

filterXss("<script>alert(123)</script>") //&lt;script&gt;alert(123)&lt;/script&gt;

屏幕(screen)

getPos   getPos() 返回鼠标在页面上的坐标

getHeight   getHeight() 得到页面的高度

getWidth   getWidth() 得到页面的宽度

字符串(string)

trim   trim(str) 去掉字符串开头和结束的空格字符串

copyStr   copyStr(str) 拷贝字符串

单位(unit)

toKm toKm(number) 转化成公里数

超链接(url)

get   get(key) 获取超链接上的值;

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.10

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.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago