2 // 1pc -> 12pt -> 1/6in -> 16px
6 // 1ex -> 7.16px (useful, right?!)
7 // 1em -> 16px - we'll just use pc for this instead
8 // 1q -> 100/106 px <-- this is a bad bad number, so, if we've already got q, we probably won't do anything with 'em'
21 function getShortestUnit(length,unit) {
22 cur_string = `${length}${unit}`;
24 if (pixel_lengths.hasOwnProperty(unit)) {
25 pixel_length = length * pixel_lengths[unit];
30 for (unit in pixel_lengths) {
31 if (pixel_lengths.hasOwnProperty(unit)) {
32 new_len = pixel_length / pixel_lengths[unit];
33 new_string = `${new_len}${unit}`;
34 if (new_string.length < cur_string.length) {
35 cur_string = new_string;
42 // REQUIRED: A `run` function thats takes in current code and returns processed code.
44 // `code` is your current code in the editor
45 var processedCode = code.replace(/(\d+)(vw|vh|pc|px|in|ex|em)/g, (match, $1,$2) => {
46 return getShortestUnit($1,$2);
49 // Return the final code