UNPKG

twilio-split-sms

Version:

Forked version of codesleuth's split-sms: An SMS message splitter with support for both GSM and Unicode.

1 lines 5.25 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&&t<=56319}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;c<d;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]&&u<=160?{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;n<r;){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,171,187,8220,8221,698,750,8223,10077,10078,12317,12318,65282,8216,8217,699,712,700,701,697,8219,65287,180,714,96,715,10075,10076,787,788,65040,65041,247,188,189,190,10744,823,824,8260,8725,65295,10745,10741,8421,65128,65340,818,65343,8402,8403,8739,65372,9144,9145,9168,9116,9119,9148,9149,8213,65123,65293,8208,8259,65131,65312,65129,65284,451,65045,65111,65281,65119,65283,65130,65285,65120,65286,8218,806,65104,65105,65292,65380,10088,10090,65113,65288,10222,10629,10089,10091,65114,65289,10223,10630,8270,8727,8859,10018,10019,10020,10021,10033,10034,10035,10042,10043,10044,10045,10051,10057,10058,10059,10694,65121,65290,726,65122,65291,12290,65106,65294,65377,65296,65297,65298,65299,65300,65301,65302,65303,65304,65305,720,760,10626,42889,65043,65306,8271,65044,65108,65307,65124,65308,839,42890,65126,65309,65125,65310,65046,65110,65311,65313,7424,65314,665,65315,7428,65316,7429,65317,7431,65318,42800,65319,610,65320,668,65321,618,65322,7434,65323,7435,65324,671,65325,7437,65326,628,65327,7439,65328,7448,65329,65330,640,65331,42801,65332,7451,65333,7452,65334,7456,65335,7457,65336,65337,655,65338,7458,710,770,65342,7629,10100,65115,65371,10101,65116,65373,65339,65341,732,759,771,816,820,8764,65374,160,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,141,159,128,144,155,16,9,0,3,4,23,25,17,18,19,20,8215,8212,8211,8218,8239,8249,8250,8252,8222,8221,8220,8219,8230,8232,8233,8287,8288],u=[12,91,92,93,94,123,124,125,126,8364,710,770,65342,7629,10100,65115,65371,8821,65116,65373,10745,10741,8421,65128,65340,65339,65341,732,759,771,816,820,8764,65374,8402,8403,8739,65372,9144,9145,9168,9116,9119];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&&t<=56319}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;f<c;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]&&s<=140?{parts:[{content:e.summary?void 0:t,length:u,bytes:s}],totalLength:u,totalBytes:s}:{parts:a,totalLength:u,totalBytes:s}}},{}]},{},[3])(3)});