vim_utility
v1.0.11
Published
helper export functionfor javascript
Downloads
2
Readme
javascript-utility
Install
npm install --save-dev vim_utility
usage
import {s_random} from "vim_utility"
s_random(7);
doc
scss
click to see code
// import px2rem.js in your bootstrap js
import {px2rem} from "vim_utility/utility"
// Dynamically change the html font-size when window's size changed
px2rem();
@import '~vim_utility/src/scss/px2rem.scss';
$designWidth : 750px; /*Design draft width*/
.example{
height: px2rem(200px);
border: solid 1px black;
font-size: 12px ;
[data-dpr="2"] &{
font-size: 24px;
}
[data-dpr="3"] &{
font-size: 36px;
}
}
cookie
// assuming there is (yourKey => yourValue) in the cookie
getCookie(yourKey); // return yourValue
removeCookie(yourKey);
setCookie(key, value, days);
dom
addClass(ele, cls); /*ele instance of Node, cls is string*/
closestNode(el, selector); /*Similar to the jquery closestNode method*/
css(ele, prop); /*get css attribute value*/
elementFromPoint(e); // e is mouse event
// return Node
getCaretPosition (el); // return number;
getMaxZIndex(ele = undefined); // if ele === undefined , return max z-index value in the document
getScrollLeft();
getScrollTop();
hasClass(ele, cls);
nextNode(el, selector);
offset(ele); // get distance away from window
/* @return
* {
left: x,
top: y
}
* */
parentNode(el, selector, root=undefined);
prevNode(el, selector);
removeClass(ele, cls);
scrollTo(to, duration); // scroll to given place during given time
setScrollTop(value); // it exec window.scrollTo();
toggleClass(ele, cls);
toDataUri(url, (d) => {console.log(d);}); // transfer image png/jpg to base64
function
throttle(delay, callback, debounceMode = false, immediate = false);
let wrap = debounce(/*callback*/ (e) => {console.log(e);}, /*delay*/ 500); // return wrapper function;
window.addEventListener('resize', (e) => {wrap(e)});
keycode
keyCode(name); // return keyCode Number;
object
deepClone(obj); // return any;
random
n_random(min, max, n = 1);
s_random(7); // return string it's length is 7
regexp
getExplore(); // get explore type and version
getOS();
getUrlParam(url); // return Map;
isChinaIDCard(str); // return boolean
isEmail(str); // return boolean
isPhone(str); // return boolean, validator chinese phone number
isUrl(url); // return boolean
time
getTimeStamp({ cal = new Date(), d = 0, h = 0, m = 0 , s = 0 } = {}); // return number(seconds)