mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add more specfic string and url checkers
This commit is contained in:
parent
d49364ae90
commit
e333fe7959
1 changed files with 24 additions and 0 deletions
|
|
@ -4,6 +4,19 @@ export function isString( maybeString ) {
|
||||||
return (typeof maybeString === 'string' || maybeString instanceof String)
|
return (typeof maybeString === 'string' || maybeString instanceof String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNonEmptyString ( maybeString ) {
|
||||||
|
if ( !isString( maybeString ) ) return false
|
||||||
|
|
||||||
|
return maybeString.length > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isPositiveNumberString ( maybeNumber ) {
|
||||||
|
if ( !isString( maybeNumber ) ) return false
|
||||||
|
|
||||||
|
return /\d+$/.test( maybeNumber )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function isValidHttpUrl( maybeUrl, allowUnsecure = false ) {
|
export function isValidHttpUrl( maybeUrl, allowUnsecure = false ) {
|
||||||
if ( !isString( maybeUrl ) ) return false
|
if ( !isString( maybeUrl ) ) return false
|
||||||
|
|
||||||
|
|
@ -22,6 +35,17 @@ export function isValidHttpUrl( maybeUrl, allowUnsecure = false ) {
|
||||||
return url.protocol === "https:"
|
return url.protocol === "https:"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isValidImageUrl ( maybeUrl ) {
|
||||||
|
if ( !isValidHttpUrl( maybeUrl ) ) return false
|
||||||
|
|
||||||
|
// Check if url has a file extension
|
||||||
|
const url = new URL(maybeUrl)
|
||||||
|
const fileExtension = url.pathname.split('.').pop()
|
||||||
|
|
||||||
|
return isNonEmptyString( fileExtension )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function isObject( maybeObject ) {
|
export function isObject( maybeObject ) {
|
||||||
return maybeObject === Object( maybeObject )
|
return maybeObject === Object( maybeObject )
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue