Skip to content

Commit

Permalink
refactored and simplified library. Added tests for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwclark committed Feb 13, 2019
1 parent 99b798d commit 91a1901
Show file tree
Hide file tree
Showing 5 changed files with 3,387 additions and 2,037 deletions.
24 changes: 5 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
'use strict'
const { gcd, highestFirst, formatAspectRatio } = require('./utils')

const gcd = (a, b) => b === 0 ? a : gcd(b, a % b)
const isUndefined = value => typeof value === 'undefined'

module.exports = (numerator, denominator, separator = ':') => {
let temp

if (numerator === denominator) return `1${separator}1`

if (numerator < denominator) {
temp = numerator
numerator = denominator
denominator = temp
}

const divisor = gcd(numerator, denominator)

return isUndefined(temp)
? `${numerator / divisor}${separator}${denominator / divisor}`
: `${denominator / divisor}${separator}${numerator / divisor}`
module.exports = (height, width, seperator = ':') => {
const [h, w] = highestFirst(height, width)
const divisor = gcd(h, w)
return formatAspectRatio(h, w, divisor, seperator)
}
Loading

0 comments on commit 91a1901

Please sign in to comment.