Fix global declarations check (#1101)

* Fix getSubstringCount not properly checking word boundaries

* Remove unused global declarations
This commit is contained in:
toasted-nutbread 2020-12-12 14:47:17 -05:00 committed by GitHub
parent fe16793779
commit 92cfd31c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 10 deletions

View File

@ -22,6 +22,10 @@ const assert = require('assert');
const {getAllFiles} = require('../util');
function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
}
function countOccurences(string, pattern) {
return (string.match(pattern) || []).length;
}
@ -38,13 +42,12 @@ function getNewline(string) {
}
function getSubstringCount(string, substring) {
let start = 0;
let count = 0;
const pattern = new RegExp(`\\b${escapeRegExp(substring)}\\b`, 'g');
while (true) {
const pos = string.indexOf(substring, start);
if (pos < 0) { break; }
const match = pattern.exec(string);
if (match === null) { break; }
++count;
start = pos + substring.length;
}
return count;
}

View File

@ -17,7 +17,6 @@
/* global
* AnkiNoteBuilder
* Modal
* TemplateRendererProxy
* api
*/

View File

@ -17,7 +17,6 @@
/* global
* DictionaryController
* Modal
* OptionsUtil
* api
*/

View File

@ -17,7 +17,6 @@
/* global
* DictionaryDatabase
* Modal
* ObjectPropertyAccessor
* api
*/

View File

@ -18,7 +18,6 @@
/* global
* DictionaryDatabase
* DictionaryImporter
* Modal
* ObjectPropertyAccessor
* api
*/

View File

@ -17,7 +17,6 @@
/* global
* Frontend
* Popup
* TextSourceRange
* api
* wanakana

View File

@ -16,7 +16,6 @@
*/
/* global
* Modal
* ProfileConditionsUI
* api
*/