Bug 1883449 - [wpt-sync] Update web-platform-tests to bb67daef8e6a384ead5da4c991c12f8...
[gecko.git] / devtools / shared / inspector / utils.js
blob3bd6b8edff0b85fea7ed2e8ae5548ec5e879c755
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 /**
8  * Truncate the string and add ellipsis to the middle of the string.
9  */
10 function truncateString(str, maxLength) {
11   if (!str || str.length <= maxLength) {
12     return str;
13   }
15   return (
16     str.substring(0, Math.ceil(maxLength / 2)) +
17     "…" +
18     str.substring(str.length - Math.floor(maxLength / 2))
19   );
22 exports.truncateString = truncateString;