-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored and simplified library. Added tests for utils
- Loading branch information
1 parent
99b798d
commit 91a1901
Showing
5 changed files
with
3,387 additions
and
2,037 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.