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