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 { export default class Input {
constructor({ element, type, classNames, placeholderValue }) { constructor({ element, type, classNames, placeholderValue }) {
@ -25,7 +25,7 @@ export default class Input {
} }
get value() { get value() {
return escape(this.element.value); return stripHTML(this.element.value);
} }
addEventListeners() { addEventListeners() {

View file

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

View file

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