Description of the string utilities.
import { string } from '@webalternatif/js-core'Pads a string to a specified length with a specified string and padding type
strstringpad_lengthnumberpad_strstring? (optional, default' ')pad_typestring? (optional, default'left')
Returns string
Converts RGB values to a hexadecimal color string.
r(number | Array<number>) Either an array representing a RGB color (e.g. [255, 0, 0]) or the red component as a number (0-255).gnumber? The green component (0-255). Required ifris a number.bnumber? The blue component (0-255). Required ifris a number.
// Using separate RGB components
rgb2hex(255, 0, 0); // Returns 'FF0000'// Using an array of RGB components
rgb2hex([255, 0, 0]); // Returns 'FF0000'Returns string The hexadecimal color string (e.g., 'FF0000').
Converts a hexadecimal color to RGB values.
hexstring The hexadecimal value (e.g #FF0000)
Returns Array<number> The RGB color array (e.g [255, 0, 0]).
Parses a URL string into its components.
strstring The URL string to be parsed.
schemestring? The scheme (protocol) of the URL (e.g.,http,https).authoritystring? The authority part of the URL.userInfostring? The user information (e.g.,user:pass).userstring? The username from the user information.passstring? The password from the user information.hoststring? The host of the URL (e.g.,example.com).portstring? The port of the URL (e.g.,8080).relativestring? The relative URL.pathstring? The path of the URL (e.g.,/path/to/resource).directorystring? The directory of the URL path.filestring? The file name from the path, if applicable.querystring? The query string (e.g.,key=value&key2=value2).fragmentstring? The fragment (hash) of the URL (e.g.,#section).
Returns Object An object containing the parsed components of the URL.
Adds or updates one or more query parameters to a given URL.
urlstring The URL to which the parameters should be added.param(string | Object) The key of the parameter to add, or an object containing multiple key-value pairs to add.value(string | null) The value of the parameter to add. Ignored ifparamis an object. (optional, defaultnull)
Add a single parameter to a URL without a query string
addUrlParam('https://example.com', 'key', 'value');
// Returns: 'https://example.com?key=value'Add multiple parameters to a URL
addUrlParam('https://example.com', { key1: 'value1', key2: 'value2' });
// Returns: 'https://example.com?key1=value1&key2=value2'Returns string The updated URL with the new query parameters.
str
- See: https://stackoverflow.com/questions/7627000/javascript-convert-string-to-safe-class-name-for-css
str