choose.d.ts 924 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /**
  7. * Chooses and evaluates a template function from a list based on matching
  8. * the given `value` to a case.
  9. *
  10. * Cases are structured as `[caseValue, func]`. `value` is matched to
  11. * `caseValue` by strict equality. The first match is selected. Case values
  12. * can be of any type including primitives, objects, and symbols.
  13. *
  14. * This is similar to a switch statement, but as an expression and without
  15. * fallthrough.
  16. *
  17. * @example
  18. *
  19. * ```ts
  20. * render() {
  21. * return html`
  22. * ${choose(this.section, [
  23. * ['home', () => html`<h1>Home</h1>`],
  24. * ['about', () => html`<h1>About</h1>`]
  25. * ],
  26. * () => html`<h1>Error</h1>`)}
  27. * `;
  28. * }
  29. * ```
  30. */
  31. export declare const choose: <T, V>(value: T, cases: [T, () => V][], defaultCase?: (() => V) | undefined) => V | undefined;
  32. //# sourceMappingURL=choose.d.ts.map