Documentation v4.0.0

Overview

Trim whitespace (including full-width spaces) from both ends of a string. Optionally converts to lowercase.

Import

import {utils} from 'metronic-extension';
const {trim} = utils;

Signature

trim(str: string | null | undefined, toLower?: boolean): string | null | undefined
Parameter Type Default Description
str string | null | undefined - String to trim.
toLower boolean false If true, converts the trimmed string to lowercase.
Returns: string | null | undefined — Trimmed string, or null/undefined if input is null/undefined.

Example

Result: foo bar
<div class="mb-3">
  <label class="form-label">Input value</label>
  <input id="trimInput" class="form-control form-control-solid" value="  foo bar  ">
</div>
<div>
  <span class="fw-bold">Result: </span>
  <code id="trimResult">foo bar</code>
</div>
var trim = metronicExtension.utils.trim;
var input = document.getElementById('trimInput');
var result = document.getElementById('trimResult');

function update() {
  result.textContent = trim(input.value) || '(empty)';
}

input.addEventListener('input', update);
update();