mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 05:55:03 +01:00
feat(utils): new util isFullPath
This commit is contained in:
committed by
Carlos García Ortiz
parent
786007e6ae
commit
5c5a14a220
@@ -44,3 +44,4 @@ export * from './logsManager';
|
||||
export * from './bigNumber';
|
||||
export * from './throttler';
|
||||
export * from './extractUrlsFromText';
|
||||
export * from './isFullPath';
|
||||
|
||||
5
packages/utils/src/isFullPath.ts
Normal file
5
packages/utils/src/isFullPath.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const isFullPath = (path: string) => {
|
||||
const fullPathPattern = /^(\/|([a-zA-Z]:\\))/;
|
||||
|
||||
return fullPathPattern.test(path);
|
||||
};
|
||||
27
packages/utils/tests/isFullPath.test.ts
Normal file
27
packages/utils/tests/isFullPath.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user