Skip to content

Commit 91a1901

Browse files
committed
refactored and simplified library. Added tests for utils
1 parent 99b798d commit 91a1901

File tree

5 files changed

+3387
-2037
lines changed

5 files changed

+3387
-2037
lines changed

index.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
'use strict'
2+
const { gcd, highestFirst, formatAspectRatio } = require('./utils')
23

3-
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b)
4-
const isUndefined = value => typeof value === 'undefined'
5-
6-
module.exports = (numerator, denominator, separator = ':') => {
7-
let temp
8-
9-
if (numerator === denominator) return `1${separator}1`
10-
11-
if (numerator < denominator) {
12-
temp = numerator
13-
numerator = denominator
14-
denominator = temp
15-
}
16-
17-
const divisor = gcd(numerator, denominator)
18-
19-
return isUndefined(temp)
20-
? `${numerator / divisor}${separator}${denominator / divisor}`
21-
: `${denominator / divisor}${separator}${numerator / divisor}`
4+
module.exports = (height, width, seperator = ':') => {
5+
const [h, w] = highestFirst(height, width)
6+
const divisor = gcd(h, w)
7+
return formatAspectRatio(h, w, divisor, seperator)
228
}

0 commit comments

Comments
 (0)