0.0.5 • Published 3 years ago
front-end-common-method v0.0.5
front-end-common-method
English | 中文
Introduce
A collection of common front-end methods for easy development
Applicable to mobile terminals, some methods come from the Internet
Usage
npm i front-end-common-method -D
// index.js
import FecmPlugin from ('Front-end-common-metho');
const myPlugin = new FecmPlugin();
Method
Methods provided by plug-ins
loadImages(src)
Load images
Parameter name | Explanation | Default value |
---|---|---|
src | URL of the image to load | '' |
Example:
myPlugin
.loadImages('http://xxxx')
// Loaded successfully
.then(img => {
})
// Failed to load
.catch(err => {
});
wait(delay)
Delay function
Parameter name | Explanation | Default value |
---|---|---|
delay | time to delay | 500 |
Example:
myPlugin
.wait(1000)
// Execute after a delay of 1s
.then( => {
});
showTips({})
Display prompt pop-up
Parameter name | Explanation | Default value |
---|---|---|
autoClose | Whether to close automatically | true |
delay | How many seconds to close automatically | 1000 |
text | Copy to display | loading... |
Example:
myPlugin
.showTips({
autoClose: false,
delay: 2000,
text: 'please waiting'
});
closeTips()
Close the prompt pop-up
Explanation: Applicable when autoClose: false
of showTips
Example:
myPlugin.closeTips();
rangeRandom(min, max)
Generates a range of random integers
Parameter name | Explanation | Default value |
---|---|---|
min | Generated minimum value | 0 |
max | Generated maximum value | 0 |
Example:
// Generate random numbers from 1 to 10
const num = myPlugin.isPhoneNum(1, 10);
removeEmoji(content)
remove emoji from string
Parameter name | Explanation | Default value |
---|---|---|
content | String content | '' |
Example:
const str = myPlugin.removeEmoji('hello,I am 🍁');
console.log(str); // hello,I am
allChinese(val)
Determine whether it is pure Chinese (excluding spaces, special characters)
Parameter name | Explanation | Default value |
---|---|---|
val | String content | '' |
Example:
const str = myPlugin.allChinese('你好吗?');
console.log(str); // false,because of the special character question mark
allEnglish(val)
Determine whether it is pure English (excluding spaces, special characters)
Parameter name | Explanation | Default value |
---|---|---|
val | String content | '' |
Example:
const str = myPlugin.allEnglish('hello world');
console.log(str); // false,because it contains spaces
hasSpecialCharacters(str)
Determine if there are special characters
Parameter name | Explanation | Default value |
---|---|---|
str | String content | '' |
Example:
const str = myPlugin.allEnglish('??!');
console.log(str); // true
removeSpaceSrt(str)
remove spaces from string
Parameter name | Explanation | Default value |
---|---|---|
str | String content | '' |
Example:
const str = myPlugin.allEnglish('hello, I am lMC');
console.log(str); // hello, IamlMC
checkID(ID)
Verify ID
Parameter name | Explanation | Default value |
---|---|---|
ID | ID card (only supports mainland ID cards) | '' |
Example:
const flag = myPlugin.checkID('441522xxxxxxxxxxxx');
// ID card format is correct
if (flag) {
}
// ID card format error
else {
}
checkEmail(email)
Verify email
Parameter name | Explanation | Default value |
---|---|---|
email | '' |
Example:
const flag = myPlugin.checkEmail('xxxx@gmail.com');
// Email format is correct
if (flag) {
}
// Email format error
else {
}
isPhoneNum(phone)
Verify phone number
Parameter name | Explanation | Default value |
---|---|---|
phone | Mobile number (only supports mainland mobile phones) | '' |
Example:
const flag = myPlugin.isPhoneNum('1581xxxxx81');
// Mobile number format is correct
if (flag) {
}
// Wrong format of phone number
else {
}
Properties
Properties provided by the plug-in
Parameter name | Default value | Explanation | Value Description |
---|---|---|---|
platform | unknown | Whether it is mobile or pc . | pc : pc mobile : mobile |
screenType | unknown | Phone screen type | X : Full screen normal : Normal screen (iphone5, 6, 7) short : Smaller than normal screen |
showTipsObj | null | popup object | Dom object for showTips method |
sysTem | unknown | client system | ios : ios system android : android system not moblie : Current non-mobile terminal |
version | '' | Plugin version number |