createEnum does not take an array

This commit is contained in:
Bruno Windels 2020-09-18 13:08:35 +02:00
parent ed913ca24b
commit 3aead4eae2
2 changed files with 4 additions and 1 deletions

View file

@ -17,7 +17,7 @@ limitations under the License.
import anotherjson from "../../../lib/another-json/index.js"; import anotherjson from "../../../lib/another-json/index.js";
import {createEnum} from "../../utils/enum.js"; import {createEnum} from "../../utils/enum.js";
export const DecryptionSource = createEnum(["Sync", "Timeline", "Retry"]); export const DecryptionSource = createEnum("Sync", "Timeline", "Retry");
// use common prefix so it's easy to clear properties that are not e2ee related during session clear // use common prefix so it's easy to clear properties that are not e2ee related during session clear
export const SESSION_KEY_PREFIX = "e2ee:"; export const SESSION_KEY_PREFIX = "e2ee:";

View file

@ -17,6 +17,9 @@ limitations under the License.
export function createEnum(...values) { export function createEnum(...values) {
const obj = {}; const obj = {};
for (const value of values) { for (const value of values) {
if (typeof value !== "string") {
throw new Error("Invalid enum value name" + value?.toString());
}
obj[value] = value; obj[value] = value;
} }
return Object.freeze(obj); return Object.freeze(obj);