UNPKG

@kitmi/utils

Version:

A JavaScript utility library for both server and browser

23 lines (18 loc) 498 B
import fileURLToPath from './fileURLToPath'; /** * Check if the current module is the main module. * @param {*} entryMetaUrl - import.meta.url of the entry module. * @returns {boolean} */ function esmIsMain(entryMetaUrl) { if (entryMetaUrl.startsWith('file:')) { // (A) const modulePath = fileURLToPath(entryMetaUrl); if (process.argv[1] === modulePath) { // (B) return true; } } return false; } export default esmIsMain;