UNPKG

2.81 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2018 Google Inc. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.Arguments = exports.Raw = exports.Status = exports.Parsed = void 0;
19const getValue = (arg) => {
20 for (const key in arg) {
21 if (key === 'name' || key === 'textValue' || key === 'status') {
22 continue;
23 }
24 return arg[key];
25 }
26 // Manually handle the PERMISSION argument because of a bug not returning boolValue
27 if (arg.name === 'PERMISSION') {
28 return !!arg.boolValue;
29 }
30 return arg.textValue;
31};
32class Parsed {
33 /** @hidden */
34 constructor(raw) {
35 /** @public */
36 this.input = {};
37 this.list = raw.map((arg, i) => {
38 const value = getValue(arg);
39 const name = arg.name;
40 this.input[name] = value;
41 return value;
42 });
43 }
44 get(name) {
45 return this.input[name];
46 }
47}
48exports.Parsed = Parsed;
49class Status {
50 /** @hidden */
51 constructor(raw) {
52 /** @public */
53 this.input = {};
54 this.list = raw.map((arg, i) => {
55 const name = arg.name;
56 const status = arg.status;
57 this.input[name] = status;
58 return status;
59 });
60 }
61 /** @public */
62 get(name) {
63 return this.input[name];
64 }
65}
66exports.Status = Status;
67class Raw {
68 /** @hidden */
69 constructor(list) {
70 this.list = list;
71 this.input = list.reduce((o, arg) => {
72 o[arg.name] = arg;
73 return o;
74 }, {});
75 }
76 /** @public */
77 get(name) {
78 return this.input[name];
79 }
80}
81exports.Raw = Raw;
82class Arguments {
83 /** @hidden */
84 constructor(raw = []) {
85 this.parsed = new Parsed(raw);
86 this.status = new Status(raw);
87 this.raw = new Raw(raw);
88 }
89 get(name) {
90 return this.parsed.get(name);
91 }
92 /** @public */
93 [Symbol.iterator]() {
94 return this.raw.list[Symbol.iterator]();
95 // suppose to be Array.prototype.values(), but can't use because of bug:
96 // https://bugs.chromium.org/p/chromium/issues/detail?id=615873
97 }
98}
99exports.Arguments = Arguments;
100//# sourceMappingURL=argument.js.map
\No newline at end of file