fecmjs
v2.1.1
Published
Collection of common front-end methods to facilitate normal development. Applicable to mobile terminal (some methods come from the Internet).Modular development for easy reference.Support 'tree shaking' to reduce packing volume
Downloads
553
Maintainers
Readme
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 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 validationAnimation
: aboutcss
,vue
usable animations
Translated with DeepL.com (free version)
Usage
- 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>
Date
getCurrentTimestamp
Get current timestamp
Example:
import {getCurrentTimestamp} from 'femcjs'; console.log(getCurrentTimestamp()) // 1730129184412
getDateByFewdays
Depending on the time of day, get the date a few days before or a few days after that time
parameter name | description | default value ------| ----| -----
fewdays
| The number of days to the target day to be acquired |0
time
| target time |new Date().getTime()
Note:
- 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
getDateByTimestamp
Get the time based on the incoming timestamp
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(getDateByTimestamp('1730129184412')); // 2024-10-28 console.log(getDateByTimestamp('1730129184412', true)); // 2024-10-28 23:26:24
getTimestamp
Get timestamp
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 {getTimestamp} from 'femcjs'; console.log(getTimestamp()); // 1730131646512 console.log(getTimestamp('2024-10-29')); // 1730160000000 console.log(getTimestamp('2024-10-29 01:30')); // 1730136600000
Device
isAndroid
Is it currently Android
isIos
Is the current system ios
isIpad
Currently is not an ipad device
isIphone
Currently not an iphone device
isMoblie
Is it currently mobile
isPc
Is it currently a pc
isWechat
Whether the current environment is WeChat
Dom
$
Returns the
Dom
objectparameter name | description | default value ------| ----| -----
selectName
|css
selector |Note:
if there is more than one
Dom
, then return an arrayif there is only one
Dom
, return a singleDom
.
addClass
Adds a class name to a
Dom
object.parameter name | description | default value ------| ----| -----
selectName
|css
selector ordom
object |nameList
| The name of the class to be added |Note:
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']);
getClass
Get the class name of a
Dom
objectparameter name | description | default value ------| ----| -----
selectName
|css
selector ordom
object |Note:
Returns an array of the object's class names
removeClass
Remove one or more class names from a
Dom
object.parameter name | description | default value ------| ----| -----
selectName
|css
selector ordom
object |nameList
| Class name to be deleted |Note:
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.
setStyle
Setting the style of a
Dom
objectparameter name | description | default value ------| ----| -----
selectName
|css
selector ordom
object |style
| The style to be set |Note:
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
getDomInfo
Get information about a
dom
, or aNodeList
.parameter name | description | default value ------| ----| -----
selectName
| Acss
selector or adom
object, or a set ofNodeList
s.Note:
- If
selectName
is a set ofNodeList
s, return an array of information consisting of theNodeList
s.
Example:
import {setStyle} from 'femcjs'; console.log(getDomInfo($('li'))); // [DOMRect, DOMRect]
- If
isExceedParentHeight
Determine if a child element exceeds the height of the parent element
parameter name | description | default value ------| ----| -----
parentSelectName
| Parent element class name selector ordom
object |childSelectName
| Child element class name selector ordom
object |Note:
The parent element has to set the height
isShowOnVisualArea
Determine if an element appears in the visual area
parameter name | description | default value ------| ----| -----
selectName
| Element class name selector ordom
object |setPageNoScroll
Setting the page not to scroll
restorePageScroll
Resume page scrolling
Format
formatFileSize
Formatting File Size
parameter name | description | default value ------| ----| -----
file
| file object |{}
Example:
import {formatFileSize} from 'femcjs'; console.log(formatFileSize(file)); // 1.37KB
formatVideoDuration
Formatted Video Duration
parameter name | description | default value ------| ----| -----
totalSeconds
| video duration |0
Example:
import {formatVideoDuration} from 'femcjs'; console.log(formatVideoDuration(3600)); // 01:00:00
File
getFileName
Get the name of the
file
uploadedparameter name | description | default value ------| ----| -----
file
|file
objects |getFileSuffix
Get the suffix of the uploaded
file
fileparameter name | description | default value ------| ----| -----
file
|file
objects |getFilePreviewSrc
Get the address of the uploaded
file
previewparameter name | description | default value ------| ----| -----
file
|file
objects |Note:
- 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;
isFileAudioType
Is the uploaded file an audio type
parameter name | description | default value ------| ----| -----
file
|file
objects |isFilePicType
Is the uploaded file an image type
parameter name | description | default value ------| ----| -----
file
|file
objects |isFileVideoType
Is the uploaded file an video type
parameter name | description | default value ------| ----| -----
file
|file
objects |isContentSrtFormat
Is the content format an srt file format
parameter name | description | default value ------| ----| -----
textStr
| Contents text |
Object
emptyObj
Whether the current object has no value
isArr
Whether the current type is
array
or notisDate
Whether the current type is
Date
or notisFn
Whether the current type is
function
or notisNull
Whether the current is
null
or notisNum
Whether the current type is
number
or notisObj
Whether the current type is
Object
or notisStr
Whether the current type is
String
or notisUndefined
Whether the current type is
Undefined
or notisHtmlObj
Whether the current object is an
htmlDom
object.isNodeList
Whether the current object is
NodeList
or not.
Storage
getLocalStorage
Getting a value from local storage
parameter name | description | default value ------| ----| -----
key
| The key value to get |Note:
- 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
setLocalStorage
Setting a LocalStorage value
parameter name | description | default value ------| ----| -----
key
| The value of thekey
to be set |val
| The value corresponding to thekey
to be set |Note:
val
can be an object or a stringExample:
import {setLocalStorage} from 'femcjs'; setLocalStorage('info', {name: 'lee', age: 29}); // info -> {"name":"lee","age":29}
removeLocalStorage
Delete one or more locally stored values
parameter name | description | default value ------| ----| -----
key
| value ofkey
to be deleted |Note:
- 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
clearLocalStorage
Clear Local Storage
Example:
import {clearLocalStorage} from 'femcjs'; clearLocalStorage();
validate
containCN
Does it contain Chinese
parameter name | description | default value ------| ----| -----
textStr
| Contents text |Note:
Returns
true
whenever there is a Chinese character.containEN
Does it contain English
parameter name | description | default value ------| ----| -----
textStr
| Contents text |Note:
Returns
true
whenever there is English.containCNSpecialChar
Whether to include Chinese special characters
parameter name | description | default value ------| ----| -----
textStr
| Contents text |Note:
Returns
true
whenever there are Chinese special characters.containENSpecialChar
Whether to include English special characters
parameter name | description | default value ------| ----| -----
textStr
| Contents text |Note:
Returns
true
whenever there is an English special character.isAllCN
Is it all in Chinese?
parameter name | description | default value ------| ----| -----
textStr
| Contents text |Note:
Is it in pure Chinese (Contains Chinese special characters and numbers; Excluding English and special English characters)
isAllEN
Is it all in English?
parameter name | description | default value ------| ----| -----
textStr
| Contents text |Note:
Is it in pure English (Contains English special characters and numbers; Excluding English and special English characters)
isEmail
Is it a mail format?
parameter name | description | default value ------| ----| -----
email
| email |isPhoneNum
Is it a cell phone number format
parameter name | description | default value ------| ----| -----
phoneNumber
| mobile telephone number |Note:
Verify Mainland China Cell Phone Number
isIntlPhone
Is it an international cell phone number format
parameter name | description | default value ------| ----| -----
phoneNumber
| international cell phone number |
Url
getUrlValue
Get the value of the
url
parameterparameter name | description | default value ------| ----| -----
key
| The key of the value to get |''
url
| Theurl
link to get |window.location.href
Note:
- 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
setUrlWithNorefresh
Setting the url and not refreshing the page
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
Animation
vue
animationSupported 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:
<Transition name="fade-right-to-left"> <components v-if="show" /> </Transition>
css
animationNote:
See
dist/styles/css-ani.css
for details.Example:
<!-- The element will be delayed 500ms to 750ms for a cyclic blinking animation --> <div class="shine time750 delay500"></div>