Bug 1573473 - Creates global function to make strings kebab-case. r=johannh

Differential Revision: https://phabricator.services.mozilla.com/D41818

--HG--
extra : moz-landing-system : lando
This commit is contained in:
dleblanccyr 2019-08-19 22:45:57 +00:00
parent 3660d8e202
commit 7a290c37fd
3 changed files with 16 additions and 9 deletions

View File

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { InfoItem } from "./info-item.js";
import { normalizeToKebabCase } from "../utils.js";
export class InfoGroup extends HTMLElement {
constructor(item) {
@ -24,9 +25,7 @@ export class InfoGroup extends HTMLElement {
// Adds a class with the section title's name, to make
// it easier to find when highlighting errors.
this.classList.add(
this.item.sectionTitle.replace(/\s+/g, "-").toLowerCase()
);
this.classList.add(normalizeToKebabCase(this.item.sectionTitle));
for (let i = 0; i < this.item.sectionItems.length; i++) {
this.shadowRoot.append(new InfoItem(this.item.sectionItems[i]));

View File

@ -2,6 +2,8 @@
* 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/. */
import { normalizeToKebabCase } from "../utils.js";
export class InfoItem extends HTMLElement {
constructor(item) {
super();
@ -23,12 +25,7 @@ export class InfoItem extends HTMLElement {
render() {
let label = this.shadowRoot.querySelector("label");
let labelText = this.item.label
.replace(/\s+/g, "-")
.replace(/\./g, "")
.replace(/\//g, "")
.replace(/--/g, "-")
.toLowerCase();
let labelText = normalizeToKebabCase(this.item.label);
label.setAttribute("data-l10n-id", "certificate-viewer-" + labelText);
this.classList.add(labelText);

View File

@ -57,3 +57,14 @@ export const hashify = hash => {
export const pemToDER = pem => {
return stringToArrayBuffer(window.atob(pem));
};
export const normalizeToKebabCase = string => {
let kebabString = string
.replace(/\s+/g, "-")
.replace(/\./g, "")
.replace(/\//g, "")
.replace(/--/g, "-")
.toLowerCase();
return kebabString;
};