UNPKG

@deathabyss/wwebjs-sender

Version:

A package to send messages/buttons using constructors with the whatsapp-web.js package

36 lines (33 loc) 1.11 kB
/** * Contains various general-purpose utility methods. */ class Util extends null { /** * Verifies the provided data is a string, otherwise throws provided error. * @param {string} data The string resolvable to resolve * @param {Function} [error] The Error constructor to instantiate. Defaults to Error * @param {string} [errorMessage] The error message to throw with. Defaults to "Expected string, got <data> instead." * @param {boolean} [allowEmpty=true] Whether an empty string should be allowed * @returns {string} */ static verifyString( data, error = Error, errorMessage = `Expected a string, got ${data} instead.`, allowEmpty = true ) { if (typeof data !== "string") throw new error(errorMessage); if (!allowEmpty && data.length === 0) throw new error(errorMessage); return data; } /** * Shallow-copies an object with its class/prototype intact. * @param {Object} obj Object to clone * @returns {Object} * @private */ static cloneObject(obj) { return Object.assign(Object.create(obj), obj); } } module.exports = Util;