@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
100 lines (99 loc) • 4.13 kB
JavaScript
import { _validateDateTimeComponent } from './syntax-verifier';
/**
* Represents an internal duration equivalent structure used to hold PDF duration components and serialize them.
*
* @private
*/
var _PdfDurationEquivalent = /** @class */ (function () {
function _PdfDurationEquivalent(years, months, weeks, days, hours, minutes, seconds, fractionalPart) {
if (typeof weeks !== 'undefined' && weeks !== null && (years || months || days || hours || minutes || seconds)) {
throw new Error('Duration equivalent may not combine week components and date-time components.');
}
if (years) {
_validateDateTimeComponent('year', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', years);
}
if (months) {
_validateDateTimeComponent('month', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', months);
}
if (weeks) {
_validateDateTimeComponent('week', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', weeks);
}
if (days) {
_validateDateTimeComponent('day', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', days);
}
if (hours) {
_validateDateTimeComponent('hour', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', hours);
}
if (minutes) {
_validateDateTimeComponent('minute', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', minutes);
}
if (seconds) {
_validateDateTimeComponent('second', 0, Number.MAX_SAFE_INTEGER)('Duration equivalent', seconds);
}
if (fractionalPart && !Number.isSafeInteger(fractionalPart.fractionalValue)) {
throw new Error('The fractional part of the duration is incorrectly formatted');
}
this._years = years;
this._months = months;
this._weeks = weeks;
this._days = days;
this._hours = hours;
this._minutes = minutes;
this._seconds = seconds;
this._fractionalPart = fractionalPart;
}
/**
* Converts the internal duration equivalent into a readable textual representation.
*
* @private
* @returns {string} A formatted string describing the included duration components.
*/
_PdfDurationEquivalent.prototype._toString = function () {
var result = 'DURATION { ';
if (typeof this._years !== 'undefined' && this._years !== null) {
result += "years " + this._years + " ";
}
if (typeof this._months !== 'undefined' && this._months !== null) {
result += "months " + this._months + " ";
}
if (typeof this._days !== 'undefined' && this._days !== null) {
result += "days " + this._days + " ";
}
if (typeof this._hours !== 'undefined' && this._hours !== null) {
result += "hours " + this._hours + " ";
}
if (typeof this._minutes !== 'undefined' && this._minutes !== null) {
result += "minutes " + this._minutes + " ";
}
if (typeof this._seconds !== 'undefined' && this._seconds !== null) {
result += "seconds " + this._seconds + " ";
}
result += '}';
return result;
};
/**
* Converts the internal duration equivalent into a JSON-compatible representation.
*
* @private
* @returns {any} A JSON object containing duration components and optional fractional information.
*/
_PdfDurationEquivalent.prototype._toJson = function () {
return {
years: this._years,
months: this._months,
weeks: this._weeks,
days: this._days,
hours: this._hours,
minutes: this._minutes,
seconds: this._seconds,
fractionalPart: this._fractionalPart
? {
numberOfDigits: this._fractionalPart.numberOfDigits,
fractionalValue: this._fractionalPart.fractionalValue
}
: undefined
};
};
return _PdfDurationEquivalent;
}());
export { _PdfDurationEquivalent };