UNPKG

@juzi/wechaty-puppet-whatsapp

Version:
38 lines 1.25 kB
import { HISTORY_MESSAGES_DAYS } from '../config.js'; const InviteLinkRegex = /^(https?:\/\/)?chat\.whatsapp\.com\/(?:invite\/)?([a-zA-Z0-9_-]{22})$/; export const sleep = async (milliseconds) => { if (milliseconds) { await new Promise(resolve => setTimeout(resolve, milliseconds)); } }; export const isRoomId = (id) => { return /@g.us$/i.test(id); }; export const isContactId = (id) => { return /@c.us$/i.test(id); }; export const isInviteLink = (link) => { return InviteLinkRegex.test(link); }; export const getInviteCode = (link) => { const matched = link.match(InviteLinkRegex); if (matched) { if (matched.length === 3) { const inviteCode = matched[2]; return inviteCode; } } return undefined; }; export const batchProcess = async (batchSize, list, func) => { let index = 0; while (batchSize * index < list.length) { const curList = list.slice(batchSize * index, batchSize * (index + 1)); await Promise.all(curList.map(func)); index++; } }; export const getMaxTimestampForLoadHistoryMessages = () => { return Math.floor(Date.now() / 1000) - HISTORY_MESSAGES_DAYS * 24 * 3600; }; //# sourceMappingURL=miscellaneous.js.map