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

export function getDOMStringList(arr: string[]): 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[] & DOMStringList;
}