@loltech/sms-splitter
v1.0.2
Published
Typescript library for splitting strings into SMS messages according to GSM-7 or UCS-2.
Maintainers
Readme
LOLTECH SMS Splitter
A Typescript library for splitting a message string into parts according to GSM specifications.
Installation
This package is meant for usage in Node.js. Should work in the browser when using something like webpack or
rollup.
yarn add @loltech/sms-splitterOR
npm install @loltech/sms-splitterUsage
import { isMultipart, split } from '@loltech/sms-splitter';Is a message multipart?
function isMultipart(message: string): boolean;Given a message string, determines whether that string needs to be split up according to GSM spec. Return the result as a boolean.
Split the message
function split(message: string): ISplitResult | null;Given a message string, will determine its required encoding and split it into parts according to GSM spec.
Return value
If message is anything other than a string, it returns null.
If message is a string, it returns an object of the form:
interface ISplitResult {
encoding: ENCODING;
extended?: boolean;
parts: string[];
}encoding- Can beGSM-7,UCS-2,UTF-16.UCS-2andUTF-16are very similar, butUTF-16can also encodeUTF-32characters.UCS-2basically means the string does not use characters outside the BMP.extended- Only present whenencodingisGSM-7. Signals the string containsGSM-7extended characters.parts- An array of strings making up the resultant SMS parts.
Note on behaviour
When splitting SMS messages for transmission, it's best practice to not split up characters.
This happens both in GSM-7 (where extended characters are actually made up of two characters) and
UTF-16 (where surrogate pairs are employed).
This library DOES NOT split characters.
While this is
technically correct, it's not the whole story.
As can be seen in
this particular patch comment, some
carries cannot handle messages split within character boundaries.
Unfortunately the only possible solution I found will
be to use Intl.breakItreator, but that feature hasn't been
standardized or implemented yet.
