forked from tanner/qotnews
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
589 B
25 lines
589 B
import createDOMPurify from 'dompurify'; |
|
import { JSDOM } from 'jsdom'; |
|
|
|
export const purify = (story, DOMPurify) => { |
|
if (!DOMPurify) { |
|
DOMPurify = createDOMPurify(new JSDOM('').window); |
|
} |
|
if (story.title) { |
|
story.title = DOMPurify.sanitize(story.title); |
|
} |
|
if (story.text) { |
|
story.text = DOMPurify.sanitize(story.text); |
|
} |
|
return story; |
|
}; |
|
|
|
export const purifyArray = (array, DOMPurify) => { |
|
if (array instanceof Array) { |
|
if (!DOMPurify) { |
|
DOMPurify = createDOMPurify(new JSDOM('').window); |
|
} |
|
return array.map(story => purify(story, DOMPurify)); |
|
} |
|
return array; |
|
}; |