summaryrefslogtreecommitdiff
path: root/cli/js/web/dom_util.ts
blob: d12593e8e88da4d3f296210c7051ccf494b2759b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

import * as domTypes from "./dom_types.d.ts";

export function getDOMStringList(arr: string[]): domTypes.DOMStringList {
  Object.defineProperties(arr, {
    contains: {
      value(searchElement: string): boolean {
        return arr.includes(searchElement);
      },
      enumerable: true,
    },
    item: {
      value(idx: number): string | null {
        return idx in arr ? arr[idx] : null;
      },
    },
  });
  return arr as string[] & domTypes.DOMStringList;
}