JavaScript Code Snippets

You may be able to try some of this code out in your browser at

Send a Single SMS Message (Twilio)

To run this Node.js script, the Twilio JavaScript library must first be installed. Here, sendingNumber and receivingNumber include the country code. Note that the Account SID and Auth Token are provided to the script as environment variables. You can find these values in your Twilio dashboard.

Node.js Unit Testing (Jest)

The structure of a test suite in Node.js. First, Jest must be installed. This code should be in a file titled mytest.test.js, and it can be ran by executing the jest command in the terminal.

Linear Interpolation (lerp)

A simple lerp implementation. progress ranges from 0 (start) to 1 (end).

Generate list of numbers in range

Like Python's range function, this returns an array of numbers, starting from the given initial value, and increments by step, and stops before the given final value. If the optional boolean parameter inclusiveOfB is set to true, this function will include the given final value at the end of the returned array.

Slugify a String

Turn a string into a slug. Borrowed from Lulu.