Created
May 7, 2018 08:22
-
-
Save tobiasdalhof/d54082e56d2ea49408f3d42c5ac59d52 to your computer and use it in GitHub Desktop.
Helper class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class DeliveryMessageHelper { | |
/** | |
* Get current URL without trailing slash. | |
* @returns {string} | |
*/ | |
static getCurrentURL () { | |
return window.location.origin + window.location.pathname | |
} | |
/** | |
* Remove trailing slash from string | |
* @param {string} string | |
*/ | |
static removeTrailingSlash (string) { | |
return string.replace(/\/+$/, '') | |
} | |
/** | |
* HTML to element. | |
* @param {String} htmlString | |
*/ | |
static createElementFromHTML (htmlString) { | |
const div = document.createElement('div') | |
div.innerHTML = htmlString.trim() | |
return div.childNodes | |
} | |
/** | |
* Add new element BEFORE another. | |
* @param {HTMLElement} newElement | |
* @param {HTMLElement} element | |
*/ | |
static addElementBefore (newElement, element) { | |
element.parentNode.insertBefore(newElement, element) | |
} | |
/** | |
* Add new element AFTER another. | |
* @param {HTMLElement} newElement | |
* @param {HTMLElement} element | |
*/ | |
static addElementAfter (newElement, element) { | |
element.parentNode.insertBefore(newElement, element.nextSibling) | |
} | |
/** | |
* Remove hashtags from string. | |
* @param {String} string | |
*/ | |
static removeHashtags (string) { | |
const regexp = new RegExp('#([^\\s]*)', 'g') | |
return string.replace(regexp, '') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment