@cc-heart/utils
Version:
🔧 javascript common tools collection
40 lines (37 loc) • 1.09 kB
JavaScript
;
/**
* This function does nothing.
*
* @return {void} No return value.
*/
const noop = () => {
/** */
};
/**
* @description Add the number of cuts based on the original split and return all subsets after the cut
* @param str need to split of primitive string
* @param splitStr split params
* @param num split limit
* @returns a new split array, length is num + 1
*/
function mulSplit(str, splitStr, num = -1) {
const splitList = str.split(splitStr, num);
if (num === -1)
return splitList;
const originStr = splitList.join(splitStr);
if (originStr === str)
return splitList;
const endStr = str.slice(originStr.length + 1);
splitList.push(endStr);
return splitList;
}
/**
* Sleeps for a given delay.
*
* @param {number} delay - The delay, in milliseconds.
* @return {Promise<void>} A promise that resolves after the delay.
*/
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
exports.mulSplit = mulSplit;
exports.noop = noop;
exports.sleep = sleep;