UNPKG

1.42 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License.
5 */
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.StringUtils = void 0;
8/**
9 * @hidden
10 */
11var StringUtils = /** @class */ (function () {
12 function StringUtils() {
13 }
14 /**
15 * Check if a string is empty
16 *
17 * @param str
18 */
19 StringUtils.isEmpty = function (str) {
20 return (typeof str === "undefined" || !str || 0 === str.length);
21 };
22 /**
23 * Check if a string's value is a valid JSON object
24 *
25 * @param str
26 */
27 StringUtils.validateAndParseJsonCacheKey = function (str) {
28 try {
29 var parsedKey = JSON.parse(str);
30 /**
31 * There are edge cases in which JSON.parse will successfully parse a non-valid JSON object
32 * (e.g. JSON.parse will parse an escaped string into an unescaped string), so adding a type check
33 * of the parsed value is necessary in order to be certain that the string represents a valid JSON object.
34 *
35 */
36 return (parsedKey && typeof parsedKey === "object") ? parsedKey : null;
37 }
38 catch (error) {
39 return null;
40 }
41 };
42 return StringUtils;
43}());
44exports.StringUtils = StringUtils;
45//# sourceMappingURL=StringUtils.js.map
\No newline at end of file