Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function toDpi(resolution) {
units = String(resolution).match(RE_RESOLUTION_UNIT)[1];

switch (units) {
case 'dpcm': return value / 2.54;
case 'dpcm': return value * 2.54;
case 'dppx': return value * 96;
default : return value;
}
Expand All @@ -173,8 +173,8 @@ function toPx(length) {
case 'cm' : return value * 96 / 2.54;
case 'mm' : return value * 96 / 2.54 / 10;
case 'in' : return value * 96;
case 'pt' : return value * 72;
case 'pc' : return value * 72 / 12;
case 'pt' : return value * 96 / 72;
case 'pc' : return value * 96 / 6;
default : return value;
}
}
18 changes: 17 additions & 1 deletion test/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ describe('mediaQuery.match()', function () {
});

describe('Different Units', function () {
['72pt', '6pc'].forEach(function (length) {
it('should equate ' + length + ' with 96px in either operand', function () {
expect(mediaQuery.match('(width: ' + length + ')', {width: '96px'})).to.be.true;
expect(mediaQuery.match('(width: 96px)', {width: length})).to.be.true;
expect(mediaQuery.match('(min-width: ' + length + ')', {width: '95px'})).to.be.false;
expect(mediaQuery.match('(max-width: ' + length + ')', {width: '97px'})).to.be.false;
});
});

it('should work with ems', function () {
expect(mediaQuery.match(
'(min-width: 500px)', {width: '48em'}
Expand Down Expand Up @@ -190,12 +199,19 @@ describe('mediaQuery.match()', function () {
it('should convert units properly', function () {
expect(mediaQuery.match(
'(min-resolution: 72dpi)', {resolution: '75dpcm'}
)).to.be.false;
)).to.be.true;

expect(mediaQuery.match(
'(resolution: 192dpi)', {resolution: '2dppx'}
)).to.be.true;
});

it('should equate 100dpcm with 254dpi in either operand', function () {
expect(mediaQuery.match('(resolution: 100dpcm)', {resolution: '254dpi'})).to.be.true;
expect(mediaQuery.match('(resolution: 254dpi)', {resolution: '100dpcm'})).to.be.true;
expect(mediaQuery.match('(min-resolution: 100dpcm)', {resolution: '253dpi'})).to.be.false;
expect(mediaQuery.match('(max-resolution: 100dpcm)', {resolution: '255dpi'})).to.be.false;
});
});

describe('Aspect Ratio Check', function () {
Expand Down