UNPKG

@cc-heart/utils

Version:

🔧 javascript common tools collection

36 lines (34 loc) • 1.03 kB
/** * 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)); export { mulSplit, noop, sleep };