UNPKG
holyfills
Version:
latest (1.0.1)
1.0.1
1.0.0
No more "Holy Sxxt!!" when writting ES5/ES6
github.com/tomchentw/holyfills
tomchentw/holyfills
holyfills
/
lib
/
helpers
/
toInteger.js
15 lines
(13 loc)
•
303 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"use strict"
;
// ES5 9.4
// http://es5.github.com/#x9.4
// http://jsperf.com/to-integer
module
.
exports
=
function
(
num
) {
var
n = +num;
if
(n !== n) {
// isNaN
n =
0
; }
else
if
(n !==
0
&& n !== (
1
/
0
) && n !== -(
1
/
0
)) { n = (n >
0
|| -
1
) *
Math
.
floor
(
Math
.
abs
(n)); }
return
n; };