Ts all the tests (#1998)

* Convert tests to TypeScript

* Add types for tests

* Rename files to TS

* Fix up test imports

* Fix TSC errors

* Liiiint

* Add types to util method signatures

* Some more types
This commit is contained in:
Paulus Schoutsen
2018-11-06 10:09:09 +01:00
committed by GitHub
parent 856ef34964
commit cdb2093ea6
78 changed files with 524 additions and 364 deletions

View File

@@ -0,0 +1,26 @@
export default function parseAspectRatio(input) {
// Handle 16x9, 16:9, 1.78x1, 1.78:1, 1.78
// Ignore everything else
function parseOrThrow(num) {
const parsed = parseFloat(num);
if (isNaN(parsed)) {
throw new Error(`${num} is not a number`);
}
return parsed;
}
try {
if (input) {
const arr = input.replace(":", "x").split("x");
if (arr.length === 0) {
return null;
}
return arr.length === 1
? { w: parseOrThrow(arr[0]), h: 1 }
: { w: parseOrThrow(arr[0]), h: parseOrThrow(arr[1]) };
}
} catch (err) {
// Ignore the error
}
return null;
}