summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-07 20:24:22 -0500
committerGitHub <noreply@github.com>2021-01-07 20:24:22 -0500
commit7d706df66b4cd68d6ac430c2e3e8b9f3a7f4b6ae (patch)
treea0d8e81f41555468a5c3b2b9b4d21e646adceea6
parent3760b22a2544d0f86a8097b345831de8efc0e325 (diff)
Update DictionaryDataUtil to be able to be used in a sandbox frame (#1206)
-rw-r--r--.eslintrc.json6
-rw-r--r--ext/mixed/js/dictionary-data-util.js30
2 files changed, 32 insertions, 4 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
index 4839447e..f9ca5814 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -84,7 +84,8 @@
{
"files": [
"ext/mixed/js/core.js",
- "ext/bg/js/template-renderer.js"
+ "ext/bg/js/template-renderer.js",
+ "ext/mixed/js/dictionary-data-util.js"
],
"env": {
"webextensions": false
@@ -94,7 +95,8 @@
"files": ["ext/**/*.js"],
"excludedFiles": [
"ext/mixed/js/core.js",
- "ext/bg/js/template-renderer.js"
+ "ext/bg/js/template-renderer.js",
+ "ext/mixed/js/dictionary-data-util.js"
],
"globals": {
"errorToJson": "readonly",
diff --git a/ext/mixed/js/dictionary-data-util.js b/ext/mixed/js/dictionary-data-util.js
index c049d591..8d8772fe 100644
--- a/ext/mixed/js/dictionary-data-util.js
+++ b/ext/mixed/js/dictionary-data-util.js
@@ -52,8 +52,8 @@ class DictionaryDataUtil {
const exclusiveExpressions = [];
const exclusiveReadings = [];
const resultExpressions = result.expressions;
- if (!areSetsEqual(resultExpressions, allExpressions)) {
- exclusiveExpressions.push(...getSetIntersection(resultExpressions, allExpressions));
+ if (!this._areSetsEqual(resultExpressions, allExpressions)) {
+ exclusiveExpressions.push(...this._getSetIntersection(resultExpressions, allExpressions));
}
if (multipleReadings) {
exclusiveReadings.push(result.reading);
@@ -71,6 +71,8 @@ class DictionaryDataUtil {
return results2;
}
+ // Private
+
static _findExistingPitchAccentInfo(reading, position, tags, pitchAccentInfoList) {
for (const pitchInfo of pitchAccentInfoList) {
if (
@@ -98,4 +100,28 @@ class DictionaryDataUtil {
return true;
}
+
+ static _areSetsEqual(set1, set2) {
+ if (set1.size !== set2.size) {
+ return false;
+ }
+
+ for (const value of set1) {
+ if (!set2.has(value)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ static _getSetIntersection(set1, set2) {
+ const result = [];
+ for (const value of set1) {
+ if (set2.has(value)) {
+ result.push(value);
+ }
+ }
+ return result;
+ }
}