Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(isNaN): isNumberNaN #11242

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ function toInt(str) {
return parseInt(str, 10);
}

var isNumberNaN = Number.isNaN || function isNumberNaN(num) {
return num !== num;
};


function inherit(parent, extra) {
return extend(Object.create(parent), extra);
Expand Down Expand Up @@ -1113,7 +1117,7 @@ function fromJson(json) {

function timezoneToOffset(timezone, fallback) {
var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
return isNumberNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
}


Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (isDefined(val) && !isNumber(val)) {
val = parseFloat(val, 10);
}
minVal = isNumber(val) && !isNaN(val) ? val : undefined;
minVal = !isNumberNaN(val) ? val : undefined;
// TODO(matsko): implement validateLater to reduce number of validations
ctrl.$validate();
});
Expand All @@ -1275,7 +1275,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (isDefined(val) && !isNumber(val)) {
val = parseFloat(val, 10);
}
maxVal = isNumber(val) && !isNaN(val) ? val : undefined;
maxVal = !isNumberNaN(val) ? val : undefined;
// TODO(matsko): implement validateLater to reduce number of validations
ctrl.$validate();
});
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
*/
this.$validate = function() {
// ignore $validate before model is initialized
if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) {
if (isNumberNaN(ctrl.$modelValue)) {
return;
}

Expand Down Expand Up @@ -676,7 +676,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
}
}
}
if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) {
if (isNumberNaN(ctrl.$modelValue)) {
// ctrl.$modelValue has not been touched yet...
ctrl.$modelValue = ngModelGet($scope);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ng/directive/ngPluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale,

scope.$watch(numberExp, function ngPluralizeWatchAction(newVal) {
var count = parseFloat(newVal);
var countIsNaN = isNaN(count);
var countIsNaN = isNumberNaN(count);

if (!countIsNaN && !(count in whens)) {
// If an explicit number rule such as 1, 2, 3... is defined, just use it.
Expand All @@ -217,7 +217,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale,

// If both `count` and `lastCount` are NaN, we don't need to re-register a watch.
// In JS `NaN !== NaN`, so we have to exlicitly check.
if ((count !== lastCount) && !(countIsNaN && isNumber(lastCount) && isNaN(lastCount))) {
if ((count !== lastCount) && !(countIsNaN && isNumberNaN(lastCount))) {
watchRemover();
var whenExpFn = whensExpFns[count];
if (isUndefined(whenExpFn)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var maxlengthDirective = function() {
var maxlength = -1;
attr.$observe('maxlength', function(value) {
var intVal = toInt(value);
maxlength = isNaN(intVal) ? -1 : intVal;
maxlength = isNumberNaN(intVal) ? -1 : intVal;
ctrl.$validate();
});
ctrl.$validators.maxlength = function(modelValue, viewValue) {
Expand Down
2 changes: 1 addition & 1 deletion src/ng/filter/limitTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function limitToFilter() {
} else {
limit = toInt(limit);
}
if (isNaN(limit)) return input;
if (isNumberNaN(limit)) return input;

if (isNumber(input)) input = input.toString();
if (!isArray(input) && !isString(input)) return input;
Expand Down
3 changes: 1 addition & 2 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,7 @@ function $RootScopeProvider() {
if ((value = watch.get(current)) !== (last = watch.last) &&
!(watch.eq
? equals(value, last)
: (typeof value === 'number' && typeof last === 'number'
&& isNaN(value) && isNaN(last)))) {
: (isNumberNaN(value) && isNumberNaN(last)))) {
dirty = true;
lastDirtyWatch = watch;
watch.last = watch.eq ? copy(value, null) : value;
Expand Down