SMS segements calculator
npm install sms-segments-calculatorThis repo contains a package for an SMS segments calculator. The package is released as a nodeJS package as well as a browser script.
A browser demo for this package can be accessed here
The package can be installed using:
``shell`
npm install --save sms-segments-calculator
Sample usage:
`javascript
const { SegmentedMessage } = require('sms-segments-calculator');
const segmentedMessage = new SegmentedMessage('Hello World');
console.log(segmentedMessage.encodingName); // "GSM-7"
console.log(segmentedMessage.segmentsCount); // "1"
`
You can add the library to your page using the CDN file:
`html`
Alternatively you can add the library to your page using the file segmentsCalculator.js provided in docs/scripts/ and adding it to your page:
`html`
And example of usage can be find in docs/index.html
This is the main class exposed by the package
#### constructor(message, encoding)
Arguments:
* message: Body of the SMS encoding
* : Optional: encoding. It can be GSM-7, UCS-2, auto. Default value: auto
##### encodingName
Returns the name of the calculated encoding for the message: GSM-7 or UCS-2
#### totalSize
Total size of the message in bits (including User Data Header if present)
#### messageSize
Total size of the message in bits (excluding User Data Header if present)
#### segmentsCount
Number of segment(s)
Return an array with the non GSM-7 characters in the body. It can be used to replace character and reduce the number of segments
If you want to test the library you can use the script provided in playground/index.js. Install the dependencies (npm install) and then run:
`shell`
$ node playground/index.js "👋 Hello World 🌍"
This code is open source and welcomes contributions. All contributions are subject to our Code of Conduct.
The source code for the library is all contained in the src folder. Before submitting a PR:
* Run linter using npm run lint command and make sure there are no linter errornpm run build
* Compile the code using command and make sure there are no errorsnpm test
* Execute the test using and make sure all tests passnpm run webpack
* Transpile the code using and test the web page in docs/index.html`
No warranty expressed or implied. Software is as is.
[twilio]: https://www.twilio.com