diff --git a/README.md b/README.md index c66b574..e3c4e0a 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,12 @@ $ aspect-ratio $ aspect-ratio [options] options: - -s specified a separator. (by default is ':'). - --version output the current version. + -s specified a separator. (by default is ':'). + --version output the current version. examples: - aspect-ratio 1920 1080 - aspect-ratio 800 600 -s / + aspect-ratio 1920 1080 + aspect-ratio 800 600 -s / ``` ## License diff --git a/bin/index.js b/bin/index.js index 7bed8b8..18679f4 100755 --- a/bin/index.js +++ b/bin/index.js @@ -5,7 +5,7 @@ const cli = require('meow')({ pkg: '../package.json', help: [ 'Usage', - ' $ aspect-ratio [options]', + ' $ aspect-ratio [options]', '\n options:', "\t -s\t specified a separator. (by default is ':').", '\t --version output the current version.', diff --git a/src/index.js b/src/index.js index 1d92c08..5df3b16 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const { gcd, highestFirst, formatAspectRatio } = require('./util') -module.exports = (height, width, seperator = ':') => { +module.exports = (width, height, seperator = ':') => { if (typeof height !== 'number') { throw new Error( `Invalid height: expected a \`number\`, received \`${height}\`` @@ -17,5 +17,5 @@ module.exports = (height, width, seperator = ':') => { const [h, w] = highestFirst(height, width) const divisor = gcd(h, w) - return formatAspectRatio(h, w, divisor, seperator) + return formatAspectRatio(width, height, divisor, seperator) } diff --git a/test/index.js b/test/index.js index 85b8662..7018f5f 100644 --- a/test/index.js +++ b/test/index.js @@ -5,8 +5,13 @@ const should = require('should') describe('aspect ratio', () => { it('1024x768', () => should(aspectRatio(1024, 768)).equal('4:3')) + it('768x1024', () => should(aspectRatio(768, 1024)).equal('3:4')) it('1920x1080', () => should(aspectRatio(1920, 1080)).equal('16:9')) it('1280x1024', () => should(aspectRatio(1280, 1024)).equal('5:4')) + it('1024x1280', () => should(aspectRatio(1024, 1280)).equal('4:5')) + it('1080x1920', () => should(aspectRatio(1080, 1920)).equal('9:16')) + it('3840x2160', () => should(aspectRatio(3840, 2160)).equal('16:9')) + it('2160x3840', () => should(aspectRatio(2160, 3840)).equal('9:16')) it('specifying output separator', () => should(aspectRatio(1920, 1080, '/')).equal('16/9'))