Skip to content

Commit

Permalink
Add IE11 support using minimal polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnorris committed Aug 26, 2017
1 parent 5eb9357 commit 9ed9eb0
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/striptags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

(function (global) {

// minimal symbol polyfill for IE11 and others
if (typeof Symbol !== 'function') {
var Symbol = function(name) {
return name;
}

Symbol.nonNative = true;
}

const STATE_PLAINTEXT = Symbol('plaintext');
const STATE_HTML = Symbol('html');
const STATE_COMMENT = Symbol('comment');
Expand Down Expand Up @@ -36,8 +45,8 @@
allowable_tags = parse_allowable_tags(allowable_tags);

return {
allowable_tags,
tag_replacement,
allowable_tags : allowable_tags,
tag_replacement: tag_replacement,

state : STATE_PLAINTEXT,
tag_buffer : '',
Expand Down Expand Up @@ -179,21 +188,28 @@
}

function parse_allowable_tags(allowable_tags) {
let tags_array = [];
let tag_set = new Set();

if (typeof allowable_tags === 'string') {
let match;

while ((match = ALLOWED_TAGS_REGEX.exec(allowable_tags)) !== null) {
tags_array.push(match[1]);
while ((match = ALLOWED_TAGS_REGEX.exec(allowable_tags))) {
tag_set.add(match[1]);
}
}

else if (typeof allowable_tags[Symbol.iterator] === 'function') {
tags_array = allowable_tags;
else if (!Symbol.nonNative &&
typeof allowable_tags[Symbol.iterator] === 'function') {

tag_set = new Set(allowable_tags);
}

else if (typeof allowable_tags.forEach === 'function') {
// IE11 compatible
allowable_tags.forEach(tag_set.add, tag_set);
}

return new Set(tags_array);
return tag_set;
}

function normalize_tag(tag_buffer) {
Expand Down

0 comments on commit 9ed9eb0

Please sign in to comment.