UNPKG

verimor-api-sdk

Version:
40 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmsUtils = void 0; /** * Utility class for SMS-related calculations. */ class SmsUtils { /** * Calculates the number of SMS credits required for the given message. * @param message - The message content. * @returns The number of SMS credits required. */ static calculateSmsCredits(message) { const length = message.length; const isUnicode = /[^\u0000-\u00FF]/.test(message); const specialChars = /[\^{}\\[\]~|€]/g; const specialCharCount = (message.match(specialChars) || []).length; let credits = 0; if (isUnicode) { if (length <= 70) { credits = 1; } else { credits = Math.ceil(length / 67); } } else { const adjustedLength = length + specialCharCount; if (adjustedLength <= 160) { credits = 1; } else { credits = Math.ceil(adjustedLength / 153); } } return credits; } } exports.SmsUtils = SmsUtils; //# sourceMappingURL=sms-utils.js.map