Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// We must use a variable here, otherwise webpack attempts to include it in the bundle.
// If that happens and the module does not exist, it will throw a warning.
// https://github.com/webpack/webpack/issues/8826
// https://github.com/webpack/webpack/issues/4175
const requireFunc =
// eslint-disable-next-line @typescript-eslint/camelcase
typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
testData = requireFunc('emojibase-test-utils/test-data.json');
} catch {
testData = [];
}
request = Promise.resolve(testData);
} else {
request = fetchFromCDN(`${locale}/${set}.json`, version);
}
promises.set(
key,
request.then(response => {
const instance = EmojiDataManager.getInstance(locale);
instance.parseEmojiData(response);
return instance.getData();
}),
);
return promises.get(key)!;
}
// Abort as we've already loaded data
if (loaded.has(key) || emojis.length > 0) {
this.setEmojis(emojis);
return Promise.resolve();
}
// Or hook into the promise if we're loading
if (promise.has(key)) {
return promise.get(key)!.then(() => {
this.setEmojis();
});
}
// Otherwise, start loading emoji data from the CDN
const request = fetchFromCDN(`${locale}/${set}.json`, version)
.then(response => {
loaded.add(key);
this.getDataInstance().parseEmojiData(response);
this.setEmojis();
})
.catch(error => {
loaded.add(key);
if (throwErrors) {
throw error;
}
});
promise.set(key, request);