Skip to content

Instantly share code, notes, and snippets.

@shakhzodkudratov
Created January 9, 2022 01:31
Show Gist options
  • Save shakhzodkudratov/3df1a52156e35d2beab56f6899b1ae07 to your computer and use it in GitHub Desktop.
Save shakhzodkudratov/3df1a52156e35d2beab56f6899b1ae07 to your computer and use it in GitHub Desktop.
convert base font-size: 10px; rem to base font-size: 16px; rem
code = `` // put your code here
index = 0
while (index > -1) {
regex = /(\d+|\d*\.\d+)rem/g
result = regex.exec(code.slice(index))
if (result == null) {
index = -1
} else {
index = result.index + code.slice(0, index).length
codeBefore = code.slice(0, index)
codeAfter = code.slice(index + result[0].length)
number = parseFloat(result[1])
number = number * 10 / 16 // rem -> base 10px -> base 16px
code = codeBefore + number + 'rem' + codeAfter
index += number.toString().length + 3
}
}
console.log(code) // copy from browser console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment