Skip to content

Commit

Permalink
Move more functions to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
skoshy committed Jan 9, 2017
1 parent 3cacb3e commit 3925449
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
38 changes: 0 additions & 38 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,32 +630,6 @@ function prepTemperature(fahr) {
}
}

function convertLinebreaksToBrs(text) {
return text.replace(/(?:\r\n|\r|\n)/g, "<br>");
}

function convertBrsToLinebreaks(text) {
return text.replace(/<\s*br.*?>/g, "\n");
}

function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
let newlineDelim = '%%%%%html_decode_newline%%%%%';
let pattern = new RegExp(newlineDelim, 'g');
return $('<div/>').text(
value.replace(/(?:\r\n|\r|\n)/g, newlineDelim)
).html().replace(pattern, "\n");
}

function htmlDecode(value) {
let newlineDelim = '%%%%%html_decode_newline%%%%%';
let pattern = new RegExp(newlineDelim, 'g');
return $('<div/>').html(
value.replace(/(?:\r\n|\r|\n)/g, newlineDelim)
).text().replace(pattern, "\n");
}

function getAndUpdateWeather(location, isUsingWeatherId) {
console.log("Getting weather...");

Expand Down Expand Up @@ -714,18 +688,6 @@ function updateWeatherDisplay() {
}
}

function getDomainFromUrl(url) {
return url.split('/')[url.indexOf('//') < 0 ? 0 : 2].split(/[\/?:#&]/)[0]
};

function getRandomRgb() {
let toReturn = [];
for (let i = 0; i < 3; i++) {
toReturn.push(Math.floor(Math.random() * 256));
}
return toReturn;
}

function getSelectionText() {
let text = "";
let activeEl = document.activeElement;
Expand Down
38 changes: 38 additions & 0 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,42 @@ function versionCompare(v1, v2, options) {
}

return 0;
}

function getDomainFromUrl(url) {
return url.split('/')[url.indexOf('//') < 0 ? 0 : 2].split(/[\/?:#&]/)[0]
};

function getRandomRgb() {
let toReturn = [];
for (let i = 0; i < 3; i++) {
toReturn.push(Math.floor(Math.random() * 256));
}
return toReturn;
}

function convertLinebreaksToBrs(text) {
return text.replace(/(?:\r\n|\r|\n)/g, "<br>");
}

function convertBrsToLinebreaks(text) {
return text.replace(/<\s*br.*?>/g, "\n");
}

function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
let newlineDelim = '%%%%%html_decode_newline%%%%%';
let pattern = new RegExp(newlineDelim, 'g');
return $('<div/>').text(
value.replace(/(?:\r\n|\r|\n)/g, newlineDelim)
).html().replace(pattern, "\n");
}

function htmlDecode(value) {
let newlineDelim = '%%%%%html_decode_newline%%%%%';
let pattern = new RegExp(newlineDelim, 'g');
return $('<div/>').html(
value.replace(/(?:\r\n|\r|\n)/g, newlineDelim)
).text().replace(pattern, "\n");
}

0 comments on commit 3925449

Please sign in to comment.