Overview
Check if a value is a (synchronous) function. Returns false for async functions.
Import
import {utils} from 'metronic-extension';
const {isFn} = utils;
Signature
isFn(payload: any): boolean
| Parameter |
Type |
Description |
payload |
any |
The value to test. |
Returns: boolean — true for functions, false otherwise.
Example
<table class="table table-row-bordered" id="isFnDemo">
<thead><tr class="fw-bold fs-6 text-gray-800"><th>Value</th><th>Result</th></tr></thead>
<tbody></tbody>
</table>
var isFn = metronicExtension.utils.isFn;
var testCases = [
{label: "function(){}", value: function(){}},
{label: "async function(){}", value: async function(){}},
{label: "42", value: 42},
{label: "'string'", value: 'string'},
{label: "true", value: true},
{label: "null", value: null},
{label: "{}", value: {}},
{label: "[]", value: []},
];
var tbody = document.querySelector('#isFnDemo tbody');
testCases.forEach(function(tc) {
var valid = isFn(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);
});