@gpa-gemstone/helper-functions
Version:
Helper Functions for gpa-gemstone packages
62 lines (61 loc) • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JoinKeyValuePairs = void 0;
// ******************************************************************************************************
// JoinKeyValuePairs.tsx - Gbtc
//
// Copyright © 2025, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 11/09/2023 - Preston Crawford
// Migrated code from GSF.
//
// ******************************************************************************************************
var IsBool_1 = require("./IsBool");
/**
* Combines an object of key/value pairs into a delimited string.
*
* @param source - An object of kvp pairs.
* @param parameterDelimiter - Delimiter between parameters (default `";"`).
* @param keyValueDelimiter - Delimiter between key and value (default `"="`).
* @param startValueDelimiter - Delimiter to wrap the start of values containing delimiters (default `"{"`).
* @param endValueDelimiter - Delimiter to wrap the end of values containing delimiters (default `"}"`).
* @returns A string of joined key/value pairs
*/
var JoinKeyValuePairs = function (source, parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter) {
var _a;
if (parameterDelimiter === void 0) { parameterDelimiter = ";"; }
if (keyValueDelimiter === void 0) { keyValueDelimiter = "="; }
if (startValueDelimiter === void 0) { startValueDelimiter = "{"; }
if (endValueDelimiter === void 0) { endValueDelimiter = "}"; }
var values = [];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
var value = source[key];
if ((0, IsBool_1.IsBool)(value !== null && value !== void 0 ? value : ''))
value = value.toString().toLowerCase();
else
value = value != null ? ((_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : '') : '';
if (value.indexOf(parameterDelimiter) >= 0 ||
value.indexOf(keyValueDelimiter) >= 0 ||
value.indexOf(startValueDelimiter) >= 0 ||
value.indexOf(endValueDelimiter) >= 0)
value = startValueDelimiter + value + endValueDelimiter;
values.push(key + keyValueDelimiter + value);
}
}
return values.join(parameterDelimiter + " ");
};
exports.JoinKeyValuePairs = JoinKeyValuePairs;