0.0.5 • Published 3 years ago

front-end-common-method v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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 nameExplanationDefault value
srcURL of the image to load''

Example:

myPlugin
.loadImages('http://xxxx')
// Loaded successfully
.then(img => {
    
})
// Failed to load
.catch(err => {
    
});

wait(delay) Delay function

Parameter nameExplanationDefault value
delaytime to delay500

Example:

myPlugin
.wait(1000)
// Execute after a delay of 1s
.then( => {
    
});

showTips({}) Display prompt pop-up

Parameter nameExplanationDefault value
autoCloseWhether to close automaticallytrue
delayHow many seconds to close automatically1000
textCopy to displayloading...

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 nameExplanationDefault value
minGenerated minimum value0
maxGenerated maximum value0

Example:

// Generate random numbers from 1 to 10
const num = myPlugin.isPhoneNum(1, 10);

removeEmoji(content) remove emoji from string

Parameter nameExplanationDefault value
contentString 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 nameExplanationDefault value
valString 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 nameExplanationDefault value
valString 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 nameExplanationDefault value
strString content''

Example:

const str = myPlugin.allEnglish('??!');
console.log(str); // true 

removeSpaceSrt(str) remove spaces from string

Parameter nameExplanationDefault value
strString content''

Example:

const str = myPlugin.allEnglish('hello, I am lMC');
console.log(str); // hello, IamlMC 

checkID(ID) Verify ID

Parameter nameExplanationDefault value
IDID 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 nameExplanationDefault value
emailemail''

Example:

const flag = myPlugin.checkEmail('xxxx@gmail.com');
// Email format is correct
if (flag) {

} 
// Email format error
else {

}

isPhoneNum(phone) Verify phone number

Parameter nameExplanationDefault value
phoneMobile 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 nameDefault valueExplanationValue Description
platformunknownWhether it is mobile or pc.pc: pc mobile: mobile
screenTypeunknownPhone screen typeX: Full screen normal: Normal screen (iphone5, 6, 7) short: Smaller than normal screen
showTipsObjnullpopup objectDom object for showTips method
sysTemunknownclient systemios: ios system android: android system not moblie: Current non-mobile terminal
version''Plugin version number
0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago