30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
import htmlTags from '../json/html-tags.json' with { type: 'json' };
|
|
import htmlVoidTags from '../json/html-tags-void.json' with { type: 'json' };
|
|
|
|
const browser = bowser.getParser(window.navigator.userAgent).getBrowserName();
|
|
|
|
export let unifiedTagCollection = [];
|
|
|
|
if (browser === "Chrome") {
|
|
unifiedTagCollection = [...htmlTags, ...htmlVoidTags];
|
|
} else if (browser === "Firefox") {
|
|
const htmlTags = await fetchMultipleJsonUrls([
|
|
`${window.location.origin}/json/html-tags.json`,
|
|
`${window.location.origin}/json/html-tags-void.json`
|
|
]);
|
|
|
|
unifiedTagCollection = [...htmlTags];
|
|
} else {
|
|
unifiedTagCollection = [...htmlTags, ...htmlVoidTags];
|
|
}
|
|
|
|
export default function isValidTag(tag) {
|
|
return unifiedTagCollection.includes(tag);
|
|
}
|
|
|
|
/** @returns {Promise<string[]>} */
|
|
async function fetchMultipleJsonUrls(urls) {
|
|
const responses = await Promise.all(urls.map(url => fetch(url)));
|
|
const jsonArrays = await Promise.all(responses.map(response => response.json()));
|
|
return jsonArrays.flat();
|
|
} |