Fix ESLinting errors and remove TSLint
This commit is contained in:
@ -19,14 +19,12 @@ describe("Utility", () => {
|
||||
|
||||
describe("#uniqueNumericId", () => {
|
||||
it("should generate a unique incrementing ID", () => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(uniqueNumericId()).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#uniqueId", () => {
|
||||
it("should generate a unique pseudorandom ID", () => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(uniqueId()).to.not.be.empty;
|
||||
});
|
||||
});
|
||||
|
@ -7,8 +7,6 @@ export const convertMillimetersToTwip = (millimeters: number): number => Math.fl
|
||||
|
||||
export const convertInchesToTwip = (inches: number): number => Math.floor(inches * 72 * 20);
|
||||
|
||||
export const uniqueNumericId = (): number => {
|
||||
return ++currentCount;
|
||||
};
|
||||
export const uniqueNumericId = (): number => ++currentCount;
|
||||
|
||||
export const uniqueId = (): string => nanoid().toLowerCase();
|
||||
|
@ -7,63 +7,63 @@
|
||||
// <xsd:simpleType name="ST_DecimalNumber">
|
||||
// <xsd:restriction base="xsd:integer"/>
|
||||
// </xsd:simpleType>
|
||||
export function decimalNumber(val: number): number {
|
||||
export const decimalNumber = (val: number): number => {
|
||||
if (isNaN(val)) {
|
||||
throw new Error(`Invalid value '${val}' specified. Must be an integer.`);
|
||||
}
|
||||
return Math.floor(val);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_UnsignedDecimalNumber">
|
||||
// <xsd:restriction base="xsd:unsignedLong"/>
|
||||
// </xsd:simpleType>
|
||||
export function unsignedDecimalNumber(val: number): number {
|
||||
export const unsignedDecimalNumber = (val: number): number => {
|
||||
const value = decimalNumber(val);
|
||||
if (value < 0) {
|
||||
throw new Error(`Invalid value '${val}' specified. Must be a positive integer.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
// The xsd:hexBinary type represents binary data as a sequence of binary octets.
|
||||
// It uses hexadecimal encoding, where each binary octet is a two-character hexadecimal number.
|
||||
// Lowercase and uppercase letters A through F are permitted. For example, 0FB8 and 0fb8 are two
|
||||
// equal xsd:hexBinary representations consisting of two octets.
|
||||
// http://www.datypic.com/sc/xsd/t-xsd_hexBinary.html
|
||||
function hexBinary(val: string, length: number): string {
|
||||
const hexBinary = (val: string, length: number): string => {
|
||||
const expectedLength = length * 2;
|
||||
if (val.length !== expectedLength || isNaN(Number("0x" + val))) {
|
||||
throw new Error(`Invalid hex value '${val}'. Expected ${expectedLength} digit hex value`);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_LongHexNumber">
|
||||
// <xsd:restriction base="xsd:hexBinary">
|
||||
// <xsd:length value="4"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function longHexNumber(val: string): string {
|
||||
export const longHexNumber = (val: string): string => {
|
||||
return hexBinary(val, 4);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_ShortHexNumber">
|
||||
// <xsd:restriction base="xsd:hexBinary">
|
||||
// <xsd:length value="2"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function shortHexNumber(val: string): string {
|
||||
export const shortHexNumber = (val: string): string => {
|
||||
return hexBinary(val, 2);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_UcharHexNumber">
|
||||
// <xsd:restriction base="xsd:hexBinary">
|
||||
// <xsd:length value="1"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function uCharHexNumber(val: string): string {
|
||||
export const uCharHexNumber = (val: string): string => {
|
||||
return hexBinary(val, 1);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_LongHexNumber">
|
||||
// <xsd:restriction base="xsd:hexBinary">
|
||||
@ -76,7 +76,7 @@ export function uCharHexNumber(val: string): string {
|
||||
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function universalMeasureValue(val: string): string {
|
||||
export const universalMeasureValue = (val: string): string => {
|
||||
const unit = val.slice(-2);
|
||||
if (!universalMeasureUnits.includes(unit)) {
|
||||
throw new Error(`Invalid unit '${unit}' specified. Valid units are ${universalMeasureUnits.join(", ")}`);
|
||||
@ -86,7 +86,7 @@ export function universalMeasureValue(val: string): string {
|
||||
throw new Error(`Invalid value '${amount}' specified. Expected a valid number.`);
|
||||
}
|
||||
return `${Number(amount)}${unit}`;
|
||||
}
|
||||
};
|
||||
const universalMeasureUnits = ["mm", "cm", "in", "pt", "pc", "pi"];
|
||||
|
||||
// <xsd:simpleType name="ST_PositiveUniversalMeasure">
|
||||
@ -94,13 +94,13 @@ const universalMeasureUnits = ["mm", "cm", "in", "pt", "pc", "pi"];
|
||||
// <xsd:pattern value="[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function positiveUniversalMeasureValue(val: string): string {
|
||||
export const positiveUniversalMeasureValue = (val: string): string => {
|
||||
const value = universalMeasureValue(val);
|
||||
if (parseFloat(value) < 0) {
|
||||
throw new Error(`Invalid value '${value}' specified. Expected a positive number.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_HexColor">
|
||||
// <xsd:union memberTypes="ST_HexColorAuto s:ST_HexColorRGB"/>
|
||||
@ -116,7 +116,7 @@ export function positiveUniversalMeasureValue(val: string): string {
|
||||
// <xsd:length value="3" fixed="true"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function hexColorValue(val: string): string {
|
||||
export const hexColorValue = (val: string): string => {
|
||||
if (val === "auto") {
|
||||
return val;
|
||||
}
|
||||
@ -124,42 +124,42 @@ export function hexColorValue(val: string): string {
|
||||
// Most clients work with it, but strip it off anyway for strict compliance.
|
||||
const color = val.charAt(0) === "#" ? val.substring(1) : val;
|
||||
return hexBinary(color, 3);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_SignedTwipsMeasure">
|
||||
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
|
||||
// </xsd:simpleType>
|
||||
export function signedTwipsMeasureValue(val: string | number): string | number {
|
||||
export const signedTwipsMeasureValue = (val: string | number): string | number => {
|
||||
return typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_HpsMeasure">
|
||||
// <xsd:union memberTypes="s:ST_UnsignedDecimalNumber s:ST_PositiveUniversalMeasure"/>
|
||||
// </xsd:simpleType>
|
||||
export function hpsMeasureValue(val: string | number): string | number {
|
||||
export const hpsMeasureValue = (val: string | number): string | number => {
|
||||
return typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_SignedHpsMeasure">
|
||||
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
|
||||
// </xsd:simpleType>
|
||||
export function signedHpsMeasureValue(val: string | number): string | number {
|
||||
export const signedHpsMeasureValue = (val: string | number): string | number => {
|
||||
return typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_TwipsMeasure">
|
||||
// <xsd:union memberTypes="ST_UnsignedDecimalNumber ST_PositiveUniversalMeasure"/>
|
||||
// </xsd:simpleType>
|
||||
export function twipsMeasureValue(val: string | number): string | number {
|
||||
export const twipsMeasureValue = (val: string | number): string | number => {
|
||||
return typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_Percentage">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?%"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export function percentageValue(val: string): string {
|
||||
export const percentageValue = (val: string): string => {
|
||||
if (val.slice(-1) !== "%") {
|
||||
throw new Error(`Invalid value '${val}'. Expected percentage value (eg '55%')`);
|
||||
}
|
||||
@ -168,7 +168,7 @@ export function percentageValue(val: string): string {
|
||||
throw new Error(`Invalid value '${percent}' specified. Expected a valid number.`);
|
||||
}
|
||||
return `${Number(percent)}%`;
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_MeasurementOrPercent">
|
||||
// <xsd:union memberTypes="ST_DecimalNumberOrPercent s:ST_UniversalMeasure"/>
|
||||
@ -182,7 +182,7 @@ export function percentageValue(val: string): string {
|
||||
// <xsd:restriction base="xsd:integer"/>
|
||||
// </xsd:simpleType>
|
||||
|
||||
export function measurementOrPercentValue(val: number | string): number | string {
|
||||
export const measurementOrPercentValue = (val: number | string): number | string => {
|
||||
if (typeof val === "number") {
|
||||
return decimalNumber(val);
|
||||
}
|
||||
@ -190,7 +190,7 @@ export function measurementOrPercentValue(val: number | string): number | string
|
||||
return percentageValue(val);
|
||||
}
|
||||
return universalMeasureValue(val);
|
||||
}
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_EighthPointMeasure">
|
||||
// <xsd:restriction base="s:ST_UnsignedDecimalNumber"/>
|
||||
@ -222,6 +222,6 @@ export const pointMeasureValue = unsignedDecimalNumber;
|
||||
//
|
||||
// Luckily, js has this format built in already. See:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
||||
export function dateTimeValue(val: Date): string {
|
||||
export const dateTimeValue = (val: Date): string => {
|
||||
return val.toISOString();
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user