2.0.4 • Published 10 months ago
@dpsys/js-utils v2.0.4
Javascript Utilities
Handy functions for JS development.
Supports CJS, ESM and TypeScript.
Installation
npm i @dpsys/js-utils Example Usage
import { cLog } from '@dpsys/js-utils/misc';
let myVar = 'Hello World';
cLog('myVar', myVar);List of Functions
Array
arrayMoveItem(arr, fromIndex, toIndex): Moves an item within an array from one index to another, returning the modified array.
File
blobToBase64(blob): Converts a Blob/File to base64 stringdownloadStream(data, headers): Downloads data stream with proper filename from content-dispositionprint(data, dataType, mimeType): Invokes system print dialog ready to print provided data (base64 or blob)fileExists(url): Checks if file exists at given URL
Function
debounce(callback, delayMs): Delay function execution
Is
isStrictMode(): Detects if code is running in strict modeisEmpty(val): Checks if array/string/object is emptyisArrayStringEmpty(arr): Checks if array or string is emptyisObjectEmpty(obj): Checks if object is emptyisIterable(val): Checks if variable is iterableisString(val): Checks if variable is stringisTouchDevice(): Detects if device has touch capabilities
Misc
emToPx(ems): Converts em units to pixelspxToEm(px): Converts pixels to em unitscLog(valueDescription, value, fn): Enhanced console.log with function name supportcErr(valueDescription, value, fn): Enhanced console.error with function name supportredirect(url, afterMs): Redirects to URL after specified millisecondspause(ms): Creates a promise that resolves after specified millisecondsgetTimestamp(format): Gets current timestamp in seconds or milliseconds
String
stringTruncate(str, length, ellipsis): Truncates string to specified length with ellipsisstringToBool(str): Converts string to boolean
Form
setDisabledStateChildInputs(parent, state): Sets disabled state for all form inputs within parent elementgetFileNames(fileInp): Gets array of file names from file input element
Element
getOffset(el): Gets element's offset relative to documentelCreate(tagName, attrs, innerHTML): Creates HTML element with attributes and inner HTMLisOverflown(el, heightTolerance, widthTolerance): Checks if element content is overflowingisScrollableX(el): Checks if element is scrollable horizontallyisScrollableY(el): Checks if element is scrollable verticallyisScrollableXY(el): Checks if element is scrollable horizontally and verticallygetPositionAmongSiblings(element): Gets element's position among its siblingshtmlToElements(html, elementNodesOnly): Converts HTML string to elements/nodesinsertNodes(nodes, referenceElement, after): Inserts nodes (or nodes created from provided string) before/after the reference elementswitchElements(element1, element2): Swaps positions of two DOM elements
1.0.19
1 year ago
1.1.0
1 year ago
1.0.18
1 year ago
1.0.17
1 year ago
1.0.16
1 year ago
2.0.3
1 year ago
2.0.2
1 year ago
2.0.4
10 months ago
2.0.1
1 year ago
2.0.0
1 year ago
1.0.15
1 year ago
1.0.14
1 year ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago