@kreisler/js-helpers
A comprehensive collection of utility functions for common JavaScript tasks including text normalization, number formatting, base64 encoding, unit conversions, and WhatsApp markdown formatting.Installation
Re-exported Utilities
This package also re-exports:- All exports from
@kreisler/debounce - All exports from
@kreisler/createapi - All exports from
@kreisler/try-catch(asTCatchnamespace)
Functions
Number Utilities
abbreviateNumber
Abbreviates large numbers with suffixes (k, M, B, T).The number to abbreviate.
The abbreviated number as a string (e.g., “1.5k”, “2.3M”).
bytes2Kb
Converts bytes to kilobytes.Size in bytes.
Number of decimal places.
Size in KB as a string.
bytes2Mb
Converts bytes to megabytes.Size in bytes.
Number of decimal places.
Size in MB as a string.
bytes2Gb
Converts bytes to gigabytes.Size in bytes.
Number of decimal places.
Size in GB as a string.
Temperature & Speed Conversions (converters namespace)
kToF
Converts Kelvin to Fahrenheit.Temperature in Kelvin.
Number of decimal places.
Temperature in Fahrenheit.
kToC
Converts Kelvin to Celsius.Temperature in Kelvin.
Number of decimal places.
Temperature in Celsius.
msToMph
Converts meters per second to miles per hour.Speed in m/s.
Number of decimal places.
Speed in mph.
msToKmh
Converts meters per second to kilometers per hour.Speed in m/s.
Number of decimal places.
Speed in km/h.
Base64 Utilities (base64converters namespace)
utf8Tob64
Converts UTF-8 string to base64.UTF-8 encoded string.
Base64 encoded string.
b64Toutf8
Converts base64 to UTF-8 string.Base64 encoded string.
UTF-8 decoded string.
Text Processing
normalize
Normalizes strings by removing accents and special characters.String to normalize.
If
false, converts to URL-safe format (lowercase with dashes).Normalized string.
trimText
Removes excessive whitespace and empty lines.String to trim.
Cleaned string.
stripHtmlTags
Removes HTML tags from a string.String containing HTML.
Custom regex pattern for tag removal.
String without HTML tags.
levenshteinDistance
Calculates the Levenshtein distance between two strings.First string.
Second string.
Edit distance between the strings.
titleSimilarity
Calculates similarity between two titles (0-1 scale).First title.
Second title.
Similarity score (0 = completely different, 1 = identical). A threshold of 0.8 is recommended for matching.
Command Line Utilities
argv2Object
Converts command-line arguments to a key-value object.Array of command-line arguments.
Parse Unix-style arguments (
--key=value, -k value).Object with parsed key-value pairs.
WhatsApp Markdown (MarkdownWsp object)
Italic
Text to format.
Text wrapped in underscores:
_text_Bold
Text to format.
Text wrapped in asterisks:
*text*Strikethrough
Text to format.
Text wrapped in tildes:
~text~Monospace
Text to format.
Text wrapped in triple backticks:
```text```Quote
Text to format.
Text prefixed with
>: > textBulletedList
Text or array of strings to format.
Bullet character.
Formatted bulleted list.
NumberedLists
Text or array of strings to format.
Formatted numbered list.
InlineCode
Text to format.
Text wrapped in backticks:
`text`