Giter VIP home page Giter VIP logo

fast-message-segment-calculator's Introduction

SMS Segment Calculator

This 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

Usage

nodeJS

The package can be installed using:

npm install --save sms-segments-calculator

Sample usage:

const { SegmentedMessage } = require('sms-segments-calculator');

const segmentedMessage = new SegmentedMessage('Hello World');

console.log(segmentedMessage.encodingName); // "GSM-7"
console.log(segmentedMessage.segmentsCount); // "1"

Browser

You can add the library to your page using the CDN file:

<script src="https://cdn.jsdelivr.net/gh/TwilioDevEd/message-segment-calculator/docs/scripts/segmentsCalculator.js" integrity="sha256-wXuHVlXNhEWNzRKozzB87Qyi9/3p6LKskjDXFHIMInw=" crossorigin="anonymous"></script>

Alternatively you can add the library to your page using the file segmentsCalculator.js provided in docs/scripts/ and adding it to your page:

<script type="text/javascript" src="scripts/segmentsCalculator.js"></script>

And example of usage can be find in docs/index.html

Documentation

SegmentedMessage class

This is the main class exposed by the package

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

Total size of the message in bits (including User Data Header if present)

Total size of the message in bits (excluding User Data Header if present)

Number of segment(s)

[getNonGsmCharacters()]

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

Try the library

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:

$ node playground/index.js "๐Ÿ‘‹ Hello World ๐ŸŒ"

Contributing

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 error
  • Compile the code using npm run build command and make sure there are no errors
  • Execute the test using npm test and make sure all tests pass
  • Transpile the code using npm run webpack and test the web page in docs/index.html

License

MIT

Disclaimer

No warranty expressed or implied. Software is as is.

fast-message-segment-calculator's People

Contributors

vernig avatar smendes avatar hughrawlinson avatar micaswyers avatar semantic-release-bot avatar alexisbcc avatar firstwhack avatar dependabot[bot] avatar hugocrd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.