MCPcopy
hub / github.com/autoNumeric/autoNumeric / localize

Method localize

src/AutoNumeric.js:4618–4650  ·  view source on GitHub ↗

* Unformat and localize the given formatted string with the given options. This returns a numeric string. * It can also unformat and localize the given DOM element value with the given options and returns the unformatted numeric string. * Note: This does *not* update that element value.

(numericStringOrDomElement, settings = null)

Source from the content-addressed store, hash-verified

4616 * @returns {*}
4617 */
4618 static localize(numericStringOrDomElement, settings = null) {
4619 let value;
4620 if (AutoNumericHelper.isElement(numericStringOrDomElement)) {
4621 value = AutoNumericHelper.getElementValue(numericStringOrDomElement);
4622 } else {
4623 value = numericStringOrDomElement;
4624 }
4625
4626 if (value === '') {
4627 // This allows to be coherent when serializing forms with empty inputs. Fix issue #512.
4628 return '';
4629 }
4630
4631 if (AutoNumericHelper.isNull(settings)) {
4632 settings = AutoNumeric.defaultSettings;
4633 }
4634
4635 value = this.unformat(value, settings);
4636
4637 //XXX The following code is pretty close to the one you can find in `getLocalized()`, but different enough so we won't refactor it.
4638 if (Number(value) === 0 && settings.leadingZero !== AutoNumeric.options.leadingZero.keep) {
4639 value = '0';
4640 }
4641
4642 let outputFormatToUse;
4643 if (AutoNumericHelper.isNull(settings)) {
4644 outputFormatToUse = settings.outputFormat;
4645 } else {
4646 outputFormatToUse = AutoNumeric.defaultSettings.outputFormat;
4647 }
4648
4649 return this._toLocale(value, outputFormatToUse, settings);
4650 }
4651
4652 static localizeAndSet(domElement, options = null) { //FIXME test this
4653 const localizedValue = this.localize(domElement, options);

Callers 2

localizeAndSetMethod · 0.95
_serializeMethod · 0.95

Calls 5

unformatMethod · 0.95
_toLocaleMethod · 0.95
isElementMethod · 0.80
getElementValueMethod · 0.80
isNullMethod · 0.80

Tested by

no test coverage detected