MCPcopy
hub / github.com/autoNumeric/autoNumeric / _toLocale

Method _toLocale

src/AutoNumeric.js:5210–5246  ·  view source on GitHub ↗

* Converts the ISO numeric string to the locale decimal and minus sign placement. * See the "outputFormat" option definition for more details. * Note: If the `outputFormat` is set to a number, the custom `negativeSignCharacter` is ignored. * * @param {string|null} value The unfor

(value, locale, settings)

Source from the content-addressed store, hash-verified

5208 * @returns {*}
5209 */
5210 static _toLocale(value, locale, settings) {
5211 if (AutoNumericHelper.isNull(locale) || locale === AutoNumeric.options.outputFormat.string) {
5212 return value;
5213 }
5214
5215 let result;
5216 switch (locale) {
5217 case AutoNumeric.options.outputFormat.number:
5218 result = Number(value);
5219 break;
5220 case AutoNumeric.options.outputFormat.dotNegative:
5221 result = AutoNumericHelper.isNegative(value) ? value.replace('-', '') + '-' : value;
5222 break;
5223 case AutoNumeric.options.outputFormat.comma:
5224 case AutoNumeric.options.outputFormat.negativeComma:
5225 result = value.replace('.', ',');
5226 break;
5227 case AutoNumeric.options.outputFormat.commaNegative:
5228 result = value.replace('.', ',');
5229 result = AutoNumericHelper.isNegative(result) ? result.replace('-', '') + '-' : result;
5230 break;
5231 // The default case
5232 case AutoNumeric.options.outputFormat.dot:
5233 case AutoNumeric.options.outputFormat.negativeDot:
5234 result = value;
5235 break;
5236 default :
5237 AutoNumericHelper.throwError(`The given outputFormat [${locale}] option is not recognized.`);
5238 }
5239
5240 if (locale !== AutoNumeric.options.outputFormat.number && settings.negativeSignCharacter !== '-') {
5241 // Modify the default minus sign with the custom one, if any
5242 result = result.replace('-', settings.negativeSignCharacter);
5243 }
5244
5245 return result;
5246 }
5247
5248 /**
5249 * Modify the negative sign and the decimal character of the given string value to a hyphen (-) and a dot (.) in order to make that value 'typecastable' to a real number.

Callers 4

unformatMethod · 0.95
localizeMethod · 0.95
getNumberMethod · 0.80
getLocalizedMethod · 0.80

Calls 3

isNullMethod · 0.80
isNegativeMethod · 0.80
throwErrorMethod · 0.80

Tested by

no test coverage detected