UNPKG

3.25 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2018, OpenCensus Authors
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.isToValueInterface = exports.isSizeMethodInterface = exports.isSizeAttributeInterface = exports.isLengthMethodInterface = exports.isLengthAttributeInterface = exports.initializeDefaultLabels = exports.hashLabelValues = void 0;
19const COMMA_SEPARATOR = ',';
20const UNSET_LABEL_VALUE = {
21 value: null,
22};
23/**
24 * Returns a string(comma separated) from the list of label values.
25 *
26 * @param labelValues The list of the label values.
27 * @returns The hashed label values string.
28 */
29function hashLabelValues(labelValues) {
30 return labelValues
31 .map(lv => lv.value)
32 .sort()
33 .join(COMMA_SEPARATOR);
34}
35exports.hashLabelValues = hashLabelValues;
36/**
37 * Returns default label values.
38 *
39 * @param count The number of label values.
40 * @returns The list of the label values.
41 */
42function initializeDefaultLabels(count) {
43 return new Array(count).fill(UNSET_LABEL_VALUE);
44}
45exports.initializeDefaultLabels = initializeDefaultLabels;
46// TODO(mayurkale): Consider to use unknown type instead of any for below
47// functions, unknown type is available since TypeScript 3.0
48// Fact: unknown acts like a type-safe version of any by requiring us to
49// perform some type of checking before we can use the value of the unknown
50// element or any of its properties.
51// Checks if the specified collection is a LengthAttributeInterface.
52function isLengthAttributeInterface(
53// tslint:disable-next-line:no-any
54obj) {
55 return obj && typeof obj.length === 'number';
56}
57exports.isLengthAttributeInterface = isLengthAttributeInterface;
58// Checks if the specified collection is a LengthMethodInterface.
59function isLengthMethodInterface(
60// tslint:disable-next-line:no-any
61obj) {
62 return obj && typeof obj.length === 'function';
63}
64exports.isLengthMethodInterface = isLengthMethodInterface;
65// Checks if the specified collection is a SizeAttributeInterface.
66function isSizeAttributeInterface(
67// tslint:disable-next-line:no-any
68obj) {
69 return obj && typeof obj.size === 'number';
70}
71exports.isSizeAttributeInterface = isSizeAttributeInterface;
72// Checks if the specified collection is a SizeMethodInterface.
73// tslint:disable-next-line:no-any
74function isSizeMethodInterface(obj) {
75 return obj && typeof obj.size === 'function';
76}
77exports.isSizeMethodInterface = isSizeMethodInterface;
78// Checks if the specified callbackFn is a ToValueInterface.
79// tslint:disable-next-line:no-any
80function isToValueInterface(obj) {
81 return obj && typeof obj.getValue === 'function';
82}
83exports.isToValueInterface = isToValueInterface;
84//# sourceMappingURL=utils.js.map
\No newline at end of file