My collection of most common used function in javascript. Most of them found in stackoverflow.
npm install utilibjs- Install
- API
* BrowserFunctions
* isSafari() ⇒ boolean
* isChrome() ⇒ boolean
* isOffline() ⇒ boolean
* openInNewTab(url)
* [triggerDownload(fileUrl, [fileName], [target])](#triggerdownloadfileurl-filename-target)
* downloadFile(file)
* FileFunctions
* getFileType(fileName) ⇒ string
* getRelativePath(path) ⇒ string
* renameFile(file, name) ⇒ File
* getFileName(url) ⇒ string
* convertMBToBytes(mb) ⇒ number
* convertKBToBytes(kb) ⇒ number
* removeFileExtension(fileName) ⇒ string
* KeyboardFunctions
* isEnterKeyPressed(event) ⇒ boolean
* isSpacebarKeyPressed(event) ⇒ boolean
* isEscKeyPressed(event) ⇒ boolean
* isBackspaceKeyPressed(event) ⇒ boolean
* isTabKeyPressed(event) ⇒ boolean
* isShiftKeyPressed(event) ⇒ boolean
* isUndoKeyPressed(event) ⇒ boolean
* StringFunctions
* isEmail(email) ⇒
* generateRandomString(length) ⇒
* truncateStart(fullStr, strLen, separator) ⇒
* truncateMiddle(fullStr, strLen, separator) ⇒
* truncateEmail(email, strLen, separator) ⇒
* toCapitalize(str) ⇒
- MISC
npm install utilibjs
booleanCheck if the browser is Safari.
booleanCheck if the browser is Chrome.
booleanCheck if the browser is currently offline.
Open the given URL in a new tab.
Download the file at the given URL with the given filename and target.
Download the given file by creating a download link and clicking it.
Kind: global function
Returns: boolean - true if the browser is Safari, false otherwise.
Kind: global function
Returns: boolean - true if the browser is Chrome, false otherwise.
Kind: global function
Returns: boolean - true if the browser is offline, false otherwise.
Kind: global function
| Param | Type | Description |
| --- | --- | --- |
| url | string | The URL to open in a new tab. |
Kind: global function
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| fileUrl | string | | The URL of the file to download. |
| [fileName] | string \| null | null | The name of the file to save as. |
| [target] | string \| null | null | The target window or tab to open the file in. |
Kind: global function
| Param | Type | Description |
| --- | --- | --- |
| file | File | The file to download. |
stringGet file type based on the file name extension.
stringGet the relative path from a full path.
FileRename a file with a new name.
stringGet the file name from a URL.
numberConvert megabytes to bytes.
numberConvert kilobytes to bytes.
stringRemove the file extension from a file name.
Kind: global function
Returns: string - The file type.
| Param | Type | Description |
| --- | --- | --- |
| fileName | string | The file name. |
Kind: global function
Returns: string - The relative path.
| Param | Type | Description |
| --- | --- | --- |
| path | string | The full path. |
Kind: global function
Returns: File - A new File instance with the new name.
| Param | Type | Description |
| --- | --- | --- |
| file | File | The file to rename. |
| name | string | The new name to assign to the file. |
Kind: global function
Returns: string - The file name.
| Param | Type | Description |
| --- | --- | --- |
| url | string | The file URL. |
Kind: global function
Returns: number - The size in bytes.
| Param | Type | Description |
| --- | --- | --- |
| mb | number | The size in megabytes. |
Kind: global function
Returns: number - The size in bytes.
| Param | Type | Description |
| --- | --- | --- |
| kb | number | The size in kilobytes. |
Kind: global function
Returns: string - The file name without the extension.
| Param | Type | Description |
| --- | --- | --- |
| fileName | string | The file name. |
booleanCheck if the Enter key is pressed in the keyboard event.
booleanCheck if the Spacebar key is pressed in the keyboard event.
booleanCheck if the Escape key is pressed in the keyboard event.
booleanCheck if the Backspace key is pressed in the keyboard event.
booleanCheck if the Tab key is pressed in the keyboard event.
booleanCheck if the Shift key is pressed in the keyboard event.
booleanCheck if the Undo (Ctrl + Z) key combination is pressed in the keyboard event.
Kind: global function
Returns: boolean - - True if Enter key is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Kind: global function
Returns: boolean - - True if Spacebar key is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Kind: global function
Returns: boolean - - True if Escape key is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Kind: global function
Returns: boolean - - True if Backspace key is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Kind: global function
Returns: boolean - - True if Tab key is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Kind: global function
Returns: boolean - - True if Shift key is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Kind: global function
Returns: boolean - - True if Undo key combination is pressed, false otherwise.
| Param | Type | Description |
| --- | --- | --- |
| event | KeyboardEvent | The keyboard event. |
Determines whether the input is a valid email address.
Generates a random string.
Truncates a string from the beginning and adds a separator at the end.
Truncates a string from both the beginning and the end and adds a separator in the middle.
Truncates an email address and adds a separator in the middle.
Converts the first letter of each word in a string to uppercase.
Kind: global function
Returns: true if the input is a valid email address, false otherwise.
| Param | Description |
| --- | --- |
| email | The email address to check. |
Kind: global function
Returns: A random string of the specified length.
| Param | Description |
| --- | --- |
| length | The length of the string to generate. |
Kind: global function
Returns: The truncated string with the separator at the end.
| Param | Description |
| --- | --- |
| fullStr | The string to truncate. |
| strLen | The maximum length of the truncated string. |
| separator | The separator to add at the end of the truncated string. Default is "...". |
Kind: global function
Returns: The truncated string with the separator in the middle.
| Param | Description |
| --- | --- |
| fullStr | The string to truncate. |
| strLen | The maximum length of the truncated string. |
| separator | The separator to add in the middle of the truncated string. Default is "...". |
Kind: global function
Returns: The truncated email address with the separator in the middle.
| Param | Description |
| --- | --- |
| email | The email address to truncate. |
| strLen | The maximum length of the truncated email address. |
| separator | The separator to add in the middle of the truncated email address. Default is "...". |
Kind: global function
Returns: The input string with the first letter of each word in uppercase.
| Param | Description |
| --- | --- |
| str | The string to convert. |