@sealcode/autosizes-parser
v0.0.1
Published
A module for generating sizes strings for responsive images based on measurement data.
Readme
Autosizes Parse
This module generates a sizes string for responsive images based on measurement data. It analyzes the measurements and generates a sizes string that describes the behavior of the image's sizes attribute.
Installation
Make sure you have Node.js version 17 or later installed. You can install the package using npm:
npm install @sealcode/autosizes-parserUsage
You can import the generateSizes function from the module and use it to generate the sizes string based on your measurement data.
import generateSizes from '@sealcode/autosizes-parse';
import data from './data/measurement.json'; // measurement data path
const sizesString = generateSizes(data);
console.log(sizesString);Example output:
(max-width: 400px) calc(100vw / -2 + 480px), (max-width: 600px) calc(100vw / -2 + 602px), (max-width: 880px) calc(100vw / 4 - 40px), 440pxFile Structure
The module is structured as follows:
src/
└── autosizeparse.ts # Module implementation
└── autosizeparse.test.ts # Test suite for the module
└── index.ts # Export of generateSizes function
data/
└── test.json # Example test data in JSON formatRunning Tests
Tests ensure that the module functions correctly. You can run the tests using the following command:
npm test