toolscript
A mini tools of JavaScript
Install
yarn add toolscript --dev
or npm
npm install toolscript --save-dev
Usage
import * as tool from 'toolscript'tool.echo.red('echo red')// echo red stringtool.detectIE(9)//if current browser is IE 9 return true else return falsetool.copyText('content')//copy the `content` to clipboardtool.throttle(Func, 50, 100)//The call that is triggered continuously within a 50ms interval, the latter call will handle the pending processing of the previous call, but at least once every 100mstool.timeDifference('2017-01-01 12:00:00', '2018-01-01 13:00:00')//Calculate the difference between two times, return '365天1小时0分钟0秒'tool.arrayRemoveEle(['1', '2', '3'], '1')//Remove the element that belong to the arraytool.isPlainObject(obj)//Judge the value is a Object.tool.rgbToHex(255, 255, 255)//rgb switch to the Hexadecimal.too.countMaxRepetition('abskgoxugnska14432q1124')//Count the characters that repeat the most times in a string.too.unitNormalization(1.259, 2) //1.26//Format the number that reserve the decimal for the specified number of digits.ORimport { echo, detectIE, ...other } from 'toolscript'echo.red('echo red')// echo red stringdetectIE(9)//if current browser is IE 9 return true else return falsecopyText('content')//copy the `content` to clipboard...
Tool List
- echo
- detectIE
- copyText
- throttle
- timeDifference
- arrayRemoveEle
- isPlainObject
- rgbToHex
- countMaxRepetition
- unitNormalization
- getScriptPath
Tools
name | function | parameters | description |
---|---|---|---|
echo |
echo.black(content) echo.red(content) echo.green(content) echo.yellow(content) echo.blue(content) echo.carmine(content) echo.cyan(content) |
any data | echo colorful information in console |
detectIE | detectIE(version) |
`int` version of IE |
judge IE version |
copyText | copy(text) |
string the content |
copy the content to clipboard, it must be called as a direct result of user action. |
throttle | throttle(fn, delay, mustRunDelay) |
throttle function`function` the time that successive calls do not trigger, it's in milliseconds `number` the time that at least once, it's in milliseconds `number` |
function throttle |
timeDifference | timeDifference(startTime, endTime) |
startTimen`String` endTime`String` |
Calculate the difference between two times |
arrayRemoveEle | arrayRemoveEle(array, removeValue) |
array`Array` removeValue`Element type` |
Remove the element that belong to the array |
isPlainObject | isPlainObject(obj) |
any data |
Judge the value is a Object |
rgbToHex | rgbToHex(R, G, B) |
the rgb value`number` |
rgb switch to the Hexadecimal |
countMaxRepetition | countMaxRepetition('abskgoxugnska14432q1124') |
`string` |
Count the characters that repeat the most times in a string. |
unitNormalization | unitNormalization(1.253, 2) |
`number` `int` |
Format the number that reserve the decimal for the specified number of digits. |
getScriptPath | getScriptPath() | Get current script url. |
Release
npm publish
License
The MIT License (MIT). Please see License File for more information.