fecmjs v2.1.2
fecmjs
Front end common method collection
English | 中文
Features
- 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
Modules
Date: some methods for Date wrappingDom: some methods forDomoperationsDevice: some methods for devicesFile: Wrapping some methods aroundFileFormat: some method wrappers for formattingObject: Wrapping some methods aroundobjectArray: Some method encapsulation onarrayStorage: Wrappers forStoragemethodsUrl: Some methods aroundUrlValidate: Wrapping some methods around validationAnimation: aboutcss,vueusable animations
Translated with DeepL.com (free version)
Usage
- use the
npmmethod
npm i fecmjs// 1. Use all modules
import * as Fecmjs from 'fecmjs';
const flag = Fecmjs.isEmail('limingcan562@163.com');
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('limingcan562@163.com');
console.log(flag); // true- Use
<script></script>to import
<script src="https://cdn.xxxx/fecmjs.min.js"></script>
<script>
var flag = fecmjs.checkEmail('limingcan562@163.com');
console.log(flag); // true
</script>Date
getCurrentTimestampGet current timestamp
Example:
import {getCurrentTimestamp} from 'femcjs'; console.log(getCurrentTimestamp()) // 1730129184412getDateByFewdaysDepending on the time of day, get the date a few days before or a few days after that time
parameter name description default value fewdaysThe number of days to the target day to be acquired 0timetarget time new Date().getTime()Note:
- When
fewdaysis a positive integer, get the next few days of the target date When
fewdaysis a negative integer, get the first few days of the target dateExample:
// 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
getDateByTimestampGet the time based on the incoming timestamp
parameter name description default value timestamptimestamp needHMSWhether you need to return hours, minutes and seconds falseExample:
import {getDateByTimestamp} from 'femcjs'; console.log(getDateByTimestamp('1730129184412')); // 2024-10-28 console.log(getDateByTimestamp('1730129184412', true)); // 2024-10-28 23:26:24getTimestampByDateGet timestamps based on specific dates
parameter name description default value timeSpecific date. The format is the same as that passed in by new Date()new Date().getTime()Note:
- 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 {getTimestampByDate} from 'femcjs'; console.log(getTimestampByDate()); // 1730131646512 console.log(getTimestampByDate('2024-10-29')); // 1730160000000 console.log(getTimestampByDate('2024-10-29 01:30')); // 1730136600000
Device
isAndroidIs it currently Android
isIosIs the current system ios
isIpadCurrently is not an ipad device
isIphoneCurrently not an iphone device
isMoblieIs it currently mobile
isPcIs it currently a pc
isWechatWhether the current environment is WeChat
Dom
$Returns the
Domobjectparameter name description default value selectNamecssselectorNote:
- 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
addClassAdds a class name to a
Domobject.parameter name description default value selectNamecssselector ordomobjectnameListThe name of the class to be added Note:
nameListcan be passed as an array when you want to add multiple class names.nameListcan be passed as a string if you want to add a single class name.Example:
import {addClass} from 'femcjs'; addClass('#dom', ['name1', 'name2', 'nam3']);
getClassGet the class name of a
Domobjectparameter name description default value selectNamecssselector ordomobjectNote:
Returns an array of the object's class names
removeClassRemove one or more class names from a
Domobject.parameter name description default value selectNamecssselector ordomobjectnameListClass name to be deleted Note:
nameListcan be passed as an array if you want to delete multiple class names.nameListcan be passed as a string if you want to delete a single class name.
setStyleSetting the style of a
Domobjectparameter name description default value selectNamecssselector ordomobjectstyleThe style to be set Note:
stylecan be passed as an object when you want to set multiple styles.stylecan 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
getDomInfoGet information about a
dom, or aNodeList.parameter name description default value selectNameA cssselector or adomobject, or a set ofNodeLists.Note:
If
selectNameis a set ofNodeLists, return an array of information consisting of theNodeLists.Example:
import {setStyle} from 'femcjs'; console.log(getDomInfo($('li'))); // [DOMRect, DOMRect]
isExceedParentHeightDetermine if a child element exceeds the height of the parent element
parameter name description default value parentSelectNameParent element class name selector or domobjectchildSelectNameChild element class name selector or domobjectNote:
The parent element has to set the height
isShowOnVisualAreaDetermine if an element appears in the visual area
parameter name description default value selectNameElement class name selector or domobjectsetPageNoScrollSetting the page not to scroll
restorePageScrollResume page scrolling
Format
formatFileSizeFormatting File Size
parameter name description default value filefile object {}Example:
import {formatFileSize} from 'femcjs'; console.log(formatFileSize(file)); // 1.37KBformatVideoDurationFormatted Video Duration
parameter name description default value totalSecondsvideo duration 0Example:
import {formatVideoDuration} from 'femcjs'; console.log(formatVideoDuration(3600)); // 01:00:00
File
getFileNameGet the name of the
fileuploadedparameter name description default value filefileobjectsgetFileSuffixGet the suffix of the uploaded
filefileparameter name description default value filefileobjectsgetFilePreviewSrcGet the address of the uploaded
filepreviewparameter name description default value filefileobjectsNote:
- Mainly used for previewing uploaded images
Note the use of the
revokeObjectURLmethod to reclaim memory.Example:
import {getFilePreviewSrc, $} from 'femcjs'; const previewSrc = getFilePreviewSrc(file); $('#preview_img').src = previewSrc;
isFileAudioTypeIs the uploaded file an audio type
parameter name description default value filefileobjectsisFilePicTypeIs the uploaded file an image type
parameter name description default value filefileobjectsisFileVideoTypeIs the uploaded file an video type
parameter name description default value filefileobjectsisContentSrtFormatIs the content format an srt file format
parameter name description default value textStrContents text
Object
emptyObjWhether the current object has no value
isArrWhether the current type is
arrayor notisDateWhether the current type is
Dateor notisFnWhether the current type is
functionor notisNullWhether the current is
nullor notisNumWhether the current type is
numberor notisObjWhether the current type is
Objector notisStrWhether the current type is
Stringor notisUndefinedWhether the current type is
Undefinedor notisHtmlObjWhether the current object is an
htmlDomobject.isNodeListWhether the current object is
NodeListor not.
Array
chunkArrBySizeReturns an array grouped according to a specified size.
parameter name | description | default value
------| ----| -----
`array`| array being manipulated |
`size`| Size to specify |
Example:
```javascript
import {chunkArrBySize} from 'femcjs';
const arr = [1, 2, 3, 4, 5, 6, 7, 8];
const SIZE = 3;
console.log(chunkArrBySize(arr, SIZE)); // [[1,2,3], [4,5,6], [7,8]]
```removeArrayItemDeleting an item in an array
parameter name description default value arrayarray being manipulated itemItems to be deleted newoneWhether to return a new array without changing the size of the original array falseNote:
itemcan only be of type string or numeric.- if
newone = false; changes the size of the original array if
newone = true; does not change the size of the original array, returns a new target arrayExample:
import {removeArrayItem} from 'femcjs'; const arr = [1, 2, 3, 4, 'hello', 'lee', 7, 8]; console.log(removeArrayItem(arr, 'hello', true)); // [1, 2, 3, 4, 'lee', 7, 8]; console.log(arr); // [1, 2, 3, 4, 'hello', 'lee', 7, 8];
Storage
getLocalStorageGetting a value from local storage
parameter name description default value keyThe key value to get
##### Note:
1. if the `key` value is an object, return the object corresponding to the `key` value directly
2. otherwise, return the string corresponding to the `key` value.
Example:
```javascript
// 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
```setLocalStorageSetting a LocalStorage value
parameter name description default value keyThe value of the keyto be setvalThe value corresponding to the keyto be setNote:
valcan be an object or a stringExample:
import {setLocalStorage} from 'femcjs'; setLocalStorage('info', {name: 'lee', age: 29}); // info -> {"name":"lee","age":29}removeLocalStorageDelete one or more locally stored values
parameter name description default value keyvalue of keyto be deletedNote:
- if
keyis an array, multiple correspondingkeyvalues can be removed - if
keyis a string, then a single value is removed
- if
Example:
```javascript
import {removeLocalStorage} from 'femcjs';
console.log(removeLocalStorage(['info', 'test'])); // The values of info,test will be deleted.
```clearLocalStorageClear Local Storage
Example:
import {clearLocalStorage} from 'femcjs'; clearLocalStorage();
validate
containCNDoes it contain Chinese
parameter name description default value textStrContents text Note:
Returns
truewhenever there is a Chinese character.containENDoes it contain English
parameter name description default value textStrContents text Note:
Returns
truewhenever there is English.containCNSpecialCharWhether to include Chinese special characters
parameter name description default value textStrContents text Note:
Returns
truewhenever there are Chinese special characters.
containENSpecialCharWhether to include English special characters
parameter name description default value textStrContents text Note:
Returns
truewhenever there is an English special character.isAllCNIs it all in Chinese?
parameter name description default value textStrContents text Note:
Is it in pure Chinese (Contains Chinese special characters and numbers; Excluding English and special English characters)
isAllENIs it all in English?
parameter name description default value textStrContents text Note:
Is it in pure English (Contains English special characters and numbers; Excluding English and special English characters)
isEmailIs it a mail format?
parameter name description default value emailemail isPhoneNumIs it a cell phone number format
parameter name description default value phoneNumbermobile telephone number Note:
Verify Mainland China Cell Phone Number
isIntlPhoneIs it an international cell phone number format
parameter name description default value phoneNumberinternational cell phone number
Url
getUrlValueGet the value of the
urlparameterparameter name description default value keyThe key of the value to get ''urlThe urllink to getwindow.location.hrefNote:
- When
keyis empty, an object consisting of the values of all the arguments ofurlis returned. When
keyis a value, the value ofurlaskeyis 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
setUrlWithNorefreshSetting the url and not refreshing the page
parameter name description default value keyValue to be set {}Example:
import {setUrlWithNorefresh} from 'femcjs'; console.log(setUrlWithNorefresh({name: 'lmc', age: 29}); // http://localhost:5501/test/?name=lmc&age=29
Animation
vueanimationSupported animations are
fade-in: fade-infade-right-to-left: fade in from right to leftfade-top-to-bottom: fade in from top to bottomfade-zoom-in: zoom in
Example:
```html
<Transition name="fade-right-to-left">
<components v-if="show" />
</Transition>
```cssanimationNote:
See
dist/styles/css-ani.cssfor details.Example:
<!-- The element will be delayed 500ms to 750ms for a cyclic blinking animation --> <div class="shine time750 delay500"></div>
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago