| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import path from 'node:path'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | /** |
| b69ab31 | | | 11 | * Add a trailing path sep (/ or \) if one does not exist |
| b69ab31 | | | 12 | */ |
| b69ab31 | | | 13 | export function ensureTrailingPathSep(p: string): string { |
| b69ab31 | | | 14 | if (p.endsWith(path.sep)) { |
| b69ab31 | | | 15 | return p; |
| b69ab31 | | | 16 | } |
| b69ab31 | | | 17 | return p + path.sep; |
| b69ab31 | | | 18 | } |
| b69ab31 | | | 19 | |
| b69ab31 | | | 20 | /** |
| b69ab31 | | | 21 | * Remove leading path sep (/ or \) if one exists |
| b69ab31 | | | 22 | */ |
| b69ab31 | | | 23 | export function removeLeadingPathSep(p: string): string { |
| b69ab31 | | | 24 | if (p.startsWith(path.sep)) { |
| b69ab31 | | | 25 | return p.slice(1); |
| b69ab31 | | | 26 | } |
| b69ab31 | | | 27 | return p; |
| b69ab31 | | | 28 | } |