UNPKG

2.75 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.request = exports.toArray = exports.stringify = exports.clone = exports.values = exports.deprecate = exports.info = exports.error = exports.warn = exports.debug = void 0;
19const Debug = require("debug");
20const https = require("https");
21const name = 'actions-on-google';
22/** @hidden */
23exports.debug = Debug(`${name}:debug`);
24/** @hidden */
25exports.warn = Debug(`${name}:warn`);
26/** @hidden */
27// tslint:disable-next-line:no-console Allow console binding
28exports.error = console.error.bind(console);
29/** @hidden */
30// tslint:disable-next-line:no-console Allow console binding
31exports.info = console.log.bind(console);
32exports.warn.log = exports.error;
33exports.debug.log = exports.info;
34/** @hidden */
35const deprecate = (feature, alternative) => exports.info(`${feature} is *DEPRECATED*: ${alternative}`);
36exports.deprecate = deprecate;
37/** @hidden */
38const values = (o) => Object.keys(o).map(k => o[k]);
39exports.values = values;
40/** @hidden */
41const clone = (o) => JSON.parse(JSON.stringify(o));
42exports.clone = clone;
43/** @hidden */
44// tslint:disable-next-line:no-any root can be anything
45const stringify = (root, ...exclude) => {
46 const excluded = new Set(exclude);
47 const filtered = Object.keys(root).reduce((o, k) => {
48 if (excluded.has(k)) {
49 o[k] = '[Excluded]';
50 return o;
51 }
52 const value = root[k];
53 try {
54 JSON.stringify(value);
55 o[k] = value;
56 return o;
57 }
58 catch (e) {
59 const { message = '' } = e;
60 o[k] = message.includes('Converting circular structure to JSON')
61 ? '[Circular]'
62 : `[Stringify Error] ${e}`;
63 return o;
64 }
65 }, {});
66 return JSON.stringify(filtered, null, 2);
67};
68exports.stringify = stringify;
69/** @hidden */
70const toArray = (a) => (Array.isArray(a) ? a : [a]);
71exports.toArray = toArray;
72// Bind this to https to ensure its not implementation dependent
73/** @hidden */
74exports.request = https.request.bind(https);
75//# sourceMappingURL=common.js.map
\No newline at end of file