2.0.8 • Published 4 years ago

jes-utils v2.0.8

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

jes-utils collections for JavaScript

Jes-utils is a front-end tool library, mainly including BOM, DOM, Regex, Calculator, Client, Common, Date, File, Storage, Geo, Canvas, Event and so on. These main aspects encapsulate some Common methods.

Later on, it will be possible to integrate richer toolchains and accumulate more common methods for easier development

Custom badge GitHub issues GitHub forks GitHub stars GitHub closed issues

Installation


To use with node:

$ npm install jes-utils --save

cmd:

const Utils = require('jes-utils');

amd:

define(['jes-utils'], function(Utils) { // todo })

To use directly in the browser (iife):

<script src="path/dist/jes-utils.js"></script>

or in entry point:

require('jes-utils')

es:

// cmd
const Utils = require('jes-utils')
// es - require module
import { blobToFile } from 'jes-utils/lib/File'
import { getStyle } from 'jes-utils/lib/Dom'
// es - require all
import { Bower, Dom } from 'jes-utils'
// as
import * as Bower from 'jes-utils/lib/Bower'

babel config

.babelrc

"plugin": [["import", {"libraryName": "jes-utils", "libraryDirectory": "lib", "camel2DashComponentName": false}]]

Usage:


Utils.Bower.currentURL()

Bower.currentURL()

getStyle()

The following is the method document provided by js-utils:

Members

Constants

Functions

factorialize ⇒ number

阶乘算法 factorialize

Kind: global variable
Returns: number - - factorialize

TypeDescription
numbernumber

getFibonacci ⇒ number

生成菲波那切数列 getFibonacci

Kind: global variable
Returns: number - - value

TypeDescription
numbernumber

stripHTMLTags ⇒ string

删除字符串中的HTMl标签

Kind: global variable

TypeDescription
stringstr - html模版

scrollToTop

平滑滚动到页面顶部

Kind: global constant

smoothScroll

滚动到指定元素区域

Kind: global constant

ParamType
element*

getScrollPosition

返回当前滚动条位置

Kind: global constant

ParamType
el*

requestAnimFrame ⇒ function

requestAnimationFrame 制作动画

Kind: global constant
Returns: function - - 动画全局对象

cancelAnimFrame ⇒ function

cancelAnimFrame 取消动画

Kind: global constant
Returns: function - - 动画全局对象

formatMoney

金钱格式化,三位加逗号

Kind: global constant

ParamType
numnumber

checkIosAndroidIpad

判断是终端类型,值有ios,android,iPad

Kind: global constant

checkWeixinQqUc

判断是否是微信,qq 或 uc

Kind: global constant

checkIsIphoneX

检查是否是 IphoneX

Kind: global constant

objIsEqual

判断两个对象是否相等,目前只支持对象值为简单数据类型的判断

Kind: global constant

ParamTypeDescription
oneObjObject对象
twoObjObject对象

RandomNum

生成指定范围随机数

Kind: global constant

ParamType
minnumber
maxnumber

getMonthNum

获取当前月天数

Kind: global constant

ParamTypeDescription
yearString年份
monthString月份

timesToYyMmDd ⇒ date

时间戳转化为年月日

Kind: global constant
Returns: date - - data - 年月日

TypeDescription
datetimes - 时间戳
stringymd - 格式类型(yyyy-mm-dd,yyyy/mm/dd)
stringhms - 可选,格式类型(hh,hh:mm,hh:mm:ss)

hideTag

隐藏所有指定标签 例: hide(document.querySelectorAll('img'))

Kind: global constant

TypeDescription
nodeel

getStyle

返回指定元素的生效样式

Kind: global constant

ParamTypeDescription
elelement元素节点
ruleNamestring指定元素的名称

elementContains

检查是否包含子元素

Kind: global constant

ParamTypeDescription
parentelement
childelement例:elementContains(document.querySelector('head'), document.querySelector('title')); // true

escapeHTML

转义html(防XSS攻击)

Kind: global constant

TypeDescription
stringstr - 需转义的字符串

fileToBase64

file转base64

Kind: global constant

TypeDescription
*file 图片文件

blobToFile

blob转file

Kind: global constant

TypeDescription
blobblob
stringfileName

base64ToBlob

base64转blob

Kind: global constant

ParamType
base64base64

base64ToFile

base64转file

Kind: global constant

TypeDescription
base64base64
stringfilename 转换后的文件名

isNoWord ⇒ boolean

验证不能包含字母

Kind: global constant
Returns: boolean - - true/false

TypeDescription
stringvalue

isCHNAndEN ⇒ boolean

验证中文和数字

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isPostcode ⇒ boolean

验证邮政编码(中国)

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isWeChatNum ⇒ boolean

验证微信号,6至20位,以字母开头,字母,数字,减号,下划线

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isColor16 ⇒ boolean

验证16进制颜色

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isIMEI ⇒ boolean

验证手机机身码(IMEI)

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isHttpAndPort ⇒ boolean

验证必须带端口号的网址(或ip)

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isRightWebsite ⇒ boolean

验证网址(支持端口和"?+参数"和"#+参数)

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isEnglishName ⇒ boolean

验证英文姓名

Kind: global constant
Returns: boolean - - true/false

ParamType
valuestring

isChineseName

验证中文姓名

Kind: global constant

ParamType
valuestring

isImageUrl

验证图片链接地址(图片格式可按需增删)

Kind: global constant

ParamType
valuestring

isVersion

验证版本号格式必须为X.Y.Z

Kind: global constant

ParamType
valuestring

isAccountNumber

验证银行卡号(10到30位, 覆盖对公/私账户, 参考微信支付)

Kind: global constant

ParamType
valuestring

isLicensePlateNumberNER

验证车牌号(新能源/非新能源)

Kind: global constant

TypeDescription
stringvalue
stringtype(new/normal/default)

isMPN

验证手机号中国(严谨), 根据工信部2019年最新公布的手机号段

Kind: global constant

TypeDescription
stringvalue
stringisStrict 是否严格模式验证

isLandlineTelephone

验证座机电话(国内),如: 0341-86091234

Kind: global constant

ParamType
valuestring

isIDCard

验证身份证号, 支持1/2代(15位/18位数字)

Kind: global constant

ParamType
valuestring

isPassport

验证护照(包含香港、澳门)

Kind: global constant

ParamType
valuestring

isWebAccount

验证帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线组合

Kind: global constant

ParamType
valuestring

isChineseCharacter

验证中文/汉字

Kind: global constant

ParamType
valuestring

isQQNum

验证qq号格式

Kind: global constant

ParamType
valuestring

isNumAndStr

验证数字和字母组成

Kind: global constant

ParamType
valuestring

cookieSet

Kind: global constant

ParamTypeDescription
keyString属性
value*
expireString过期时间,单位天

cookieGet

cookie 获取

Kind: global constant

ParamTypeDescription
keyString属性

cookieRemove

cookie 删除

Kind: global constant

ParamTypeDescription
keyString属性

sessionStorageSet

sessionStorage 存贮某一段时间失效

Kind: global constant

ParamTypeDescription
keyString属性
value*存贮值
expireString过期时间,毫秒数

sessionStorageRemove

sessionStorage 删除

Kind: global constant

ParamTypeDescription
keyString属性

sessionStorageGet

sessionStorage 获取

Kind: global constant

ParamTypeDescription
keyString属性

localStorageSet

localStorage 存贮某一段时间失效

Kind: global constant

ParamTypeDescription
keyString属性
value*存贮值
expirenumber过期时间,毫秒数

localStorageGet

localStorage 获取

Kind: global constant

ParamTypeDescription
keyString属性

localStorageRemove

localStorage 移除

Kind: global constant

ParamTypeDescription
keyString属性

currentURL() ⇒ string

返回当前url

Kind: global function

getUrlParam() ⇒ null

获取url参数(第一种)

Kind: global function

TypeDescription
stringname
stringorigin

getUrlParams(name, origin)

获取url参数(第二种)

Kind: global function

ParamType
name*
origin*

replaceParamVal(paramName, replaceWith)

修改url中的参数

Kind: global function

ParamType
paramNamestring
replaceWithstring

funcUrlDel(name)

删除url中指定的参数

Kind: global function

ParamType
namestring

getClientHeight()

获取窗口可视范围的高度

Kind: global function

getPageViewWidth()

Kind: global function

getPageWidth()

获取窗口宽度

Kind: global function

getViewportOffset()

获取窗口尺寸

Kind: global function

getPageScrollTop()

获取滚动条距顶部高度

Kind: global function

getPageScrollLeft()

获取滚动条距左边的高度

Kind: global function

Type
*

launchFullscreen(element)

开启全屏

Kind: global function

ParamType
element*

openWindow(url, windowName, width, height)

打开一个窗口

Kind: global function

ParamType
urlstring
windowNamestring
widthnumber
heightnumber

exitFullscreen()

关闭全屏

Kind: global function

getQueryString(name)

获取 url 后面通过?传参的参数

Kind: global function

ParamType
nameString

AutoResponse(width)

自适应页面(rem)

Kind: global function

ParamType
widthnumber

getTreeData(data, pid, pidName, idName, childrenName, key) ⇒ array

递归生成树形结构

Kind: global function

ParamTypeDefaultDescription
data*
pid*
pidNamestring"'parentId'"
idNamestring"'id'"
childrenNamestring"'children'"
keystringkey

inArray(item, data)

查询数组中是否存在某个元素并返回元素第一次出现的下标

Kind: global function

ParamType
item*
dataarray

countOccurrences(arr, value)

数组中某元素出现的次数

Kind: global function

ParamType
arrarray
value*

quickSort() ⇒ Array

quick sort calculator

Kind: global function
Returns: Array - - arr - 序列后数组

TypeDescription
Arrayarr - 数组

bubbleSort() ⇒ Array

bubble sort calculator

Kind: global function
Returns: Array - - arr - 序列后数组

TypeDescription
Arrayarr - 数组

bubbleSort~temp

console.time('bubbels') => console.timeEnd('bubbels'): 0.02685546875ms

Kind: inner property of bubbleSort

checkBrowser

判断是浏览器内核() Kind: global function

OutOsName(osVersion)

Windows根据详细版本号判断当前系统名称

Kind: global function

ParamType
osVersionstring

detectDeviceType()

检测移动/PC设备

Kind: global function

深拷贝(<object>) ⇒ cloneObj

Kind: global function
Returns: cloneObj -

ParamType
currentObject

isObject(obj) ⇒

Kind: global function
Returns: boolean

ParamType
obj*

getQueryString(name)

获取 url 后面通过?传参的参数

Kind: global function

ParamType
nameString

randomNumInteger(min, max) ⇒ number

生成随机整数

Kind: global function

ParamType
min*
max*

equals() ⇒ boolean

equals 是否全等 - object | array | string | number | function

Kind: global function
Returns: boolean - - true/false

isYesterday(val) ⇒ boolean

Kind: global function
Returns: boolean - 返回布尔值

ParamTypeDescription
valstring需要验证的日期

timeToTimestamp(time) ⇒ Number

Kind: global function
Returns: Number - - 返回值为时间毫秒值

ParamTypeDescription
timeStringtime - 日期字符串,如'2018-8-8','2018,8,8','2018/8/8'

dom选择器(tagName) ⇒ Object

Kind: global function
Returns: Object - tag

ParamType
tagNamestring

EventHub() ⇒ Object

EventHub 发布者订阅事件器

Kind: global function
Returns: Object - - 广播/订阅

TypeDescription
null无返回参数

formatFileSize(fileSize)

B转换到KB,MB,GB并保留两位小数

Kind: global function

ParamType
fileSizenumber

fileToBase64String(file, format, size, formatMsg, sizeMsg) ⇒ Promise.<any>

获取文件base64编码

Kind: global function

ParamDescription
file
format指定文件格式
size指定文件大小(字节)
formatMsg格式错误提示
sizeMsg大小超出限制提示

memoize() ⇒ Map

缓存函数器

Kind: global function
Returns: Map - - cached - 类数组

TypeDescription
functionfn - 函数
2.0.7

4 years ago

2.0.6

4 years ago

2.0.8

4 years ago

2.0.5

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago