Jesse Schettler | bf41a9feb | 2020-09-09 22:52:25 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jesse Schettler | 447bd418 | 2020-09-28 23:05:41 | [diff] [blame] | 5 | import {assertNotReached} from 'chrome://resources/js/assert.m.js'; |
| 6 | |
| 7 | /** |
| 8 | * Converts a chromeos.scanning.mojom.SourceType to a string that can be |
| 9 | * displayed in the source dropdown. |
| 10 | * @param {number} mojoSourceType |
| 11 | * @return {!string} |
| 12 | */ |
| 13 | export function getSourceTypeString(mojoSourceType) { |
| 14 | // TODO(jschettler): Replace with finalized i18n strings. |
| 15 | switch (mojoSourceType) { |
| 16 | case chromeos.scanning.mojom.SourceType.kFlatbed: |
| 17 | return 'Flatbed'; |
| 18 | case chromeos.scanning.mojom.SourceType.kAdfSimplex: |
| 19 | return 'Document Feeder (Simplex)'; |
| 20 | case chromeos.scanning.mojom.SourceType.kAdfDuplex: |
| 21 | return 'Document Feeder (Duplex)'; |
Jesse Schettler | 5bd67af | 2020-10-08 01:51:17 | [diff] [blame^] | 22 | case chromeos.scanning.mojom.SourceType.kDefault: |
| 23 | return 'Default'; |
| 24 | case chromeos.scanning.mojom.SourceType.kUnknown: |
Jesse Schettler | 447bd418 | 2020-09-28 23:05:41 | [diff] [blame] | 25 | default: |
| 26 | assertNotReached(); |
| 27 | return 'Unknown'; |
| 28 | } |
| 29 | } |
| 30 | |
Jesse Schettler | bf41a9feb | 2020-09-09 22:52:25 | [diff] [blame] | 31 | /** |
| 32 | * Converts an unguessable token to a string by combining the high and low |
| 33 | * values as strings with a hashtag as the separator. |
| 34 | * @param {!mojoBase.mojom.UnguessableToken} token |
| 35 | * @return {!string} |
| 36 | */ |
| 37 | export function tokenToString(token) { |
| 38 | return `${token.high.toString()}#${token.low.toString()}`; |
| 39 | } |