8000 GitHub - feinikes/elfin: 这是一些常用的JS函数
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feinikes/elfin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

安装

npm install elfin

使用方式

在vue项目main.js中使用:

import Vue from 'vue';
import elfin from 'elfin';

Vue.use(elfin);
this.$elfin.getNowDate();

日期函数操作

formatTime(date, mark)
  date:Date参数;
  mark:年月日分隔符号,默认“-”;
  return “YYYY-MM-DD HH:mm:ss”
getNowDate(mark)
  mark:年月日分隔符号,默认“-”;
  return “YYYY-MM-DD HH:mm:ss”
formatYMD(date, mark)
  date:Date参数;
  mark:年月日分隔符号,默认“-”;
  return “YYYY-MM-DD”
formatHMS(date)
  date:Date参数;
  return “HH:mm:ss”
formatWeek(date)
  date:Date参数;
  return “星期一”
formatNumber(num)
  num:数字;
  return 个位数会在前面加上“0”

localStorage、sessionStorage存储操作

setLocal(key,value)
  key:localStorage键值;
  value:可以为任何对象;
getLocal(key)
  key:localStorage键值;
  return:localStorage的存储,取之前存得值,不过返回得都是字符串;
delLocal(key)
  key:localStorage键值;
  注:localStorage的存储,删之前存得值;
setSession(key,value)
  key:sessionStorage键值;
  value:可以为任何对象;
getSession(key)
  key:sessionStorage键值;
  return:sessionStorage的存储,取之前存得值,不过返回得都是字符串;
getSessionObj(key)
  key:sessionStorage键值;
  return:sessionStorage的存储,取之前存得对象,直接返回对象;
delSession(key)
  key:sessionStorage键值;
  注:sessionStorage的存储,删之前存得值;
delAllSession()
  注:sessionStorage的存储,删之前所有存得值;

数组相关操作

arrIn(arr, item)
  arr:目标数组;
  item:需要判断得元素;
  return true就是包含,false就是不包含
arrDel(arr, item)
  arr:目标数组;
  item:需要删除得元素;
  return 处理后得数组
arrRandom(arr)
  arr:目标数组;
  return 输入数组,会随机抽取数组中得一个值输出
arrRepeat(arr)
  arr:目标数组;
  注: 数组去除重复
arrMax(arr)
  arr:目标数组;
  return 数组最大值
arrMin(arr)
  arr:目标数组;
  return 数组最小值
arrSort(arr,order)
  arr:目标数组;
  order:需要判断得元素;
  return 排序后数组

字符串相关操作

strCut(str, length)
  str:目标字符串;
  length:需要的长度;
  return 截取后的字符串
strTrim(str)
  str:目标字符串;
  return 清除空格之后的字符串

其他操作

getSumFunc(...nums)
  注:不定参数求和;
toThousands(num,cent,isThousand)
  num:需要转换的对象可以是数字字符串或数字;
  cent:需要保留的小数点后的位数,默认2;
  isThousand:是否以千分位显示,默认1,只有两个值1、0;
  return “10,000.00”;
reBirtyhday(idNum, mark)
  idNum:身份证号码;
  mark:连接符号,默认“-”;
  return:“1987-09-28”;

About

这是一些常用的JS函数

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0