You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
venv/PyCharm 2025.2.1.1/plugins/javascript-plugin/helpers/protractor-intellij/lib/protractor-intellij-stringi...

81 lines
1.6 KiB

/**
* @param {*} value
* @return {string}
*/
function stringify(value) {
var str = doStringify(value);
if (isString(str)) {
return str;
}
return 'Oops, something went wrong: IDE failed to stringify ' + typeof value;
}
var toString = {}.toString;
/**
* @param {*} value
* @return {boolean}
*/
function isString(value) {
return typeof value === 'string' || toString.call(value) === '[object String]';
}
/**
* @param {*} value
* @return {string}
*/
function doStringify(value) {
var normalizedValue = deepCopyAndNormalize(value);
if (normalizedValue instanceof RegExp) {
return normalizedValue.toString();
}
if (normalizedValue === undefined) {
return 'undefined';
}
return JSON.stringify(normalizedValue, null, 2);
}
function isObject(val) {
return val === Object(val);
}
function deepCopyAndNormalize(value) {
var cache = [];
return (function doCopy(value) {
if (value == null) {
return value;
}
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string') {
return value;
}
if (value instanceof RegExp) {
return value;
}
if (cache.indexOf(value) !== -1) {
return '[Circular reference found] Truncated by IDE';
}
cache.push(value);
if (Array.isArray(value)) {
return value.map(function (element) {
return doCopy(element);
});
}
if (isObject(value)) {
var keys = Object.keys(value);
keys.sort();
var ret = {};
keys.forEach(function (key) {
ret[key] = doCopy(value[key]);
});
return ret;
}
return value;
})(value);
}
exports.stringify = stringify;