UNPKG

@kitmi/utils

Version:

A JavaScript utility library for both server and browser

20 lines (16 loc) 491 B
/** * Get basename with or without path. * @param {string} str - Path * @param {boolean} includePath - Include path in the result. * @returns {string} */ const baseName = (str, includePath) => { const pos = str.lastIndexOf('.'); let pathname = pos === -1 ? str : str.substring(0, pos); if (includePath) { return pathname; } pathname = pathname.replace(/\\/g, '/'); return pathname.substring(pathname.lastIndexOf('/') + 1); }; export default baseName;