mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 04:26:32 +08:00
- Update Sinon (breaking change does not affect us) - Update Mocha - Update Karma R=jacktfranklin@chromium.org Bug: none Change-Id: Ieb50ba55ce7a9e01e32ee553a6741e6323fcaaab Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3158223 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
"use strict";
|
|
|
|
var slice = require("@sinonjs/commons").prototypes.string.slice;
|
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|
var valueToString = require("@sinonjs/commons").valueToString;
|
|
|
|
/**
|
|
* Creates a string represenation of an iterable object
|
|
*
|
|
* @private
|
|
* @param {object} obj The iterable object to stringify
|
|
* @returns {string} A string representation
|
|
*/
|
|
function iterableToString(obj) {
|
|
if (typeOf(obj) === "map") {
|
|
return mapToString(obj);
|
|
}
|
|
|
|
return genericIterableToString(obj);
|
|
}
|
|
|
|
/**
|
|
* Creates a string representation of a Map
|
|
*
|
|
* @private
|
|
* @param {Map} map The map to stringify
|
|
* @returns {string} A string representation
|
|
*/
|
|
function mapToString(map) {
|
|
var representation = "";
|
|
|
|
// eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
|
|
map.forEach(function (value, key) {
|
|
representation += `[${stringify(key)},${stringify(value)}],`;
|
|
});
|
|
|
|
representation = slice(representation, 0, -1);
|
|
return representation;
|
|
}
|
|
|
|
/**
|
|
* Create a string represenation for an iterable
|
|
*
|
|
* @private
|
|
* @param {object} iterable The iterable to stringify
|
|
* @returns {string} A string representation
|
|
*/
|
|
function genericIterableToString(iterable) {
|
|
var representation = "";
|
|
|
|
// eslint-disable-next-line @sinonjs/no-prototype-methods/no-prototype-methods
|
|
iterable.forEach(function (value) {
|
|
representation += `${stringify(value)},`;
|
|
});
|
|
|
|
representation = slice(representation, 0, -1);
|
|
return representation;
|
|
}
|
|
|
|
/**
|
|
* Creates a string representation of the passed `item`
|
|
*
|
|
* @private
|
|
* @param {object} item The item to stringify
|
|
* @returns {string} A string representation of `item`
|
|
*/
|
|
function stringify(item) {
|
|
return typeof item === "string" ? `'${item}'` : valueToString(item);
|
|
}
|
|
|
|
module.exports = iterableToString;
|