@amazon-devices/vega-carousel 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +0 -0
- package/dist/Carousel/Carousel.d.ts +16 -0
- package/dist/Carousel/Carousel.js +102 -0
- package/dist/Carousel/Utils.d.ts +4 -0
- package/dist/Carousel/Utils.js +35 -0
- package/dist/Carousel/index.d.ts +7 -0
- package/dist/Carousel/index.js +23 -0
- package/dist/Carousel/types.d.ts +406 -0
- package/dist/Carousel/types.js +2 -0
- package/dist/CarouselData/CarouselDataAdapter.d.ts +141 -0
- package/dist/CarouselData/CarouselDataAdapter.js +67 -0
- package/dist/CarouselData/CarouselDataResolver.d.ts +100 -0
- package/dist/CarouselData/CarouselDataResolver.js +224 -0
- package/dist/CarouselData/CarouselDataTypes.d.ts +280 -0
- package/dist/CarouselData/CarouselDataTypes.js +84 -0
- package/dist/CarouselData/index.d.ts +3 -0
- package/dist/CarouselData/index.js +24 -0
- package/dist/CarouselScrollable/CarouselScrollable.d.ts +67 -0
- package/dist/CarouselScrollable/CarouselScrollable.js +77 -0
- package/dist/CarouselScrollable/CarouselScrollableProps.d.ts +499 -0
- package/dist/CarouselScrollable/CarouselScrollableProps.js +211 -0
- package/dist/CarouselScrollable/CarouselScrollableRef.d.ts +80 -0
- package/dist/CarouselScrollable/CarouselScrollableRef.js +7 -0
- package/dist/CarouselScrollable/CarouselScrollableTypes.d.ts +224 -0
- package/dist/CarouselScrollable/CarouselScrollableTypes.js +116 -0
- package/dist/CarouselScrollable/CarouselSimple.d.ts +71 -0
- package/dist/CarouselScrollable/CarouselSimple.js +111 -0
- package/dist/CarouselScrollable/CarouselSimpleProps.d.ts +29 -0
- package/dist/CarouselScrollable/CarouselSimpleProps.js +7 -0
- package/dist/CarouselScrollable/index.d.ts +6 -0
- package/dist/CarouselScrollable/index.js +27 -0
- package/dist/CarouselScrollable/native/CarouselNativeHostComponent.d.ts +109 -0
- package/dist/CarouselScrollable/native/CarouselNativeHostComponent.js +82 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemHostComponent.d.ts +94 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemHostComponent.js +42 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemWrapper.d.ts +255 -0
- package/dist/CarouselScrollable/native/CarouselNativeItemWrapper.js +276 -0
- package/dist/CarouselScrollable/native/CarouselNativeLogic.d.ts +209 -0
- package/dist/CarouselScrollable/native/CarouselNativeLogic.js +349 -0
- package/dist/CarouselScrollable/native/CarouselNativeWrapper.d.ts +68 -0
- package/dist/CarouselScrollable/native/CarouselNativeWrapper.js +164 -0
- package/dist/CarouselScrollable/native/index.d.ts +5 -0
- package/dist/CarouselScrollable/native/index.js +26 -0
- package/dist/CarouselScrollable/recyclerview/JSRecyclerViewList.d.ts +25 -0
- package/dist/CarouselScrollable/recyclerview/JSRecyclerViewList.js +150 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -0
- package/dist/kepler/aarch64-debug/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/aarch64-debug/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/aarch64-release/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/aarch64-release/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/armv7-debug/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/armv7-debug/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/armv7-release/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/armv7-release/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/tm-manifest.json +1 -0
- package/dist/kepler/x86_64-debug/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/x86_64-debug/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/kepler/x86_64-release/lib/com.amazon.keplerscript.carousel.so +0 -0
- package/dist/kepler/x86_64-release/lib/com.amazon.keplerscript.carousel.so.debug +0 -0
- package/dist/utils/CarouselLogger.d.ts +295 -0
- package/dist/utils/CarouselLogger.js +370 -0
- package/dist/utils/CarouselReactNativeUtilities.d.ts +108 -0
- package/dist/utils/CarouselReactNativeUtilities.js +150 -0
- package/dist/utils/HelperTypes.d.ts +5 -0
- package/dist/utils/HelperTypes.js +7 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +24 -0
- package/package.json +1 -0
- package/react-native.config.js +22 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { AnyValue } from './HelperTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Convenient type encapsulating all supported log levels.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type LogLevelType = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'log';
|
|
8
|
+
/**
|
|
9
|
+
* Helper type that encapsulates all types that are considered a "valid message"
|
|
10
|
+
* by the {@link Logger} class.
|
|
11
|
+
*
|
|
12
|
+
* When used as a string, the variable of this type is the message. When used as
|
|
13
|
+
* an array of strings, a _space character_ will join all the array elements to
|
|
14
|
+
* form the message. When used as a function, the function will be called to
|
|
15
|
+
* resolve the message string.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type LogMessage = string | Array<string> | (() => string);
|
|
20
|
+
/**
|
|
21
|
+
* Helper class to log messages to the {@link Console} using a `printf` style
|
|
22
|
+
* syntax for string interpolation, and a _Robot-like_ API.
|
|
23
|
+
*
|
|
24
|
+
* When using the `printf`-like interpolation, you'll need to use the syntax
|
|
25
|
+
* explained on the {@link Logger.format} function.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link Logger.format}
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare class Logger {
|
|
31
|
+
/**
|
|
32
|
+
* The string to be prepended to all log message logged with this utility
|
|
33
|
+
* class.
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
readonly tag: string;
|
|
37
|
+
/**
|
|
38
|
+
* Attribute that holds static information about an instance of `Logger`.
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
private readonly levelInfo;
|
|
42
|
+
constructor(tag: string);
|
|
43
|
+
/**
|
|
44
|
+
* Function to interpolate values from the variadic argument `args` into the
|
|
45
|
+
* given `message`.
|
|
46
|
+
*
|
|
47
|
+
* To embed one of the variadic arguments into the string, use the `{N}`
|
|
48
|
+
* syntax, where `N` is the positional index of the arg.
|
|
49
|
+
*
|
|
50
|
+
* You can also repeat the usage of an arg by repeating its `{N}` placeholder.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} message The string message to be interpolated with values
|
|
53
|
+
* from the given `args`.
|
|
54
|
+
* @param {...any} args A variadic list of arguments to be used to interpolate
|
|
55
|
+
* matches of `{N}` in the given `message`.
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
private static format;
|
|
59
|
+
/**
|
|
60
|
+
* Helper function to create the log prefix for a `tag` and a log `level`.
|
|
61
|
+
*
|
|
62
|
+
* This function is mainly used in tests to help us build log messages that
|
|
63
|
+
* mach the real log output.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} tag An arbitrary string to go at the start of the log
|
|
66
|
+
* message. Inside a {@link Logger} class, this will be
|
|
67
|
+
* {@link Logger.tag}.
|
|
68
|
+
* @param {LogLevelType?} level An optional string representing one of the
|
|
69
|
+
* supported logs.
|
|
70
|
+
*/
|
|
71
|
+
static buildLogPrefix(tag: string, level?: LogLevelType): string;
|
|
72
|
+
/**
|
|
73
|
+
* Helper function used to allow us to test this class. When running a test,
|
|
74
|
+
* the function returned by this wrapper is a simple pass-through of the log
|
|
75
|
+
* message.
|
|
76
|
+
*
|
|
77
|
+
* @param {(text: string) => string} wrapper The function that will wrap the
|
|
78
|
+
* log message before sending it to the console.
|
|
79
|
+
*
|
|
80
|
+
* @return {(text: string) => string} Returns the given message back to the
|
|
81
|
+
* caller, unless it is running in a test environment, which, in such
|
|
82
|
+
* a case, it will return a simple pass-through function
|
|
83
|
+
* (`msg => mst`).
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
private static logWrapper;
|
|
87
|
+
/**
|
|
88
|
+
* Main function to perform the console log.
|
|
89
|
+
*
|
|
90
|
+
* This function also augments each log message to the appropriate color for
|
|
91
|
+
* its level.
|
|
92
|
+
*
|
|
93
|
+
* @param {boolean} useRawConsole Flag indicating if the message being logged
|
|
94
|
+
* is using the `printf`-like syntax or not.
|
|
95
|
+
* @param {LogLevelType} level The log level to use to output the given
|
|
96
|
+
* `message`.
|
|
97
|
+
* @param {LogMessage} message The message to be sent to the console output.
|
|
98
|
+
* If this argument is given as an array of strings, a space character
|
|
99
|
+
* will _join_ each entry in the array to form the final message. If it
|
|
100
|
+
* is a function, the function will be called to resolve the string.
|
|
101
|
+
* @param {...any} args A variadic list of arguments to be used to interpolate
|
|
102
|
+
* matches of `{N}` in the given `message`.
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
private consoleLog;
|
|
106
|
+
/**
|
|
107
|
+
* Logs a message to the {@link Console.trace} function using a `printf` style
|
|
108
|
+
* API for string interpolation.
|
|
109
|
+
*
|
|
110
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
111
|
+
* {@link traceRaw} function.
|
|
112
|
+
*
|
|
113
|
+
* @param {LogMessage} msg The message to be logged.
|
|
114
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
115
|
+
* string interpolation.
|
|
116
|
+
*
|
|
117
|
+
* @see {@link traceRaw}
|
|
118
|
+
* @see {@link t}
|
|
119
|
+
*/
|
|
120
|
+
trace(msg: LogMessage, ...args: AnyValue[]): void;
|
|
121
|
+
/**
|
|
122
|
+
* Logs a message to the {@link Console.trace} function using the same API as
|
|
123
|
+
* the one offered by the {@link Console}.
|
|
124
|
+
*
|
|
125
|
+
* To use a `printf`-like API for string interpolation, use the {@link trace}
|
|
126
|
+
* or {@link t} functions.
|
|
127
|
+
*
|
|
128
|
+
* @param {LogMessage} msg The message to be logged.
|
|
129
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
130
|
+
* {@link Console.trace} function.
|
|
131
|
+
*
|
|
132
|
+
* @see {@link trace}
|
|
133
|
+
* @see {@link t}
|
|
134
|
+
*/
|
|
135
|
+
traceRaw(msg: LogMessage, ...args: AnyValue[]): void;
|
|
136
|
+
/** This function is just an alias to the {@link trace} function. */
|
|
137
|
+
t: (msg: LogMessage, ...args: AnyValue[]) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Logs a message to the {@link Console.debug} function using a `printf` style
|
|
140
|
+
* API for string interpolation.
|
|
141
|
+
*
|
|
142
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
143
|
+
* {@link debugRaw} function.
|
|
144
|
+
*
|
|
145
|
+
* @param {LogMessage} msg The message to be logged.
|
|
146
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
147
|
+
* string interpolation.
|
|
148
|
+
*
|
|
149
|
+
* @see {@link debugRaw}
|
|
150
|
+
* @see {@link d}
|
|
151
|
+
*/
|
|
152
|
+
debug(msg: LogMessage, ...args: AnyValue[]): void;
|
|
153
|
+
/**
|
|
154
|
+
* Logs a message to the {@link Console.debug} function using the same API as
|
|
155
|
+
* the one offered by the {@link Console}.
|
|
156
|
+
*
|
|
157
|
+
* To use a `printf`-like API for string interpolation, use the {@link debug}
|
|
158
|
+
* or {@link d} functions.
|
|
159
|
+
*
|
|
160
|
+
* @param {LogMessage} msg The message to be logged.
|
|
161
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
162
|
+
* {@link Console.debug} function.
|
|
163
|
+
*
|
|
164
|
+
* @see {@link debug}
|
|
165
|
+
* @see {@link d}
|
|
166
|
+
*/
|
|
167
|
+
debugRaw(msg: LogMessage, ...args: AnyValue[]): void;
|
|
168
|
+
/** This function is just an alias to the {@link debug} function. */
|
|
169
|
+
d: (msg: LogMessage, ...args: AnyValue[]) => void;
|
|
170
|
+
/**
|
|
171
|
+
* Logs a message to the {@link Console.info} function using a `printf` style
|
|
172
|
+
* API for string interpolation.
|
|
173
|
+
*
|
|
174
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
175
|
+
* {@link infoRaw} function.
|
|
176
|
+
*
|
|
177
|
+
* @param {LogMessage} msg The message to be logged.
|
|
178
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
179
|
+
* string interpolation.
|
|
180
|
+
*
|
|
181
|
+
* @see {@link infoRaw}
|
|
182
|
+
* @see {@link i}
|
|
183
|
+
*/
|
|
184
|
+
info(msg: LogMessage, ...args: AnyValue[]): void;
|
|
185
|
+
/**
|
|
186
|
+
* Logs a message to the {@link Console.info} function using the same API as
|
|
187
|
+
* the one offered by the {@link Console}.
|
|
188
|
+
*
|
|
189
|
+
* To use a `printf`-like API for string interpolation, use the {@link info}
|
|
190
|
+
* or {@link i} functions.
|
|
191
|
+
*
|
|
192
|
+
* @param {LogMessage} msg The message to be logged.
|
|
193
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
194
|
+
* {@link Console.info} function.
|
|
195
|
+
*
|
|
196
|
+
* @see {@link info}
|
|
197
|
+
* @see {@link i}
|
|
198
|
+
*/
|
|
199
|
+
infoRaw(msg: LogMessage, ...args: AnyValue[]): void;
|
|
200
|
+
/** This function is just an alias to the {@link info} function. */
|
|
201
|
+
i: (msg: LogMessage, ...args: AnyValue[]) => void;
|
|
202
|
+
/**
|
|
203
|
+
* Logs a message to the {@link Console.warn} function using a `printf` style
|
|
204
|
+
* API for string interpolation.
|
|
205
|
+
*
|
|
206
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
207
|
+
* {@link warnRaw} function.
|
|
208
|
+
*
|
|
209
|
+
* @param {LogMessage} msg The message to be logged.
|
|
210
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
211
|
+
* string interpolation.
|
|
212
|
+
*
|
|
213
|
+
* @see {@link warnRaw}
|
|
214
|
+
* @see {@link w}
|
|
215
|
+
*/
|
|
216
|
+
warn(msg: LogMessage, ...args: AnyValue[]): void;
|
|
217
|
+
/**
|
|
218
|
+
* Logs a message to the {@link Console.warn} function using the same API as
|
|
219
|
+
* the one offered by the {@link Console}.
|
|
220
|
+
*
|
|
221
|
+
* To use a `printf`-like API for string interpolation, use the {@link warn}
|
|
222
|
+
* or {@link w} functions.
|
|
223
|
+
*
|
|
224
|
+
* @param {LogMessage} msg The message to be logged.
|
|
225
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
226
|
+
* {@link Console.warn} function.
|
|
227
|
+
*
|
|
228
|
+
* @see {@link warn}
|
|
229
|
+
* @see {@link w}
|
|
230
|
+
*/
|
|
231
|
+
warnRaw(msg: LogMessage, ...args: AnyValue[]): void;
|
|
232
|
+
/** This function is just an alias to the {@link warn} function. */
|
|
233
|
+
w: (msg: LogMessage, ...args: AnyValue[]) => void;
|
|
234
|
+
/**
|
|
235
|
+
* Logs a message to the {@link Console.error} function using a `printf` style
|
|
236
|
+
* API for string interpolation.
|
|
237
|
+
*
|
|
238
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
239
|
+
* {@link errorRaw} function.
|
|
240
|
+
*
|
|
241
|
+
* @param {LogMessage} msg The message to be logged.
|
|
242
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
243
|
+
* string interpolation.
|
|
244
|
+
*
|
|
245
|
+
* @see {@link errorRaw}
|
|
246
|
+
* @see {@link e}
|
|
247
|
+
*/
|
|
248
|
+
error(msg: LogMessage, ...args: AnyValue[]): void;
|
|
249
|
+
/**
|
|
250
|
+
* Logs a message to the {@link Console.error} function using the same API as
|
|
251
|
+
* the one offered by the {@link Console}.
|
|
252
|
+
*
|
|
253
|
+
* To use a `printf`-like API for string interpolation, use the {@link error}
|
|
254
|
+
* or {@link e} functions.
|
|
255
|
+
*
|
|
256
|
+
* @param {LogMessage} msg The message to be logged.
|
|
257
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
258
|
+
* {@link Console.error} function.
|
|
259
|
+
*
|
|
260
|
+
* @see {@link error}
|
|
261
|
+
* @see {@link e}
|
|
262
|
+
*/
|
|
263
|
+
errorRaw(msg: LogMessage, ...args: AnyValue[]): void;
|
|
264
|
+
/** This function is just an alias to the {@link error} function. */
|
|
265
|
+
e: (msg: LogMessage, ...args: AnyValue[]) => void;
|
|
266
|
+
/**
|
|
267
|
+
* Logs a message to the {@link Console.log} function using a `printf` style
|
|
268
|
+
* API for string interpolation.
|
|
269
|
+
*
|
|
270
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
271
|
+
* {@link logRaw} function.
|
|
272
|
+
*
|
|
273
|
+
* @param {LogMessage} msg The message to be logged.
|
|
274
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
275
|
+
* string interpolation.
|
|
276
|
+
*
|
|
277
|
+
* @see {@link logRaw}
|
|
278
|
+
*/
|
|
279
|
+
log(msg: LogMessage, ...args: AnyValue[]): void;
|
|
280
|
+
/**
|
|
281
|
+
* Logs a message to the {@link Console.log} function using the same API as
|
|
282
|
+
* the one offered by the {@link Console}.
|
|
283
|
+
*
|
|
284
|
+
* To use a `printf`-like API for string interpolation, use the {@link error}
|
|
285
|
+
* function.
|
|
286
|
+
*
|
|
287
|
+
* @param {LogMessage} msg The message to be logged.
|
|
288
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
289
|
+
* {@link Console.log} function.
|
|
290
|
+
*
|
|
291
|
+
* @see {@link log}
|
|
292
|
+
*/
|
|
293
|
+
logRaw(msg: LogMessage, ...args: AnyValue[]): void;
|
|
294
|
+
}
|
|
295
|
+
export declare const Log: Logger;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 - 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* PROPRIETARY/CONFIDENTIAL. USE IS SUBJECT TO LICENSE TERMS.
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Log = exports.Logger = void 0;
|
|
12
|
+
const ansi_colors_1 = __importDefault(require("ansi-colors"));
|
|
13
|
+
const CarouselReactNativeUtilities_1 = require("./CarouselReactNativeUtilities");
|
|
14
|
+
/**
|
|
15
|
+
* Helper class to log messages to the {@link Console} using a `printf` style
|
|
16
|
+
* syntax for string interpolation, and a _Robot-like_ API.
|
|
17
|
+
*
|
|
18
|
+
* When using the `printf`-like interpolation, you'll need to use the syntax
|
|
19
|
+
* explained on the {@link Logger.format} function.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link Logger.format}
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
class Logger {
|
|
25
|
+
/**
|
|
26
|
+
* The string to be prepended to all log message logged with this utility
|
|
27
|
+
* class.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
tag;
|
|
31
|
+
/**
|
|
32
|
+
* Attribute that holds static information about an instance of `Logger`.
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
levelInfo;
|
|
36
|
+
constructor(tag) {
|
|
37
|
+
this.tag = tag;
|
|
38
|
+
this.levelInfo = {
|
|
39
|
+
trace: {
|
|
40
|
+
prefix: Logger.buildLogPrefix(this.tag, 'trace'),
|
|
41
|
+
wrapLog: Logger.logWrapper(ansi_colors_1.default.blackBright),
|
|
42
|
+
},
|
|
43
|
+
debug: {
|
|
44
|
+
prefix: Logger.buildLogPrefix(this.tag, 'debug'),
|
|
45
|
+
wrapLog: Logger.logWrapper(ansi_colors_1.default.green),
|
|
46
|
+
},
|
|
47
|
+
info: {
|
|
48
|
+
prefix: Logger.buildLogPrefix(this.tag, 'info'),
|
|
49
|
+
wrapLog: Logger.logWrapper(ansi_colors_1.default.reset),
|
|
50
|
+
},
|
|
51
|
+
warn: {
|
|
52
|
+
prefix: Logger.buildLogPrefix(this.tag, 'warn'),
|
|
53
|
+
wrapLog: Logger.logWrapper(ansi_colors_1.default.yellow),
|
|
54
|
+
},
|
|
55
|
+
error: {
|
|
56
|
+
prefix: Logger.buildLogPrefix(this.tag, 'error'),
|
|
57
|
+
wrapLog: Logger.logWrapper(ansi_colors_1.default.red),
|
|
58
|
+
},
|
|
59
|
+
log: {
|
|
60
|
+
prefix: Logger.buildLogPrefix(this.tag),
|
|
61
|
+
wrapLog: Logger.logWrapper(ansi_colors_1.default.reset),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Function to interpolate values from the variadic argument `args` into the
|
|
67
|
+
* given `message`.
|
|
68
|
+
*
|
|
69
|
+
* To embed one of the variadic arguments into the string, use the `{N}`
|
|
70
|
+
* syntax, where `N` is the positional index of the arg.
|
|
71
|
+
*
|
|
72
|
+
* You can also repeat the usage of an arg by repeating its `{N}` placeholder.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} message The string message to be interpolated with values
|
|
75
|
+
* from the given `args`.
|
|
76
|
+
* @param {...any} args A variadic list of arguments to be used to interpolate
|
|
77
|
+
* matches of `{N}` in the given `message`.
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
static format(message, ...args) {
|
|
81
|
+
let dynIndex = 0;
|
|
82
|
+
return message.replace(/{(\d*)}/g, (match, index) => {
|
|
83
|
+
const idx = index === '' ? dynIndex++ : index;
|
|
84
|
+
const argValue = idx >= 0 && idx < args.length ? args[idx] : match;
|
|
85
|
+
return argValue === null ? '<null>' : (argValue ?? '<undefined>');
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Helper function to create the log prefix for a `tag` and a log `level`.
|
|
90
|
+
*
|
|
91
|
+
* This function is mainly used in tests to help us build log messages that
|
|
92
|
+
* mach the real log output.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} tag An arbitrary string to go at the start of the log
|
|
95
|
+
* message. Inside a {@link Logger} class, this will be
|
|
96
|
+
* {@link Logger.tag}.
|
|
97
|
+
* @param {LogLevelType?} level An optional string representing one of the
|
|
98
|
+
* supported logs.
|
|
99
|
+
*/
|
|
100
|
+
static buildLogPrefix(tag, level) {
|
|
101
|
+
if (level) {
|
|
102
|
+
return `${tag} (JS) [${level.toUpperCase()}]`;
|
|
103
|
+
}
|
|
104
|
+
return `${tag} (JS)`;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Helper function used to allow us to test this class. When running a test,
|
|
108
|
+
* the function returned by this wrapper is a simple pass-through of the log
|
|
109
|
+
* message.
|
|
110
|
+
*
|
|
111
|
+
* @param {(text: string) => string} wrapper The function that will wrap the
|
|
112
|
+
* log message before sending it to the console.
|
|
113
|
+
*
|
|
114
|
+
* @return {(text: string) => string} Returns the given message back to the
|
|
115
|
+
* caller, unless it is running in a test environment, which, in such
|
|
116
|
+
* a case, it will return a simple pass-through function
|
|
117
|
+
* (`msg => mst`).
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
120
|
+
static logWrapper(wrapper) {
|
|
121
|
+
return CarouselReactNativeUtilities_1.isTest ? msg => msg : /* istanbul ignore next */ wrapper;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Main function to perform the console log.
|
|
125
|
+
*
|
|
126
|
+
* This function also augments each log message to the appropriate color for
|
|
127
|
+
* its level.
|
|
128
|
+
*
|
|
129
|
+
* @param {boolean} useRawConsole Flag indicating if the message being logged
|
|
130
|
+
* is using the `printf`-like syntax or not.
|
|
131
|
+
* @param {LogLevelType} level The log level to use to output the given
|
|
132
|
+
* `message`.
|
|
133
|
+
* @param {LogMessage} message The message to be sent to the console output.
|
|
134
|
+
* If this argument is given as an array of strings, a space character
|
|
135
|
+
* will _join_ each entry in the array to form the final message. If it
|
|
136
|
+
* is a function, the function will be called to resolve the string.
|
|
137
|
+
* @param {...any} args A variadic list of arguments to be used to interpolate
|
|
138
|
+
* matches of `{N}` in the given `message`.
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
141
|
+
consoleLog(useRawConsole, level, message, ...args) {
|
|
142
|
+
const logMessage = typeof message === 'string'
|
|
143
|
+
? message
|
|
144
|
+
: typeof message === 'function'
|
|
145
|
+
? message()
|
|
146
|
+
: message.join(' ');
|
|
147
|
+
const logInfo = this.levelInfo[level];
|
|
148
|
+
if (useRawConsole) {
|
|
149
|
+
console[level](logInfo.prefix, logMessage, ...args);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const fullMessage = `${logInfo.prefix} ${Logger.format(logMessage, ...args)}`;
|
|
153
|
+
console[level](logInfo.wrapLog(fullMessage));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Logs a message to the {@link Console.trace} function using a `printf` style
|
|
158
|
+
* API for string interpolation.
|
|
159
|
+
*
|
|
160
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
161
|
+
* {@link traceRaw} function.
|
|
162
|
+
*
|
|
163
|
+
* @param {LogMessage} msg The message to be logged.
|
|
164
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
165
|
+
* string interpolation.
|
|
166
|
+
*
|
|
167
|
+
* @see {@link traceRaw}
|
|
168
|
+
* @see {@link t}
|
|
169
|
+
*/
|
|
170
|
+
trace(msg, ...args) {
|
|
171
|
+
this.consoleLog(false, 'trace', msg, ...args);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Logs a message to the {@link Console.trace} function using the same API as
|
|
175
|
+
* the one offered by the {@link Console}.
|
|
176
|
+
*
|
|
177
|
+
* To use a `printf`-like API for string interpolation, use the {@link trace}
|
|
178
|
+
* or {@link t} functions.
|
|
179
|
+
*
|
|
180
|
+
* @param {LogMessage} msg The message to be logged.
|
|
181
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
182
|
+
* {@link Console.trace} function.
|
|
183
|
+
*
|
|
184
|
+
* @see {@link trace}
|
|
185
|
+
* @see {@link t}
|
|
186
|
+
*/
|
|
187
|
+
traceRaw(msg, ...args) {
|
|
188
|
+
this.consoleLog(true, 'trace', msg, ...args);
|
|
189
|
+
}
|
|
190
|
+
/** This function is just an alias to the {@link trace} function. */
|
|
191
|
+
t = this.trace;
|
|
192
|
+
/**
|
|
193
|
+
* Logs a message to the {@link Console.debug} function using a `printf` style
|
|
194
|
+
* API for string interpolation.
|
|
195
|
+
*
|
|
196
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
197
|
+
* {@link debugRaw} function.
|
|
198
|
+
*
|
|
199
|
+
* @param {LogMessage} msg The message to be logged.
|
|
200
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
201
|
+
* string interpolation.
|
|
202
|
+
*
|
|
203
|
+
* @see {@link debugRaw}
|
|
204
|
+
* @see {@link d}
|
|
205
|
+
*/
|
|
206
|
+
debug(msg, ...args) {
|
|
207
|
+
this.consoleLog(false, 'debug', msg, ...args);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Logs a message to the {@link Console.debug} function using the same API as
|
|
211
|
+
* the one offered by the {@link Console}.
|
|
212
|
+
*
|
|
213
|
+
* To use a `printf`-like API for string interpolation, use the {@link debug}
|
|
214
|
+
* or {@link d} functions.
|
|
215
|
+
*
|
|
216
|
+
* @param {LogMessage} msg The message to be logged.
|
|
217
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
218
|
+
* {@link Console.debug} function.
|
|
219
|
+
*
|
|
220
|
+
* @see {@link debug}
|
|
221
|
+
* @see {@link d}
|
|
222
|
+
*/
|
|
223
|
+
debugRaw(msg, ...args) {
|
|
224
|
+
this.consoleLog(true, 'debug', msg, ...args);
|
|
225
|
+
}
|
|
226
|
+
/** This function is just an alias to the {@link debug} function. */
|
|
227
|
+
d = this.debug;
|
|
228
|
+
/**
|
|
229
|
+
* Logs a message to the {@link Console.info} function using a `printf` style
|
|
230
|
+
* API for string interpolation.
|
|
231
|
+
*
|
|
232
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
233
|
+
* {@link infoRaw} function.
|
|
234
|
+
*
|
|
235
|
+
* @param {LogMessage} msg The message to be logged.
|
|
236
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
237
|
+
* string interpolation.
|
|
238
|
+
*
|
|
239
|
+
* @see {@link infoRaw}
|
|
240
|
+
* @see {@link i}
|
|
241
|
+
*/
|
|
242
|
+
info(msg, ...args) {
|
|
243
|
+
this.consoleLog(false, 'info', msg, ...args);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Logs a message to the {@link Console.info} function using the same API as
|
|
247
|
+
* the one offered by the {@link Console}.
|
|
248
|
+
*
|
|
249
|
+
* To use a `printf`-like API for string interpolation, use the {@link info}
|
|
250
|
+
* or {@link i} functions.
|
|
251
|
+
*
|
|
252
|
+
* @param {LogMessage} msg The message to be logged.
|
|
253
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
254
|
+
* {@link Console.info} function.
|
|
255
|
+
*
|
|
256
|
+
* @see {@link info}
|
|
257
|
+
* @see {@link i}
|
|
258
|
+
*/
|
|
259
|
+
infoRaw(msg, ...args) {
|
|
260
|
+
this.consoleLog(true, 'info', msg, ...args);
|
|
261
|
+
}
|
|
262
|
+
/** This function is just an alias to the {@link info} function. */
|
|
263
|
+
i = this.info;
|
|
264
|
+
/**
|
|
265
|
+
* Logs a message to the {@link Console.warn} function using a `printf` style
|
|
266
|
+
* API for string interpolation.
|
|
267
|
+
*
|
|
268
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
269
|
+
* {@link warnRaw} function.
|
|
270
|
+
*
|
|
271
|
+
* @param {LogMessage} msg The message to be logged.
|
|
272
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
273
|
+
* string interpolation.
|
|
274
|
+
*
|
|
275
|
+
* @see {@link warnRaw}
|
|
276
|
+
* @see {@link w}
|
|
277
|
+
*/
|
|
278
|
+
warn(msg, ...args) {
|
|
279
|
+
this.consoleLog(false, 'warn', msg, ...args);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Logs a message to the {@link Console.warn} function using the same API as
|
|
283
|
+
* the one offered by the {@link Console}.
|
|
284
|
+
*
|
|
285
|
+
* To use a `printf`-like API for string interpolation, use the {@link warn}
|
|
286
|
+
* or {@link w} functions.
|
|
287
|
+
*
|
|
288
|
+
* @param {LogMessage} msg The message to be logged.
|
|
289
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
290
|
+
* {@link Console.warn} function.
|
|
291
|
+
*
|
|
292
|
+
* @see {@link warn}
|
|
293
|
+
* @see {@link w}
|
|
294
|
+
*/
|
|
295
|
+
warnRaw(msg, ...args) {
|
|
296
|
+
this.consoleLog(true, 'warn', msg, ...args);
|
|
297
|
+
}
|
|
298
|
+
/** This function is just an alias to the {@link warn} function. */
|
|
299
|
+
w = this.warn;
|
|
300
|
+
/**
|
|
301
|
+
* Logs a message to the {@link Console.error} function using a `printf` style
|
|
302
|
+
* API for string interpolation.
|
|
303
|
+
*
|
|
304
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
305
|
+
* {@link errorRaw} function.
|
|
306
|
+
*
|
|
307
|
+
* @param {LogMessage} msg The message to be logged.
|
|
308
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
309
|
+
* string interpolation.
|
|
310
|
+
*
|
|
311
|
+
* @see {@link errorRaw}
|
|
312
|
+
* @see {@link e}
|
|
313
|
+
*/
|
|
314
|
+
error(msg, ...args) {
|
|
315
|
+
this.consoleLog(false, 'error', msg, ...args);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Logs a message to the {@link Console.error} function using the same API as
|
|
319
|
+
* the one offered by the {@link Console}.
|
|
320
|
+
*
|
|
321
|
+
* To use a `printf`-like API for string interpolation, use the {@link error}
|
|
322
|
+
* or {@link e} functions.
|
|
323
|
+
*
|
|
324
|
+
* @param {LogMessage} msg The message to be logged.
|
|
325
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
326
|
+
* {@link Console.error} function.
|
|
327
|
+
*
|
|
328
|
+
* @see {@link error}
|
|
329
|
+
* @see {@link e}
|
|
330
|
+
*/
|
|
331
|
+
errorRaw(msg, ...args) {
|
|
332
|
+
this.consoleLog(true, 'error', msg, ...args);
|
|
333
|
+
}
|
|
334
|
+
/** This function is just an alias to the {@link error} function. */
|
|
335
|
+
e = this.error;
|
|
336
|
+
/**
|
|
337
|
+
* Logs a message to the {@link Console.log} function using a `printf` style
|
|
338
|
+
* API for string interpolation.
|
|
339
|
+
*
|
|
340
|
+
* To use the same API as the one offered by the {@link Console}, use the
|
|
341
|
+
* {@link logRaw} function.
|
|
342
|
+
*
|
|
343
|
+
* @param {LogMessage} msg The message to be logged.
|
|
344
|
+
* @param {any[]} args A variadic argument to be used as arguments on the
|
|
345
|
+
* string interpolation.
|
|
346
|
+
*
|
|
347
|
+
* @see {@link logRaw}
|
|
348
|
+
*/
|
|
349
|
+
log(msg, ...args) {
|
|
350
|
+
this.consoleLog(false, 'log', msg, ...args);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Logs a message to the {@link Console.log} function using the same API as
|
|
354
|
+
* the one offered by the {@link Console}.
|
|
355
|
+
*
|
|
356
|
+
* To use a `printf`-like API for string interpolation, use the {@link error}
|
|
357
|
+
* function.
|
|
358
|
+
*
|
|
359
|
+
* @param {LogMessage} msg The message to be logged.
|
|
360
|
+
* @param {any[]} args A variadic argument to be passed down to the
|
|
361
|
+
* {@link Console.log} function.
|
|
362
|
+
*
|
|
363
|
+
* @see {@link log}
|
|
364
|
+
*/
|
|
365
|
+
logRaw(msg, ...args) {
|
|
366
|
+
this.consoleLog(true, 'log', msg, ...args);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
exports.Logger = Logger;
|
|
370
|
+
exports.Log = new Logger('com.amazon.kepler.tv.pnc');
|