Skip to content

Commit

Permalink
Merge pull request #1 from ArthurArakelyan/1.0.1
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
ArthurArakelyan authored Jun 19, 2024
2 parents 4e1ba54 + 4632c29 commit fc10294
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 1,400 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Arthur Arakelyan
Copyright (c) 2024 Arthur Arakelyan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# css-unit-converter-js

[![NPM Monthly Downloads](https://img.shields.io/npm/dm/css-unit-converter-js?label=montly%20downloads)](https://img.shields.io/npm/dw/css-unit-converter-js)
[![NPM Total Downloads](https://img.shields.io/npm/dt/css-unit-converter-js?label=total%20downloads)](https://img.shields.io/npm/dw/css-unit-converter-js)
[![NPM version](https://img.shields.io/npm/v/css-unit-converter-js)](https://www.npmjs.com/package/css-unit-converter-js)
[![GitHub code size in bytes](https://img.shields.io/bundlephobia/min/css-unit-converter-js?style=flat)](https://www.npmjs.com/package/css-unit-converter-js)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/ArthurArakelyan/css-unit-converter-js/blob/main/LICENSE)
Expand Down Expand Up @@ -67,6 +69,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| pxToIn | px |
| pxToPc | px |
| pxToCm | px |
| pxToMm | px |
| remToPx | rem, remSize |
| remToEm | rem, remSize, emSize |
| remToVw | rem, remSize, viewportWidth |
Expand All @@ -75,6 +78,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| remToIn | rem, remSize |
| remToPc | rem, remSize |
| remToCm | rem, remSize |
| remToMm | rem, remSize |
| emToPx | em, emSize |
| emToRem | em, emSize, remSize |
| emToVw | em, emSize, viewportWidth |
Expand All @@ -83,6 +87,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| emToIn | em, emSize |
| emToPc | em, emSize |
| emToCm | em, emSize |
| emToMm | em, emSize |
| vwToPx | vw, viewportWidth |
| vwToRem | vw, viewportWidth, remSize |
| vwToEm | vw, viewportWidth, emSize |
Expand All @@ -91,6 +96,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| vwToIn | vw, viewportWidth |
| vwToPc | vw, viewportWidth |
| vwToCm | vw, viewportWidth |
| vwToMm | vw, viewportWidth |
| vhToPx | vh, viewportHeight |
| vhToRem | vh, viewportHeight, remSize |
| vhToEm | vh, viewportHeight, emSize |
Expand All @@ -99,6 +105,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| vhToIn | vh, viewportHeight |
| vhToPc | vh, viewportHeight |
| vhToCm | vh, viewportHeight |
| vhToMm | vh, viewportHeight |
| ptToPx | pt |
| ptToRem | pt, remSize |
| ptToEm | pt, emSize |
Expand All @@ -107,6 +114,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| ptToIn | pt |
| ptToPc | pt |
| ptToCm | pt |
| ptToMm | pt |
| inToPx | inch |
| inToRem | inch, remSize |
| inToEm | inch, emSize |
Expand All @@ -115,6 +123,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| inToPt | inch |
| inToPc | inch |
| inToCm | inch |
| inToMm | inch |
| pcToPx | pc |
| pcToRem | pc, remSize |
| pcToEm | pc, emSize |
Expand All @@ -123,6 +132,7 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| pcToPt | pc |
| pcToIn | pc |
| pcToCm | pc |
| pcToMm | pc |
| cmToPx | cm |
| cmToRem | cm, remSize |
| cmToEm | cm, emSize |
Expand All @@ -131,6 +141,20 @@ pxToVw(23, 1920, { fraction: false }); // => 1.1979166666666667
| cmToPt | cm |
| cmToIn | cm |
| cmToPc | cm |
| cmToMm | cm |
| mmToPx | mm |
| mmToRem | mm, remSize |
| mmToEm | mm, emSize |
| mmToVw | mm, viewportWidth |
| mmToVh | mm, viewportHeight |
| mmToPt | mm |
| mmToIn | mm |
| mmToPc | mm |
| mmToCm | mm |

## Communities

[![Reddit](https://img.shields.io/badge/Reddit-FF4500?style=for-the-badge&logo=reddit&logoColor=white)](https://www.reddit.com/r/cssunitconverter/)

## Contributing

Expand Down
188 changes: 188 additions & 0 deletions src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export const pxToCm = (px: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion(px * 0.0264583333, options);
};

/**
* Converts **px** to **mm**
* @param px The number of **px** for converting to mm
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const pxToMm = (px: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion(px * 0.2645833333, options);
};

/**
* Converts **rem** to **px** based on given **remSize**
* @param rem The number of **rem** for converting to px
Expand Down Expand Up @@ -176,6 +186,17 @@ export const remToCm = (rem: number, remSize = 16, options: ConverterOptions = {
return applyOptionsOnConversion((rem * remSize) * 0.0264583333, options);
};

/**
* Converts **rem** to **mm** based on given **remSize**
* @param rem The number of **rem** for converting to mm
* @param remSize The size of **1 rem** in pixels. By default, **16**
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const remToMm = (rem: number, remSize = 16, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((rem * remSize) * 0.2645833333, options);
};

/**
* Converts **em** to **px** based on given **emSize**
* @param em The number of **em** for converting to px
Expand Down Expand Up @@ -267,6 +288,17 @@ export const emToCm = (em: number, emSize = 16, options: ConverterOptions = {}):
return applyOptionsOnConversion((em * emSize) * 0.0264583333, options);
};

/**
* Converts **em** to **mm** based on given **emSize**
* @param em The number of **em** for converting to mm
* @param emSize The size of **1 em** in pixels. By default, **16**
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const emToMm = (em: number, emSize = 16, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((em * emSize) * 0.2645833333, options);
};

/**
* Converts **vw** to **px** based on given **viewportWidth**
* @param vw The number of **vw** for converting to px
Expand Down Expand Up @@ -358,6 +390,17 @@ export const vwToCm = (vw: number, viewportWidth: number, options: ConverterOpti
return applyOptionsOnConversion((vw * viewportWidth / 100) * 0.0264583333, options);
};

/**
* Converts **vw** to **mm** based on given **viewportWidth**
* @param vw The number of **vw** for converting to mm
* @param viewportWidth The size of viewport width in pixels
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const vwToMm = (vw: number, viewportWidth: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((vw * viewportWidth / 100) * 0.2645833333, options);
};

/**
* Converts **vh** to **px** based on given **viewportHeight**
* @param vh The number of **vh** for converting to px
Expand Down Expand Up @@ -449,6 +492,17 @@ export const vhToCm = (vh: number, viewportHeight: number, options: ConverterOpt
return applyOptionsOnConversion((vh * viewportHeight / 100) * 0.0264583333, options);
};

/**
* Converts **vh** to **mm** based on given **viewportHeight**
* @param vh The number of **vh** for converting to mm
* @param viewportHeight The size of viewport height in pixels
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const vhToMm = (vh: number, viewportHeight: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((vh * viewportHeight / 100) * 0.2645833333, options);
};

/**
* Converts **pt** to **px**
* @param pt The number of **pt** for converting to px
Expand Down Expand Up @@ -533,6 +587,16 @@ export const ptToCm = (pt: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((pt * 1.3333343412075) * 0.0264583333, options);
};

/**
* Converts **pt** to **mm**
* @param pt The number of **pt** for converting to mm
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const ptToMm = (pt: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((pt * 1.3333343412075) * 0.2645833333, options);
};

/**
* Converts **in** to **px**
* @param inch The number of **in** for converting to px
Expand Down Expand Up @@ -617,6 +681,16 @@ export const inToCm = (inch: number, options: ConverterOptions = {}): number =>
return applyOptionsOnConversion((inch * 96) * 0.0264583333, options);
};

/**
* Converts **in** to **mm**
* @param inch The number of **in** for converting to mm
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const inToMm = (inch: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((inch * 96) * 0.2645833333, options);
};

/**
* Converts **pc** to **px**
* @param pc The number of **pc** for converting to px
Expand Down Expand Up @@ -701,6 +775,16 @@ export const pcToCm = (pc: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((pc * 16) * 0.0264583333, options);
};

/**
* Converts **pc** to **mm**
* @param pc The number of **pc** for converting to mm
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const pcToMm = (pc: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((pc * 16) * 0.2645833333, options);
};

/**
* Converts **cm** to **px**
* @param cm The number of **cm** for converting to px
Expand Down Expand Up @@ -784,3 +868,107 @@ export const cmToIn = (cm: number, options: ConverterOptions = {}): number => {
export const cmToPc = (cm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((cm * 37.7952755906) * 0.0625, options);
};

/**
* Converts **cm** to **mm**
* @param cm The number of **cm** for converting to mm
* @param options Conversion options object
* @returns {number} A number converted to **mm**
*/
export const cmToMm = (cm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((cm * 37.7952755906) * 0.2645833333, options);
};

/**
* Converts **mm** to **px**
* @param mm The number of **mm** for converting to px
* @param options Conversion options object
* @returns {number} A number converted to **px**
*/
export const mmToPx = (mm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion(mm * 3.7795275591, options);
};

/**
* Converts **mm** to **rem** based on given **remSize**
* @param mm The number of **mm** for converting to rem
* @param remSize The size of **1 rem** in pixels. By default, **16**
* @param options Conversion options object
* @returns {number} A number converted to **rem**
*/
export const mmToRem = (mm: number, remSize = 16, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((mm * 3.7795275591) / remSize, options);
};

/**
* Converts **mm** to **em** based on given **emSize**
* @param mm The number of **mm** for converting to em
* @param emSize The size of **1 em** in pixels. By default, **16**
* @param options Conversion options object
* @returns {number} A number converted to **em**
*/
export const mmToEm = (mm: number, emSize = 16, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((mm * 3.7795275591) / emSize, options);
};

/**
* Converts **mm** to **vw** based on given **viewportWidth**
* @param mm The number of **mm** for converting to vw
* @param viewportWidth The size of viewport width in pixels
* @param options Conversion options object
* @returns {number} A number converted to **vw**
*/
export const mmToVw = (mm: number, viewportWidth: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion(((mm * 3.7795275591) / viewportWidth) * 100, options);
};

/**
* Converts **cm** to **vh** based on given **viewportHeight**
* @param cm The number of **cm** for converting to vh
* @param viewportHeight The size of viewport height in pixels
* @param options Conversion options object
* @returns {number} A number converted to **vh**
*/
export const mmToVh = (cm: number, viewportHeight: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion(((cm * 3.7795275591) / viewportHeight) * 100, options);
};

/**
* Converts **mm** to **pt**
* @param mm The number of **mm** for converting to pt
* @param options Conversion options object
* @returns {number} A number converted to **pt**
*/
export const mmToPt = (mm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((mm * 3.7795275591) * 0.74999943307122, options);
};

/**
* Converts **mm** to **in**
* @param mm The number of **mm** for converting to in
* @param options Conversion options object
* @returns {number} A number converted to **in**
*/
export const mmToIn = (mm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((mm * 3.7795275591) / 96, options);
};

/**
* Converts **mm** to **pc**
* @param mm The number of **mm** for converting to pc
* @param options Conversion options object
* @returns {number} A number converted to **pc**
*/
export const mmToPc = (mm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((mm * 3.7795275591) * 0.0625, options);
};

/**
* Converts **mm** to **cm**
* @param mm The number of **mm** for converting to cm
* @param options Conversion options object
* @returns {number} A number converted to **cm**
*/
export const mmToCm = (mm: number, options: ConverterOptions = {}): number => {
return applyOptionsOnConversion((mm * 3.7795275591) * 0.0264583333, options);
};
Loading

0 comments on commit fc10294

Please sign in to comment.