Avoid name conflict with stripHTML

This commit is contained in:
Josh Johnson 2018-05-28 15:46:24 +01:00
parent 9dbb2e9733
commit 67e1940232
3 changed files with 6 additions and 6 deletions

View file

@ -1,4 +1,4 @@
import { calcWidthOfInput, escape } from '../lib/utils';
import { calcWidthOfInput, stripHTML } from '../lib/utils';
export default class Input {
constructor({ element, type, classNames, placeholderValue }) {
@ -25,7 +25,7 @@ export default class Input {
}
get value() {
return escape(this.element.value);
return stripHTML(this.element.value);
}
addEventListeners() {

View file

@ -1,4 +1,4 @@
import { escape } from './lib/utils';
import { stripHTML } from './lib/utils';
export const DEFAULT_CLASSNAMES = {
containerOuter: 'choices',
@ -63,7 +63,7 @@ export const DEFAULT_CONFIG = {
noChoicesText: 'No choices to choose from',
itemSelectText: 'Press to select',
uniqueItemText: 'Only unique values can be added.',
addItemText: value => `Press Enter to add <b>"${escape(value)}"</b>`,
addItemText: value => `Press Enter to add <b>"${stripHTML(value)}"</b>`,
maxItemText: maxItemCount => `Only ${maxItemCount} values can be added.`,
itemComparer: (choice, item) => choice === item,
fuseOptions: {

View file

@ -189,7 +189,7 @@ export const isScrolledIntoView = (el, parent, direction = 1) => {
* @param {String} html Initial string/html
* @return {String} Sanitised string
*/
export const escape = html =>
export const stripHTML = html =>
html.replace(/&/g, '&amp;')
.replace(/>/g, '&rt;')
.replace(/</g, '&lt;')
@ -235,7 +235,7 @@ export const calcWidthOfInput = (input, callback) => {
let width = input.offsetWidth;
if (value) {
const testEl = strToEl(`<span>${escape(value)}</span>`);
const testEl = strToEl(`<span>${stripHTML(value)}</span>`);
testEl.style.position = 'absolute';
testEl.style.padding = '0';
testEl.style.top = '-9999px';