-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (58 loc) · 2.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { paperSpecifications } from './paperSpecifications.js';
const mmToInches = 25.4;
const calculatedPrecision = 3;
export function isPaperType(possiblePaperType = '') {
return Object.hasOwn(paperSpecifications, possiblePaperType.toUpperCase());
}
export function getPaperSize(paperType, paperSizeUnit) {
const specifications = paperSpecifications[(paperType ?? '').toUpperCase()];
if (specifications === undefined ||
paperSizeUnit === undefined ||
specifications.unit === paperSizeUnit) {
return specifications;
}
if (paperSizeUnit === 'in') {
return {
width: Number.parseFloat((specifications.width / mmToInches).toFixed(calculatedPrecision)),
height: Number.parseFloat((specifications.height / mmToInches).toFixed(calculatedPrecision)),
unit: 'in'
};
}
else if (paperSizeUnit === 'mm') {
return {
width: Number.parseFloat((specifications.width * mmToInches).toFixed(calculatedPrecision)),
height: Number.parseFloat((specifications.height * mmToInches).toFixed(calculatedPrecision)),
unit: 'mm'
};
}
return undefined;
}
export function getLandscapePaperSize(paperType, paperSizeUnit) {
if (!isPaperType(paperType)) {
return undefined;
}
const portraitSize = getPaperSize(paperType, paperSizeUnit);
if (portraitSize === undefined) {
return undefined;
}
return {
width: portraitSize.height,
height: portraitSize.width,
unit: portraitSize.unit
};
}
export function getPaperSizeInInches(paperType) {
if (!isPaperType(paperType)) {
return undefined;
}
return getPaperSize(paperType, 'in');
}
export function getPaperSizeInMillimetres(paperType) {
if (!isPaperType(paperType)) {
return undefined;
}
return getPaperSize(paperType, 'mm');
}
export { paperSpecifications } from './paperSpecifications.js';
export { commonNorthAmericanPaperSpecifications, ansiPaperSpecifications, archPaperSpecifications, northAmericanPaperSpecifications, isNorthAmericanPaperType } from './paperSpecifications/northAmerica.js';
export { aSeriesPaperSpecifications, bSeriesPaperSpecifications, cSeriesPaperSpecifications, isoPaperSpecifications, isIsoPaperType } from './paperSpecifications/iso.js';