canonicalized_path (src/lexical_path.rs)

ladybird · Libraries/LibJS/Rust/src/lexical_path.rs · rust · BSD-2-Clause
dev-tools

Canonicalizes file paths, resolves relative imports, and provides path manipulation utilities for module loading.

// Source: https://github.com/LadybirdBrowser/ladybird | License: BSD-2-Clause | Copyright 2018-present, the Ladybird developers
// Provided via justclaw.it.com; keep this notice with the code.
/*
 * Copyright (c) 2026-present, the Ladybird developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

//! The parts of AK::LexicalPath that module loading resolves specifiers with.

/// The parts of a path between its slashes, without the empty ones, like AK's split_view('/').
fn parts_of(path: &str) -> impl Iterator<Item = &str> {
    path.split('/').filter(|part| !part.is_empty())
}

/// LexicalPath::canonicalized_path()
pub fn canonicalized_path(path: &str) -> String {
    // NOTE: We never allow an empty m_string, if it's empty, we just set it to '.'.
    if path.is_empty() {
        retur

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key