Skip to content

Instantly share code, notes, and snippets.

@boboidream
Last active December 7, 2023 02:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boboidream/329c2fa394f1b5e91b1345588288f045 to your computer and use it in GitHub Desktop.
Save boboidream/329c2fa394f1b5e91b1345588288f045 to your computer and use it in GitHub Desktop.
function camelize(str) {
return (str + "").replace(/-\D/g,
function(match) {
return match.charAt(1).toUpperCase();
});
}
camelize("border-bottom-color"); // "borderBottomColor"
function hyphenate(str) {
return (str + "").replace(/[A-Z]/g,
function(match) {
return "-" + match.toLowerCase();
});
}
hyphenate("borderBottomColor"); // "border-bottom-color"
// 格式化 size
_formatSize(size) {
let unitK = Math.round(size / 1024),
unitM = (size / 1048576).toFixed(1)
return unitM > 0.9 ? unitM + 'M' : unitK + 'K'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment