unitflip
v1.4.1
Published
A Javascript library for converting CSS units.
Downloads
36
Maintainers
Readme
Unitflip
A Javascript library for converting CSS units (e.g., px, rem, em, %) into other CSS units.
Installation
using NPM
npm install unitflipusing CDN
// ES6 Syntax
import unitFlip from "https://unpkg.com/unitflip@latest/dist/index.esm.mjs";
// Common JS
const unitFlip = require("https://unpkg.com/unitflip@latest/dist/index.cjs");using embedded CDN
<script src="https://unpkg.com/unitflip@latest/dist/index.umd.js"></script>Usage
import unitFlip from "unitflip";
// converts 16px to rem with default precision and props
unitFlip(16, "px", "rem"); // 1rem
// converts 16vw into px with a precision of 2 and with a viewPortWidth set to 1280
unitFlip(16, "px", "vw", 2, { viewPortWidth: 1280 }); // 1.25Development
Running the Test
npm run testBreak Down into End to End Test
these unit test are for checking if the conversion function is returning the right conversion value.
- focus on individual functions of unitFlip.
- test cases cover common scenarios.
- Framework: Jest
import unitFlip from "unitflip";
it("should return 1", () => {
// value, sourceUnit, targetUnit
expect(unitFlip(16, "px", "rem")).toBe(1);
});Running Locally
- Clone the repository:
git clone https://github.com/zshaian/unitflip.git- Install dependencies:
npm install- Dev Mode:
npm run dev- Build:
npm run buildThis generates a dist/ folder with the production ready files.
Contributing
Please read CONTRIBUTING for the process of submitting pull request or creating an issue.
Code of Conduct
Please read CODE OF CONDUCT for details on our code of conduct.
Built With
Versioning
SemVer for versioning. For the versions available, see the Repo Tags
License
This project is licensed under the MIT License. See the LICENSE file for more details.
