Giter VIP home page Giter VIP logo

jstool's Introduction

jsTool(持续更新和修缮)

原生JS封装的通用函数库

##API

jsTool.type(value)

返回value的类型。

jsTool.type('javascript'); 

// "string"


jsTool.type(123); 

// "number"

jsTool.isNumber(value)

jsTool.isNumber(123); 

// true

jsTool.isNumber('str')

//false

jsTool.isString(value)

jsTool.isString('I am Rcong'); 

// true

jsTool.isNull(value)

jsTool.isNull(undefined); 

//false

jsTool.isNull(null); 

// true

jsTool.isUndefined(value)

jsTool.isUndefined(undefined); 

//true

jsTool.isUndefined(null); 

// false

jsTool.isObject(value)

jsTool.isObject({}); 

//true

jsTool.isObject('str'); 

// false

jsTool.isBoolean(value)

jsTool.isBoolean(false); 

//true

jsTool.isBoolean(123); 

// false

jsTool.isFunction(value)

jsTool.isFunction(document.getElementById);

//true

jsTool.isFunction('111'); 

// false

jsTool.isArray(value)

jsTool.isArray([]);

//true

jsTool.isArray(new Array());

//true

jsTool.isArray({}); 

// false

jsTool.isDate(value)

jsTool.isDate(new Date());

//true

jsTool.isArray(Date.now());

//false

jsTool.isValidDate(value, userFormat)

根据给定格式验证日期是否合规。

jsTool.isValidDate('2016-07-12', 'yyyy-mm-dd');

//true

jsTool.isValidDate('2016.07.32', 'yyyy.mm.dd');

//根据yyyy.mm.dd格式来验证日期,因为没有32号而返回false

jsTool.isRegExp(value)

jsTool.isRegExp(/^abc/);

//true

jsTool.isRegExp(new RegExp('abc'));

//true

jsTool.isRegExp('abc');

//false

jsTool.limitStr(str, length)

根据length来限制给定的字符串str的长度,如超出,超出部分使用省略号替换

jsTool.limitStr('javascript', 2);

//"ja…"

jsTool.limitStr('javascript', 12);

//"javascript"

jsTool.isBreakPoint(bp)

目前很多设计已经采用了响应式布局来适配网站或应用在不同设备上的显示。所以经常需要在代码中判断当前处于哪一个屏幕适配度下。目前断点分别断在320px480px768px1024px1366px1440px1600px1920px

//当前屏幕宽度1389px
jsTool.isBreakPoint(1366);

//false

jsTool.isBreakPoint(1440);

//true

//使用方法
if ( jsTool.isBreakPoint(320) ) {
  // 小于320px所做的操作
}
if ( jsTool.isBreakPoint(480) ) {
  // 在320px ~ 480px之间的操作
}

jsTool.trim(str, trimMode)

去除去除字符串的空白字符,第二个参数trimModetrim模式,有三个取值:leftrightall

  • left
jsTool.trim('  javascript html css  ', 'left');
//"javascript html css  "
  • right
jsTool.trim('  javascript html css  ', 'right');
//"  javascript html css"
  • all
jsTool.trim('  javascript html css  ', 'all');
//"javascripthtmlcss"

jsTool.uniqueArray(arr)

数组去重

var arr = [1, 2, 3, 'a', '1', 'a', 2];
jsTool.uniqueArray(arr);
//[1, 2, 3, "a", "1"]

jsTool.isEmptyObject(obj)

判断是否是空对象

var obj = {};
jsTool.isEmptyObject(obj);
//true

obj[1] = 'Hello Js';
jsTool.isEmptyObject(obj);
//false

jstool's People

Contributors

rcong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.