summaryrefslogtreecommitdiffstats
path: root/toolkit/components/certviewer/content/components/utils.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/certviewer/content/components/utils.mjs')
-rw-r--r--toolkit/components/certviewer/content/components/utils.mjs26
1 files changed, 26 insertions, 0 deletions
diff --git a/toolkit/components/certviewer/content/components/utils.mjs b/toolkit/components/certviewer/content/components/utils.mjs
new file mode 100644
index 0000000000..e7c5d258d0
--- /dev/null
+++ b/toolkit/components/certviewer/content/components/utils.mjs
@@ -0,0 +1,26 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+export const normalizeToKebabCase = string => {
+ let kebabString = string
+ // Turn all dots into dashes
+ .replace(/\./g, "-")
+ // Turn whitespace into dashes
+ .replace(/\s+/g, "-")
+ // Remove all non-characters or numbers
+ .replace(/[^a-z0-9\-]/gi, "")
+ // De-dupe dashes
+ .replace(/--/g, "-")
+ // Remove trailing and leading dashes
+ .replace(/^-/g, "")
+ .replace(/-$/g, "")
+ .toLowerCase();
+
+ return kebabString;
+};
+
+export const b64ToPEM = string => {
+ let wrapped = string.match(/.{1,64}/g).join("\r\n");
+ return `-----BEGIN CERTIFICATE-----\r\n${wrapped}\r\n-----END CERTIFICATE-----\r\n`;
+};