feat(utils): new util isFullPath

This commit is contained in:
Carlos Garcia Ortiz karliatto
2024-07-30 18:18:00 +02:00
committed by Carlos García Ortiz
parent 786007e6ae
commit 5c5a14a220
3 changed files with 33 additions and 0 deletions

View File

@@ -44,3 +44,4 @@ export * from './logsManager';
export * from './bigNumber';
export * from './throttler';
export * from './extractUrlsFromText';
export * from './isFullPath';

View File

@@ -0,0 +1,5 @@
export const isFullPath = (path: string) => {
const fullPathPattern = /^(\/|([a-zA-Z]:\\))/;
return fullPathPattern.test(path);
};

View File

@@ -0,0 +1,27 @@
import { isFullPath } from '../src/isFullPath';
describe('isFullPath', () => {
it('should identify valid full paths', () => {
// Unix-like full path with extension
expect(isFullPath('/home/user/file.txt')).toBe(true);
// Windows full path with extension
expect(isFullPath('C:\\Users\\file.txt')).toBe(true);
// Unix-like full path without extension
expect(isFullPath('/home/user/directory')).toBe(true);
// Windows full path without extension
expect(isFullPath('C:\\Users\\directory')).toBe(true);
});
it('should not identify invalid or relative paths', () => {
// Relative path
expect(isFullPath('relative/path/to/file.js')).toBe(false);
// Simple filename with extension
expect(isFullPath('file.txt')).toBe(false);
// Random string
expect(isFullPath('not a path')).toBe(false);
// URL
expect(isFullPath('http://example.com')).toBe(false);
// Unix-like relative path
expect(isFullPath('./relative/path')).toBe(false);
});
});