UNPKG

split-sms

Version:

An SMS message splitter with support for both GSM and Unicode.

1 lines 3.65 kB
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.splitter=t()}}(function(){return function t(e,r,n){function a(i,s){if(!r[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(o)return o(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var f=r[i]={exports:{}};e[i][0].call(f.exports,function(t){var r=e[i][1][t];return a(r?r:t)},f,f.exports,t,e,r,n)}return r[i].exports}for(var o="function"==typeof require&&require,i=0;i<n.length;i++)a(n[i]);return a}({1:[function(t,e,r){function n(t){return t>=55296&&56319>=t}var a=t("./gsmvalidator");e.exports.split=function(t,e){function r(){var t={content:e.summary?void 0:f,length:i,bytes:s};o.push(t),l+=i,i=0,u+=s,s=0,f=""}if(e=e||{summary:!1},""===t)return{parts:[{content:e.summary?void 0:"",length:0,bytes:0}],totalLength:0,totalBytes:0};for(var o=[],i=0,s=0,u=0,l=0,f="",c=0,d=t.length;d>c;c++){var p=t.charAt(c);a.validateCharacter(p)?a.validateExtendedCharacter(p)&&(152===s&&r(),s++):(n(p.charCodeAt(0))&&c++,p=" "),s++,i++,e.summary||(f+=p),153===s&&r()}return s>0&&r(),o[1]&&160>=u?{parts:[{content:e.summary?void 0:o[0].content+o[1].content,length:l,bytes:u}],totalLength:l,totalBytes:u}:{parts:o,totalLength:l,totalBytes:u}}},{"./gsmvalidator":2}],2:[function(t,e,r){function n(t,e){for(var r=e.length,n=0;r>n;){var a=e[n];if(t===a)return!0;n++}return!1}function a(t){var e=t.charCodeAt(0);return n(e,s)}function o(t){for(var e=0;e<t.length;e++)if(!a(t.charAt(e)))return!1;return!0}function i(t){var e=t.charCodeAt(0);return n(e,u)}var s=[10,12,13,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,161,163,164,165,167,191,196,197,198,199,201,209,214,216,220,223,224,228,229,230,232,233,236,241,242,246,248,249,252,915,916,920,923,926,928,931,934,936,937,8364],u=[12,91,92,93,94,123,124,125,126,8364];e.exports.validateCharacter=a,e.exports.validateMessage=o,e.exports.validateExtendedCharacter=i},{}],3:[function(t,e,r){function n(t,e,r,n){var a=1===t.length?e:r;return(a-t[t.length-1].bytes)/n}var a=t("./gsmvalidator"),o=t("./gsmsplitter"),i=t("./unicodesplitter"),s=e.exports.UNICODE="Unicode",u=e.exports.GSM="GSM";e.exports.split=function(t,e){var r=e&&e.characterset;e={summary:e&&e.summary};var l,f,c,d,p=void 0===r&&a.validateMessage(t)||r===u;p?(l=o.split(t,e),f=160,c=153,d=1):(l=i.split(t,e),f=140,c=134,d=2);var v=n(l.parts,f,c,d);return{characterSet:p?u:s,parts:l.parts,bytes:l.totalBytes,length:l.totalLength,remainingInPart:v}}},{"./gsmsplitter":1,"./gsmvalidator":2,"./unicodesplitter":4}],4:[function(t,e,r){function n(t){return t>=55296&&56319>=t}e.exports.split=function(t,e){function r(r){var n={content:e.summary?void 0:r?t.substring(l,r+1):t.substring(l),length:o,bytes:i};a.push(n),l=r+1,u+=o,o=0,s+=i,i=0}if(e=e||{summary:!1},""===t)return{parts:[{content:e.summary?void 0:"",length:0,bytes:0}],totalLength:0,totalBytes:0};for(var a=[],o=0,i=0,s=0,u=0,l=0,f=0,c=t.length;c>f;f++){var d=t.charCodeAt(f),p=n(d);p&&(132===i&&r(f-1),i+=2,f++),i+=2,o++,134===i&&r(f)}return i>0&&r(),a[1]&&140>=s?{parts:[{content:e.summary?void 0:t,length:u,bytes:s}],totalLength:u,totalBytes:s}:{parts:a,totalLength:u,totalBytes:s}}},{}]},{},[3])(3)});