enum.js 565 B

12345678910111213141516171819202122
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. module.exports = {
  6. /**
  7. * Create a simple enum-like object with keys mirrored to values from an array.
  8. * This makes comparison to a specfic value simpler without having to repeat and
  9. * mis-type the value.
  10. */
  11. createEnum(array, target = {}) {
  12. for (let key of array) {
  13. target[key] = key;
  14. }
  15. return target;
  16. }
  17. };