Mastodon hachyterm.io

A user submits text to your program with an input field. In Javascript, this is always a string.

But sometimes you need a number:

Ramda.js defaultTo

R.pipe(
  parseInt,
  R.defaultTo(0)
)("650"); // output: 650

This converts the input (string) to a number. If the input is undefined, null or NaN, it returns the argument to Ramda’s defaultTo (in this case 0).

R.pipe(
  parseInt,
  R.defaultTo(0)
)(""); // output: 0