The `metaviewport-parser` library, currently at version 0.3.0, provides a robust parser and interpreter for the `content` attribute within HTML `<meta name="viewport">` declarations. It implements the algorithms specified in the W3C CSS Device Adaption specification, enabling developers to programmatically analyze and understand how viewport configurations affect rendering. The library offers `parseMetaViewPortContent` to break down the attribute string into valid, unknown, and invalid properties, and `getRenderingDataFromViewport` to interpret these properties against supplied browser dimensions to calculate initial width, height, zoom, and user-scalability. As a pre-1.0 package, its API should be considered experimental and may undergo changes. Its key differentiator is strict adherence to web standards for accurate viewport parsing, making it valuable for server-side rendering, testing tools, or dynamic content adaptation logic.
npm install metaviewport-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a meta viewport content string and interpreting its valid properties into rendering data based on provided device dimensions.
Always review the changelog when updating minor versions. Consider pinning to exact patch versions if stability is critical.
For ESM projects, consider using a CommonJS wrapper or a bundler like Webpack/Rollup that can handle CJS modules. Alternatively, use dynamic `import('metaviewport-parser')` if available in your runtime.Ensure all required parameters are passed as the second argument to `getRenderingDataFromViewport` and accurately reflect the target browser's environment.
If running in a Node.js ESM project, ensure your file uses `.cjs` extension for CommonJS, or use `import()` dynamic import with `const metaparser = await import('metaviewport-parser');`.Ensure you are using `const metaparser = require('metaviewport-parser');` or a similar CommonJS-compatible import that correctly assigns the module's exports to `metaparser`.No dependency data recorded yet.