Documentation v4.0.0

Overview

Check if a value is a string (including String object instances).

Import

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

Signature

isString(payload: any): boolean
Parameter Type Description
payload any The value to test.
Returns: booleantrue if string, false otherwise.

Example

ValueResult
<table class="table table-row-bordered" id="isStringDemo">
  <thead><tr class="fw-bold fs-6 text-gray-800"><th>Value</th><th>Result</th></tr></thead>
  <tbody></tbody>
</table>
var isString = metronicExtension.utils.isString;
var testCases = [
  {label: "'hello'", value: 'hello'},
  {label: "Object('a')", value: Object('a')},
  {label: "42", value: 42},
  {label: "true", value: true},
  {label: "null", value: null},
  {label: "undefined", value: undefined},
  {label: "[]", value: []},
  {label: "{}", value: {}},
  {label: "Symbol('a')", value: Symbol('a')},
];
var tbody = document.querySelector('#isStringDemo tbody');
testCases.forEach(function(tc) {
  var valid = isString(tc.value);
  var tr = document.createElement('tr');
  tr.innerHTML = '<td><code>' + tc.label + '</code></td>'
    + '<td><span class="badge ' + (valid ? 'badge-success' : 'badge-danger')
    + '">' + valid + '</span></td>';
  tbody.appendChild(tr);
});