summaryrefslogtreecommitdiff
path: root/ext/js/data/permissions-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-24 21:54:58 -0500
committerGitHub <noreply@github.com>2021-02-24 21:54:58 -0500
commitae92e0b3781e27d54cbac2570ba2a1b8a6b11999 (patch)
treeb7d7a7171a6cbc25d5f1fc4b4996024c4f73033e /ext/js/data/permissions-util.js
parent0a76de1b44443cc668882125d73d83d5f7ba8a63 (diff)
AnkiUtil (#1439)
* Add AnkiUtil * Update AnkiConnect to use AnkiUtil * Use AnkiUtil in AnkiNoteBuilder * Replace containsAnyMarker with AnkiUtil.stringContainsAnyFieldMarker * Add AnkiUtil.getFieldMarkers * Add fieldsObjectContainsMarker to AnkiUtil * Remove unused global * Remove unused parameter: enabled * Add cloneFieldMarkerPattern
Diffstat (limited to 'ext/js/data/permissions-util.js')
-rw-r--r--ext/js/data/permissions-util.js21
1 files changed, 6 insertions, 15 deletions
diff --git a/ext/js/data/permissions-util.js b/ext/js/data/permissions-util.js
index bd3a18ce..3a5b5de5 100644
--- a/ext/js/data/permissions-util.js
+++ b/ext/js/data/permissions-util.js
@@ -15,13 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/* global
+ * AnkiUtil
+ */
+
class PermissionsUtil {
constructor() {
this._ankiFieldMarkersRequiringClipboardPermission = new Set([
'clipboard-image',
'clipboard-text'
]);
- this._ankiMarkerPattern = /\{([\w-]+)\}/g;
}
hasPermissions(permissions) {
@@ -69,7 +72,7 @@ class PermissionsUtil {
}
getRequiredPermissionsForAnkiFieldValue(fieldValue) {
- const markers = this._getAnkiFieldMarkers(fieldValue);
+ const markers = AnkiUtil.getFieldMarkers(fieldValue);
const markerPermissions = this._ankiFieldMarkersRequiringClipboardPermission;
for (const marker of markers) {
if (markerPermissions.has(marker)) {
@@ -99,7 +102,7 @@ class PermissionsUtil {
];
for (const fields of fieldsList) {
for (const fieldValue of Object.values(fields)) {
- const markers = this._getAnkiFieldMarkers(fieldValue);
+ const markers = AnkiUtil.getFieldMarkers(fieldValue);
for (const marker of markers) {
if (fieldMarkersRequiringClipboardPermission.has(marker)) {
return false;
@@ -111,16 +114,4 @@ class PermissionsUtil {
return true;
}
-
- // Private
-
- _getAnkiFieldMarkers(fieldValue) {
- const pattern = this._ankiMarkerPattern;
- const markers = [];
- let match;
- while ((match = pattern.exec(fieldValue)) !== null) {
- markers.push(match[1]);
- }
- return markers;
- }
}