summaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-09-19 20:17:58 -0700
committerAlex Yatskov <alex@foosoft.net>2016-09-19 20:17:58 -0700
commit7666d6a3e6b43f102f79d9f684f4cb5195790c67 (patch)
tree622bd6c710dc1be5eae2f8f777ea295fd56c17e7 /ext/bg/js/util.js
parent396ff944a48ff0bef72f4a2fa99d686768497e98 (diff)
Cleanup
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 5583502d..95d1b43e 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -44,3 +44,63 @@ function isKanji(c) {
return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
}
+function sortTags(tags) {
+ return tags.sort((v1, v2) => {
+ const order1 = v1.order;
+ const order2 = v2.order;
+ if (order1 < order2) {
+ return -1;
+ } else if (order1 > order2) {
+ return 1;
+ }
+
+ const name1 = v1.name;
+ const name2 = v2.name;
+ if (name1 < name2) {
+ return -1;
+ } else if (name1 > name2) {
+ return 1;
+ }
+
+ return 0;
+ });
+}
+
+function sortTermDefs(definitions) {
+ return definitions.sort((v1, v2) => {
+ const sl1 = v1.source.length;
+ const sl2 = v2.source.length;
+ if (sl1 > sl2) {
+ return -1;
+ } else if (sl1 < sl2) {
+ return 1;
+ }
+
+ const s1 = v1.score;
+ const s2 = v2.score;
+ if (s1 > s2) {
+ return -1;
+ } else if (s1 < s2) {
+ return 1;
+ }
+
+ const rl1 = v1.rules.length;
+ const rl2 = v2.rules.length;
+ if (rl1 < rl2) {
+ return -1;
+ } else if (rl1 > rl2) {
+ return 1;
+ }
+
+ return v2.expression.localeCompare(v1.expression);
+ });
+}
+
+function applyTagMeta(tag, meta) {
+ const symbol = tag.name.split(':')[0];
+ for (const prop in meta[symbol] || {}) {
+ tag[prop] = meta[symbol][prop];
+ }
+
+ return tag;
+}