Skip to content

support "min-width: 0" expression on mobile-first sort #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2022
Merged
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
12 changes: 10 additions & 2 deletions lib/create-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ const maxValue = Number.MAX_VALUE;
* @param {string} length
* @return {number}
*/
function _getQueryLength(length) {
length = /(-?\d*\.?\d+)(ch|em|ex|px|rem)/.exec(length);
function _getQueryLength(query) {
let length = /(-?\d*\.?\d+)(ch|em|ex|px|rem)/.exec(query);

if (length === null && (isMinWidth(query) || isMinHeight(query))) {
length = /(\d)/.exec(query);
}

if (length === '0') {
return 0;
}

if (length === null) {
return maxValue;
Expand Down
11 changes: 11 additions & 0 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ test(`simple #2. desktop-first`, () => {
expect(received).toBe(expected);
});

test(`simple #3. mobile-first`, () => {
const receivedOrder = ['screen and (min-width: 640px)', 'screen and (min-width: 0)'];

const expectedOrder = ['screen and (min-width: 0)', 'screen and (min-width: 640px)'];

const expected = expectedOrder.join('\n');
const received = receivedOrder.sort(sortCSSmq).join('\n');

expect(received).toBe(expected);
});

test(`without dimension #1. mobile-first`, () => {
const receivedOrder = [
'tv',
Expand Down