addons/shared/pathUtils.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import path from 'node:path';
b69ab319
b69ab3110/**
b69ab3111 * Add a trailing path sep (/ or \) if one does not exist
b69ab3112 */
b69ab3113export function ensureTrailingPathSep(p: string): string {
b69ab3114 if (p.endsWith(path.sep)) {
b69ab3115 return p;
b69ab3116 }
b69ab3117 return p + path.sep;
b69ab3118}
b69ab3119
b69ab3120/**
b69ab3121 * Remove leading path sep (/ or \) if one exists
b69ab3122 */
b69ab3123export function removeLeadingPathSep(p: string): string {
b69ab3124 if (p.startsWith(path.sep)) {
b69ab3125 return p.slice(1);
b69ab3126 }
b69ab3127 return p;
b69ab3128}