Skip to content

Instantly share code, notes, and snippets.

@mrwithersea
Last active November 22, 2017 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrwithersea/374575d4658134f8ec359901838b44bb to your computer and use it in GitHub Desktop.
Save mrwithersea/374575d4658134f8ec359901838b44bb to your computer and use it in GitHub Desktop.
Safe Number
import R from 'ramda';
const safeNumber =
R.when(
R.test(/^(?!\s*$)-?(0|[1-9]\d*)?(\.\d+)?$/),
Number
);
import R from 'ramda';
import safeNumber from './safe-number';
const safeValue =
R.compose(
R.cond([
[R.equals(0), R.always(0)],
[R.equals(false), R.always(false)],
[R.isNil, R.always(undefined)],
[R.T, R.identity],
]),
safeNumber
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment