0.0.3 • Published 2 years ago

utilibjs v0.0.3

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

utilibjs

My collection of most common used function in javascript. Most of them found in stackoverflow.

Table of Contents

Install

npm install utilibjs

API

BrowserFunctions

isSafari() ⇒ boolean

Check if the browser is Safari.

Kind: global function
Returns: boolean - true if the browser is Safari, false otherwise.

isChrome() ⇒ boolean

Check if the browser is Chrome.

Kind: global function
Returns: boolean - true if the browser is Chrome, false otherwise.

isOffline() ⇒ boolean

Check if the browser is currently offline.

Kind: global function
Returns: boolean - true if the browser is offline, false otherwise.

openInNewTab(url)

Open the given URL in a new tab.

Kind: global function

ParamTypeDescription
urlstringThe URL to open in a new tab.

triggerDownload(fileUrl, fileName, target)

Download the file at the given URL with the given filename and target.

Kind: global function

ParamTypeDefaultDescription
fileUrlstringThe URL of the file to download.
fileNamestring | nullnullThe name of the file to save as.
targetstring | nullnullThe target window or tab to open the file in.

downloadFile(file)

Download the given file by creating a download link and clicking it.

Kind: global function

ParamTypeDescription
fileFileThe file to download.

FileFunctions

getFileType(fileName) ⇒ string

Get file type based on the file name extension.

Kind: global function
Returns: string - The file type.

ParamTypeDescription
fileNamestringThe file name.

getRelativePath(path) ⇒ string

Get the relative path from a full path.

Kind: global function
Returns: string - The relative path.

ParamTypeDescription
pathstringThe full path.

renameFile(file, name) ⇒ File

Rename a file with a new name.

Kind: global function
Returns: File - A new File instance with the new name.

ParamTypeDescription
fileFileThe file to rename.
namestringThe new name to assign to the file.

getFileName(url) ⇒ string

Get the file name from a URL.

Kind: global function
Returns: string - The file name.

ParamTypeDescription
urlstringThe file URL.

convertMBToBytes(mb) ⇒ number

Convert megabytes to bytes.

Kind: global function
Returns: number - The size in bytes.

ParamTypeDescription
mbnumberThe size in megabytes.

convertKBToBytes(kb) ⇒ number

Convert kilobytes to bytes.

Kind: global function
Returns: number - The size in bytes.

ParamTypeDescription
kbnumberThe size in kilobytes.

removeFileExtension(fileName) ⇒ string

Remove the file extension from a file name.

Kind: global function
Returns: string - The file name without the extension.

ParamTypeDescription
fileNamestringThe file name.

KeyboardFunctions

isEnterKeyPressed(event) ⇒ boolean

Check if the Enter key is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Enter key is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

isSpacebarKeyPressed(event) ⇒ boolean

Check if the Spacebar key is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Spacebar key is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

isEscKeyPressed(event) ⇒ boolean

Check if the Escape key is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Escape key is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

isBackspaceKeyPressed(event) ⇒ boolean

Check if the Backspace key is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Backspace key is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

isTabKeyPressed(event) ⇒ boolean

Check if the Tab key is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Tab key is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

isShiftKeyPressed(event) ⇒ boolean

Check if the Shift key is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Shift key is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

isUndoKeyPressed(event) ⇒ boolean

Check if the Undo (Ctrl + Z) key combination is pressed in the keyboard event.

Kind: global function
Returns: boolean - - True if Undo key combination is pressed, false otherwise.

ParamTypeDescription
eventKeyboardEventThe keyboard event.

StringFunctions

isEmail(email) ⇒

Determines whether the input is a valid email address.

Kind: global function
Returns: true if the input is a valid email address, false otherwise.

ParamDescription
emailThe email address to check.

generateRandomString(length) ⇒

Generates a random string.

Kind: global function
Returns: A random string of the specified length.

ParamDescription
lengthThe length of the string to generate.

truncateStart(fullStr, strLen, separator) ⇒

Truncates a string from the beginning and adds a separator at the end.

Kind: global function
Returns: The truncated string with the separator at the end.

ParamDescription
fullStrThe string to truncate.
strLenThe maximum length of the truncated string.
separatorThe separator to add at the end of the truncated string. Default is "...".

truncateMiddle(fullStr, strLen, separator) ⇒

Truncates a string from both the beginning and the end and adds a separator in the middle.

Kind: global function
Returns: The truncated string with the separator in the middle.

ParamDescription
fullStrThe string to truncate.
strLenThe maximum length of the truncated string.
separatorThe separator to add in the middle of the truncated string. Default is "...".

truncateEmail(email, strLen, separator) ⇒

Truncates an email address and adds a separator in the middle.

Kind: global function
Returns: The truncated email address with the separator in the middle.

ParamDescription
emailThe email address to truncate.
strLenThe maximum length of the truncated email address.
separatorThe separator to add in the middle of the truncated email address. Default is "...".

toCapitalize(str) ⇒

Converts the first letter of each word in a string to uppercase.

Kind: global function
Returns: The input string with the first letter of each word in uppercase.

ParamDescription
strThe string to convert.

MISC

Happy coding!

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago