Skip to content

Commit aef3754

Browse files
authored
use forEach instead of for .. in (#120)
* use for .. of for Array `for .. in` is not for Array. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#array_iteration_and_for...in * Update validator.js * use forEach for index * add semicolon
1 parent cbce280 commit aef3754

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/validator.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,22 @@ async function validateExpectations() {
130130
if (!Array.isArray(allowCredentials)) {
131131
throw new Error("expected allowCredentials to be null or array");
132132
} else {
133-
for (const index in allowCredentials) {
134-
if (typeof allowCredentials[index].id === "string") {
135-
allowCredentials[index].id = coerceToArrayBuffer(allowCredentials[index].id, "allowCredentials[" + index + "].id");
133+
allowCredentials.forEach((allowCredential, index) => {
134+
if (typeof allowCredential.id === "string") {
135+
allowCredential.id = coerceToArrayBuffer(allowCredential.id, "allowCredentials[" + index + "].id");
136136
}
137-
if (allowCredentials[index].id == null || !(allowCredentials[index].id instanceof ArrayBuffer)) {
137+
if (allowCredential.id == null || !(allowCredential.id instanceof ArrayBuffer)) {
138138
throw new Error("expected id of allowCredentials[" + index + "] to be ArrayBuffer");
139139
}
140-
if (allowCredentials[index].type == null || allowCredentials[index].type !== "public-key") {
140+
if (allowCredential.type == null || allowCredential.type !== "public-key") {
141141
throw new Error("expected type of allowCredentials[" + index + "] to be string with value 'public-key'");
142142
}
143-
if (allowCredentials[index].transports != null && !Array.isArray(allowCredentials[index].transports)) {
143+
if (allowCredential.transports != null && !Array.isArray(allowCredential.transports)) {
144144
throw new Error("expected transports of allowCredentials[" + index + "] to be array or null");
145-
} else if (allowCredentials[index].transports != null && !allowCredentials[index].transports.every(el => ["usb", "nfc", "ble", "cable", "internal"].includes(el))) {
145+
} else if (allowCredential.transports != null && !allowCredential.transports.every(el => ["usb", "nfc", "ble", "cable", "internal"].includes(el))) {
146146
throw new Error("expected transports of allowCredentials[" + index + "] to be string with value 'usb', 'nfc', 'ble', 'cable', 'internal' or null");
147147
}
148-
}
148+
});
149149
}
150150
}
151151

0 commit comments

Comments
 (0)