Skip to content

Instantly share code, notes, and snippets.

@Decad
Created October 24, 2013 17:07
Show Gist options
  • Save Decad/7141140 to your computer and use it in GitHub Desktop.
Save Decad/7141140 to your computer and use it in GitHub Desktop.
Font Awesome Upgrade 3.x - 4.0
/*
* Quickly made upgrade script from running through html files and replacing old font awesome classes with new. Be warned will make changes to any icon-* classes
*
* Author: Declan Cook
* Usage: node faupgrade.js <htmlfile>
*/
var fs = require('fs'),
lookup = {"ban-circle":"ban","bar-chart":"bar-chart-o","beaker":"flask","bell":"bell-o","bell-alt":"bell","bitbucket-sign":"bitbucket-square","bookmark-empty":"bookmark-o","calendar-empty":"calendar-o","check":"check-square-o","check-empty":"square-o","check-minus":"minus-square-o","check-sign":"check-square","chevron-sign-down":"chevron-circle-down","chevron-sign-left":"chevron-circle-left","chevron-sign-right":"chevron-circle-right","chevron-sign-up":"chevron-circle-up","circle-arrow-down":"arrow-circle-down","circle-arrow-left":"arrow-circle-left","circle-arrow-right":"arrow-circle-right","circle-arrow-up":"arrow-circle-up","circle-blank":"circle-o","collapse":"caret-square-o-down","collapse-alt":"collapse-o","collapse-top":"caret-square-o-up","comment-alt":"comment-o","comments-alt":"comments-o","copy":"files-o","cut":"scissors","dashboard":"tachometer","double-angle-down":"angle-double-down","double-angle-left":"angle-double-left","double-angle-right":"angle-double-right","double-angle-up":"angle-double-up","download":"arrow-circle-o-down","download-alt":"download","edit":"pencil-square-o","edit-sign":"pencil-square","envelope-alt":"envelope-o","exclamation-sign":"exclamation-circle","expand":"caret-square-o-right","expand-alt":"expand-o","external-link-sign":"external-link-square","eye-close":"eye-slash","eye-open":"eye","facebook-sign":"facebook-square","facetime-video":"video-camera","file-alt":"file-o","file-text-alt":"file-text-o","flag-alt":"flag-o","folder-close":"folder","folder-close-alt":"folder-o","folder-open-alt":"folder-open-o","food":"cutlery","frown":"frown-o","github-sign":"github-square","google-plus-sign":"google-plus-square","hand-down":"hand-o-down","hand-left":"hand-o-left","hand-right":"hand-o-right","hand-up":"hand-o-up","heart-empty":"heart-o","h-sign":"h-square","indent-left":"outdent","indent-right":"indent","info-sign":"info-circle","keyboard":"keyboard-o","legal":"gavel","lemon":"lemon-o","lightbulb":"lightbulb-o","linkedin-sign":"linkedin-square","meh":"meh-o","microphone-off":"microphone-slash","minus-sign":"minus-circle","minus-sign-alt":"minus-square","mobile-phone":"mobile","moon":"moon-o","off":"power-off","ok":"check","ok-circle":"check-circle-o","ok-sign":"check-circle","paper-clip":"paperclip","paste":"clipboard","phone-sign":"phone-square","picture":"picture-o","pinterest-sign":"pinterest-square","play-circle":"play-circle-o","play-sign":"play-circle","plus-sign":"plus-circle","plus-sign-alt":"plus-square","pushpin":"thumb-tack","question-sign":"question-circle","remove":"times","remove-circle":"times-circle-o","remove-sign":"times-circle","rss-sign":"rss-square","save":"floppy-o","screenshot":"crosshairs","share":"share-square-o","share-alt":"share","share-sign":"share-square","sign-blank":"square","signin":"sign-in","signout":"sign-out","smile":"smile-o","sort-by-alphabet":"sort-alpha-asc","sort-by-alphabet-alt":"sort-alpha-desc","sort-by-attributes":"sort-amount-asc","sort-by-attributes-alt":"sort-amount-desc","sort-by-order":"sort-numeric-asc","sort-by-order-alt":"sort-numeric-desc","sort-down":"sort-asc","sort-up":"sort-desc","star-empty":"star-o","star-half-empty":"star-half-o","sun":"sun-o","thumbs-down-alt":"thumbs-o-down","thumbs-up-alt":"thumbs-o-up","time":"clock-o","trash":"trash-o","tumblr-sign":"tumblr-square","twitter-sign":"twitter-square","unlink":"chain-broken","unlock-alt":"unlock-o","upload":"arrow-circle-o-up","upload-alt":"upload","warning-sign":"exclamation-triangle","xing-sign":"xing-square","youtube-sign":"youtube-square","zoom-in":"search-plus","zoom-out":"search-minus"},
replacements = 0;
if(! process.argv[2]) throw "No file specified"
fs.readFile(process.argv[2], 'UTF-8', function(err, data){
if(err) throw err
output = upgradeFA(data);
fs.writeFile(process.argv[2], output, function (err) {
if (err) throw err;
console.log(replacements + " replacements made")
});
})
function upgradeFA(string) {
return string.replace(/class=".*?"/g, function(str, g0){
if(str.indexOf('icon') === -1) return str;
return str.replace(/("|\s)icon([-|\w]+)/g, function(str1, g0, g1){
replacements++;
return g0+ 'fa' + (lookup[g1.substr(1)] ? "-"+lookup[g1.substr(1)] : g1)
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment