Some hand-crafted ES6 based JavaScript (type guarded - TypeScript based) utility functions:
-
Convert blob to base64 string
canvasToBlob( canvas: HTMLCanvasElement, options: Options = {})
-
Convert blob to base64 string
blobToBase64(blob: Blob)
-
String utils
isValidLength(str: string, minLength: number) isValidEmail(email: string) removeFileExtension(filename: string)
-
Split Array into Chunks
chunkify(kvArray = [], chunkSize = 10, reverse = false): Array<[]>
-
Split Array into Chunks - V2
chunkify(kvArray = [], chunkSize = 10): Array<[]>
-
Split Array into Chunks - V3
chunkify(kvArray: T[], chunkSize: number): Array<T[]>
-
Check number
isDecimalNumber(number: any): boolean isFloat(value: any): boolean
-
Convert text to Titled-Case
toTitleCase(text: string, delimiter = ' '): string
e.g. toTitleCase("mUdAssaAr lOves OpEn SouRCe") ===========> Mudassar Loves Open Source
-
Prettify Number
Description: Prettify a number for use in the application. Use toLocaleString, but also force a standard number of decimal places if it's a float.
prettifyNumber(number): string
-
Random Color Code Generator
randomColorGenerator(): string
-
Bump Array Sort Description: Return a new sorted array, except with one value bumped to the front. This function does not sort an array in place; a new array is returned.
bumpSort(kvArray: Array, bumpValue: any): Array
-
Sort Year Months
sortYearMonths(kvSet: Set<string>): Array sortYearMonths(kvArray: Array<string>): Array
-
Array Utils
isEqual(array1: Array<any>, array2: Array<any>): boolean takeRight(array: Array<any>, n: number): Array<any>
-
Format File Size
formatFileSize(bytes: number, suffixIndex = 0): string
-
Kebab Case to Title Case
kebabToTitleCase(str: string): string
Contributions of any kind are welcome.