mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
This rule matches the Chromium-wide coding style. Bug: chromium:1057042 Change-Id: I21ad946227ca7344146abace1d2f6146b3a6c207 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2078924 Commit-Queue: Mathias Bynens <mathias@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
// Copyright 2018 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as Common from '../common/common.js';
|
|
|
|
import * as Host from '../host/host.js';
|
|
|
|
export class NodeURL {
|
|
/**
|
|
* @param {!Object} object
|
|
*/
|
|
static patch(object) {
|
|
process(object, '');
|
|
|
|
/**
|
|
* @param {!Object} object
|
|
* @param {string} path
|
|
*/
|
|
function process(object, path) {
|
|
if (object.url && NodeURL._isPlatformPath(object.url, Host.Platform.isWin())) {
|
|
object.url = Common.ParsedURL.ParsedURL.platformPathToURL(object.url);
|
|
}
|
|
for (const entry of Object.entries(object)) {
|
|
const key = entry[0];
|
|
const value = entry[1];
|
|
const entryPath = path + '.' + key;
|
|
if (entryPath !== '.result.result.value' && value !== null && typeof value === 'object') {
|
|
process(value, entryPath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {string} fileSystemPath
|
|
* @param {boolean} isWindows
|
|
* @return {boolean}
|
|
*/
|
|
static _isPlatformPath(fileSystemPath, isWindows) {
|
|
if (isWindows) {
|
|
const re = /^([a-z]:[\/\\]|\\\\)/i;
|
|
return re.test(fileSystemPath);
|
|
}
|
|
return fileSystemPath.length ? fileSystemPath[0] === '/' : false;
|
|
}
|
|
}
|