aboutsummaryrefslogtreecommitdiff
path: root/src/client/Native/Reads.js
blob: 5785aed90ccd2959a8332c007a65f09299358ea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Elm.Native.Reads = {};
Elm.Native.Reads.make = function(localRuntime) {

  localRuntime.Native = localRuntime.Native || {};
  localRuntime.Native.Reads = localRuntime.Native.Reads || {};
  if(localRuntime.Native.Reads.values) {
    return localRuntime.Native.Reads.values;
  }

  var Maybe = Elm.Maybe.make(localRuntime);

  function readInt(str) {
    var number = Number(str);
    return isNaN(number) || str === ''
             ? Maybe.Nothing
             : Maybe.Just(number);
  }

  return localRuntime.Native.Reads.values = {
    readInt: readInt
  };
};