Front end common method collection
English | 中文
- Front-end commonly used methods collection collection , to facilitate the usual development ( part of the method from the Internet )
- Modular development, easy to reference
- support
tree shaking
, in order to reduce the size of the package
Date
: some methods for Date wrappingDom
: some methods forDom
operationsDevice
: some methods for devicesFile
: Wrapping some methods aroundFile
Format
: some method wrappers for formattingObject
: Wrapping some methods aroundobject
Storage
: Wrappers forStorage
methodsUrl
: Some methods aroundUrl
Validate
: Wrapping some methods around validation
Translated with DeepL.com (free version)
- use the
npm
method
npm i fecmjs
// 1. Use all modules
import * as Fecmjs from 'fecmjs';
const flag = Fecmjs.isEmail('[email protected]');
console.log(flag); // true
// 2. When you only need to use some functions, you can import some modules (recommended)
import {isEmail} from 'fecmjs';
const flag = isEmail('[email protected]');
console.log(flag); // true
- Use
<script></script>
to import
<script src="https://cdn.xxxx/fecmjs.min.js"></script>
<script>
var flag = fecmjs.checkEmail('[email protected]');
console.log(flag); // true
</script>
-
Example:
import {getCurrentTimestamp} from 'femcjs'; console.log(getCurrentTimestamp()) // 1730129184412
-
parameter name description default value fewdays
The number of days to the target day to be acquired 0
time
target time new Date().getTime()
- When
fewdays
is a positive integer, get the next few days of the target date - When
fewdays
is a negative integer, get the first few days of the target date
Example:
// Get the first 30 days of 2024-10-28 import {getCurrentTimestamp} from 'femcjs'; console.log(-30, '2024-10-28'); // 2024-09-28 // Get the last 30 days of 2024-10-28 console.log(30, '2024-10-28'); // 2024-11-27
- When
-
parameter name description default value timestamp
timestamp needHMS
Whether you need to return hours, minutes and seconds false
Example:
import {getDateByTimestamp} from 'femcjs'; console.log(fecmjs.getDateByTimestamp('1730129184412')); // 2024-10-28 console.log(fecmjs.getDateByTimestamp('1730129184412', true)); // 2024-10-28 23:26:24
-
- Returns the timestamp of the current time by default
- The form of the input parameter is the same as the
new Date()
method.
Example:
import {getTimestamp} from 'femcjs'; console.log(getTimestamp()); // 1730131646512 console.log(getTimestamp('2024-10-29')); // 1730160000000 console.log(getTimestamp('2024-10-29 01:30')); // 1730136600000
-
parameter name description default value selectName
css
selector- if there is more than one
Dom
, then return an array - if there is only one
Dom
, return a singleDom
.
- if there is more than one
-
parameter name description default value selectName
css
selector ordom
objectnameList
The name of the class to be added nameList
can be passed as an array when you want to add multiple class names.nameList
can be passed as a string if you want to add a single class name.
Example:
import {addClass} from 'femcjs'; addClass('#dom', ['name1', 'name2', 'nam3']);
-
parameter name description default value selectName
css
selector ordom
objectReturns an array of the object's class names
-
parameter name description default value selectName
css
selector ordom
objectnameList
Class name to be deleted nameList
can be passed as an array if you want to delete multiple class names.nameList
can be passed as a string if you want to delete a single class name.
-
parameter name description default value selectName
css
selector ordom
objectstyle
The style to be set style
can be passed as an object when you want to set multiple styles.style
can be passed as a string when you want to set a single style.
Example:
import {setStyle} from 'femcjs'; setStyle('#dom', {color: 'red', backgroundColor: '#000'}); // set multiple styles setStyle('#dom', 'color: red'); // set a single style
-
parameter name description default value parentSelectName
Parent element class name selector or dom
objectchildSelectName
Child element class name selector or dom
objectThe parent element has to set the height
-
parameter name description default value selectName
Element class name selector or dom
object -
-
-
parameter name description default value file
file object {}
Example:
import {formatFileSize} from 'femcjs'; console.log(formatFileSize(file)); // 1.37KB
-
parameter name description default value totalSeconds
video duration 0
Example:
import {formatVideoDuration} from 'femcjs'; console.log(formatVideoDuration(3600)); // 01:00:00
-
parameter name description default value file
file
objects -
parameter name description default value file
file
objects -
parameter name description default value file
file
objects- Mainly used for previewing uploaded images
- Note the use of the
revokeObjectURL
method to reclaim memory.
Example:
import {getFilePreviewSrc, $} from 'femcjs'; const previewSrc = getFilePreviewSrc(file); $('#preview_img').src = previewSrc;
-
parameter name description default value file
file
objects -
parameter name description default value file
file
objects -
parameter name description default value file
file
objects -
parameter name description default value textStr
Contents text
-
parameter name description default value key
The key value to get - if the
key
value is an object, return the object corresponding to thekey
value directly - otherwise, return the string corresponding to the
key
value.
Example:
// If localStorage stores info: {“name”: “lee”, “age”:29}, name: test import {getLocalStorage} from 'femcjs'; console.log(getLocalStorage(info)); // {name: lee, age} objects console.log(getLocalStorage(name)); // test string
- if the
-
parameter name description default value key
The value of the key
to be setval
The value corresponding to the key
to be setval
can be an object or a stringExample:
import {setLocalStorage} from 'femcjs'; setLocalStorage('info', {name: 'lee', age: 29}); // info -> {"name":"lee","age":29}
-
parameter name description default value key
value of key
to be deleted- if
key
is an array, multiple correspondingkey
values can be removed - if
key
is a string, then a single value is removed
Example:
import {removeLocalStorage} from 'femcjs'; console.log(removeLocalStorage(['info', 'test'])); // The values of info,test will be deleted.
- if
-
Example:
import {clearLocalStorage} from 'femcjs'; clearLocalStorage();
-
parameter name description default value textStr
Contents text Returns
true
whenever there is a Chinese character. -
parameter name description default value textStr
Contents text Returns
true
whenever there is English.parameter name description default value textStr
Contents text Returns
true
whenever there are Chinese special characters. -
parameter name description default value textStr
Contents text Returns
true
whenever there is an English special character. -
parameter name description default value textStr
Contents text Is it in pure Chinese (Contains Chinese special characters and numbers; Excluding English and special English characters)
-
parameter name description default value textStr
Contents text Is it in pure English (Contains English special characters and numbers; Excluding English and special English characters)
-
parameter name description default value email
email -
parameter name description default value phoneNumber
mobile telephone number Verify Mainland China Cell Phone Number
-
parameter name description default value phoneNumber
international cell phone number
-
parameter name description default value key
The key of the value to get ''
url
The url
link to getwindow.location.href
- When
key
is empty, an object consisting of the values of all the arguments ofurl
is returned. - When
key
is a value, the value ofurl
askey
is returned.
Example:
import {getUrlValue} from 'femcjs'; const url = 'http://localhost:5501/test/?name=lee&age=29' console.log(getUrlValue('', url)); // {name: 'lmc', age: 29} console.log(getUrlValue('name', url)); // 'lmc'
- When
-
parameter name description default value key
Value to be set {}
Example:
import {setUrlWithNorefresh} from 'femcjs'; console.log(setUrlWithNorefresh({name: 'lmc', age: 29}); // http://localhost:5501/test/?name=lmc&age=29