@point-api/dropdown-react
Version:
HOC to add a Point API autocomplete dropdown
56 lines • 1.64 kB
JavaScript
/**
* Get the line height of an HTMLElement
* @param element - the target element
* @returns the line height in px
*/
export function getLineHeight(element) {
let temp = document.createElement(element.nodeName);
temp.setAttribute("style", "margin:0px;padding:0px;font-family:" +
element.style.fontFamily +
";font-size:" +
element.style.fontSize);
temp.innerHTML = "test";
if (element.parentNode != null) {
temp = element.parentNode.appendChild(temp);
if (temp.parentNode != null) {
const ret = temp.clientHeight;
temp.parentNode.removeChild(temp);
return ret;
}
}
return 0;
}
/**
* Search a block of text and return all matched text
* @param re - the RegEx to match text against
* @param text - the block to search
* @returns a list of the found RegEx matches
*/
export function matchAll(re, text) {
if (!re.global) {
throw new Error("Supplied non global regular expression to matchAll function");
}
const matches = [];
let match;
// tslint:disable-next-line:no-conditional-assignment
while ((match = re.exec(text))) {
matches.push(match);
}
return matches;
}
/*
matches:
(not (whitespace leading character or end puctionation))
(most characters except for newline)
(EOL)
*/
export const CONTENT_REGEX = /[^(\s.?!)*]([^.?!]*)($)/gmu;
/*
matches:
colon trigger followed by any chars except space
*/
export const NAME_REGEX = /(:$|:(?=[^:]*))([^.?!]*)/gmu;
export function getOrigin() {
return window.location.href.split('/')[2];
}
//# sourceMappingURL=Utils.js.map