parse()

in index.js [70:97]


	parse(pattern) {
		this.pattern = pattern;
		this.parsed = parser.parse(pattern);

		const percentageInPrefix = DecimalFormat.count(this.parsed.positive.prefix, '%');
		const percentageInSuffix = DecimalFormat.count(this.parsed.positive.suffix, '%');

		if ((percentageInPrefix + percentageInSuffix) > 1) {
			throw new Error('Too many percent/per mille characters in pattern');
		}

		// Explicitly check for the pattern '.E0'
		if (this.minimumIntegerDigits === 0 && this.minimumFractionDigits === 0 && this.hasMantissa) {
			throw new Error('At least one integer or fraction digit is required for exponential patterns');
		}

		// If a negative pattern is not explicitly provided, use a copy of the
		// positive pattern.
		if (this.parsed.negative === null) {
			this.parsed.negative = Object.assign({}, this.parsed.positive);
		}

		// Java adds a '-' character to the negative prefix, when the prefix
		// is identical to the positive prefix.
		if (this.parsed.negative.prefix === this.parsed.positive.prefix) {
			this.parsed.negative.prefix = '-' + this.parsed.negative.prefix;
		}
	}