@csstools/media-query-list-parser
TypeScript icon, indicating that this package has built-in type declarations

2.1.6 • Public • Published

Media Query List Parser

npm version Build Status Discord

Implemented from : https://www.w3.org/TR/mediaqueries-5/

Usage

Add Media Query List Parser to your project:

npm install @csstools/media-query-list-parser @csstools/css-parser-algorithms @csstools/css-tokenizer --save-dev

Media Query List Parser depends on our CSS tokenizer and parser algorithms. It must be used together with @csstools/css-tokenizer and @csstools/css-parser-algorithms.

import { parse } from '@csstools/media-query-list-parser';

export function parseCustomMedia() {
	const mediaQueryList = parse('screen and (min-width: 300px), (50px < height < 30vw)');

	mediaQueryList.forEach((mediaQuery) => {
		mediaQuery.walk((entry, index) => {
			// Index of the current Node in `parent`.
			console.log(index);
			// Type of `parent`.
			console.log(entry.parent.type);

			// Type of `node`
			{
				// Sometimes nodes can be arrays.
				if (Array.isArray(entry.node)) {
					entry.node.forEach((item) => {
						console.log(item.type);
					});
				}

				if ('type' in entry.node) {
					console.log(entry.node.type);
				}
			}

			// stringified version of the current node.
			console.log(entry.node.toString());

			// Return `false` to stop the walker.
			return false;
		});
	});
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.0.22,188,016latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.22,188,016
4.0.133,576
4.0.010,805
3.0.1571,600
3.0.045,081
2.1.13945,380
2.1.1216,950
2.1.11172,539
2.1.1082
2.1.9138,058
2.1.875,980
2.1.7199,580
2.1.617,480
2.1.5145,344
2.1.474,144
2.1.325,098
2.1.254,813
2.1.120,885
2.1.010,613
2.0.428,030
2.0.317
2.0.212,610
2.0.170,433
2.0.0751
1.0.01,246

Package Sidebar

Install

npm i @csstools/media-query-list-parser@2.1.6

Version

2.1.6

License

MIT

Unpacked Size

115 kB

Total Files

7

Last publish

Collaborators

  • romainmenke
  • alaguna
  • jonathantneal