nusk
v1.0.1
Published
A simple yet efficient smpp library
Downloads
9
Readme
Nusk
Nusk is a high-performance SMS segment calculator library for Node.js that supports GSM-7 and Unicode encodings, including extended GSM-7 characters. It helps you accurately calculate the number of SMS segments and estimated costs based on message content, making it a reliable replacement for Twilio's segment calculator.
Features
- Detects GSM-7 and Unicode encoding automatically
- Supports extended GSM-7 characters that consume two bytes
- Calculates SMS segments for single and concatenated messages
- Estimates total SMS cost based on configurable cost per segment
- Batch processing for multiple messages
- Caches analysis results for better performance
- Handles large messages efficiently and safely
Installation
npm install nuskUsage
const { calculateSegments, calculateCost, processBatch } = require("nusk");
const message = "Hello, World!";
const segmentInfo = calculateSegments(message);
console.log(segmentInfo);
// Example output:
// { segments: 1, charsPerSegment: 160, encoding: 'gsm7' }
const cost = calculateCost(message, 0.0075);
console.log(`Cost: $${cost}`);
const batchMessages = [
{ text: "Short message" },
{ text: "😊 Unicode message with emoji" },
];
const batchResults = processBatch(batchMessages);
console.log(batchResults);