Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type input #743

Closed
wants to merge 2 commits into from
Closed
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
76 changes: 41 additions & 35 deletions src/numeral.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@

if (numeral.isNumeral(input)) {
value = input.value();
} else if (input === 0 || typeof input === 'undefined') {
} else if (input === 0 || typeof input === 'undefined' || input === '' || input === null) {
value = 0;
} else if (input === null || _.isNaN(input)) {
} else if (_.isNaN(input)) {
value = null;
} else if (typeof input === 'string') {
if (options.zeroFormat && input === options.zeroFormat) {
Expand Down Expand Up @@ -569,41 +569,47 @@
Numeral Prototype
************************************/

numeral.fn = Numeral.prototype = {
clone: function() {
return numeral(this);
},
format: function(inputString, roundingFunction) {
var value = this._value,
format = inputString || options.defaultFormat,
kind,
output,
formatFunction;

// make sure we have a roundingFunction
roundingFunction = roundingFunction || Math.round;

// format based on value
if (value === 0 && options.zeroFormat !== null) {
output = options.zeroFormat;
} else if (value === null && options.nullFormat !== null) {
output = options.nullFormat;
} else {
for (kind in formats) {
if (format.match(formats[kind].regexps.format)) {
formatFunction = formats[kind].format;

break;
numeral.fn = Numeral.prototype = {
clone: function() {
return numeral(this);
},
format: function(inputString, roundingFunction) {
var value = this._value,
format = inputString || options.defaultFormat,
kind,
output,
formatFunction;

// make sure we have a roundingFunction
roundingFunction = roundingFunction || Math.round;

// format based on value
if (value === 0 && options.zeroFormat !== null) {
output = options.zeroFormat;
} else if (value === null && options.nullFormat !== null) {
output = options.nullFormat;
} else {
for (kind in formats) {
if (format.match(formats[kind].regexps.format)) {
formatFunction = formats[kind].format;

break;
}
}

formatFunction = formatFunction || numeral._.numberToFormat;
output = formatFunction(value, format, roundingFunction);
}

formatFunction = formatFunction || numeral._.numberToFormat;

output = formatFunction(value, format, roundingFunction);
}

return output;
},
inputStringLen = inputString.length
fixedNumber = inputString.toFixed()
if (inputString.includes('-')) {
inputStringLen -= 1
}
if (isNaN(output) && inputStringLen > 22) {
return fixedNumber
}
return output;
},
value: function() {
return this._value;
},
Expand Down