util: isPathRelativeTo func

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-07-04 16:33:39 +02:00
parent a777edf0f6
commit 491039b9e3
2 changed files with 35 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import * as core from '@actions/core';
import * as io from '@actions/io';
import {parse} from 'csv-parse/sync';
@@ -189,4 +190,10 @@ export class Util {
public static countLines(input: string): number {
return input.split(/\r\n|\r|\n/).length;
}
public static isPathRelativeTo(parentPath: string, childPath: string): boolean {
const rpp = path.resolve(parentPath);
const rcp = path.resolve(childPath);
return rcp.startsWith(rpp.endsWith(path.sep) ? rpp : `${rpp}${path.sep}`);
}
}