From 047d7fcab99e7f1be4276a3920cdaf7185822ecf Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 28 Jul 2025 22:31:00 +0000 Subject: [PATCH] BREAKING_CHANGE(iso): rename pathJoin to join for better API consistency --- changelog.md | 8 ++++++ package.json | 2 +- readme.md | 2 +- test/test.iso.both.ts | 64 +++++++++++++++++++++---------------------- ts_iso/index.ts | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/changelog.md b/changelog.md index f46c702..d621545 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ # Changelog +## [6.0.0] - 2025-01-28 + +### BREAKING CHANGES +- Renamed `pathJoin()` to `join()` for better API consistency and brevity + +### Changed +- Updated all references and tests to use the new `join()` function name + ## [5.1.0] - 2025-01-28 ### Added diff --git a/package.json b/package.json index 8b283b7..4317e9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@push.rocks/smartpath", - "version": "5.1.0", + "version": "6.0.0", "private": false, "description": "A library offering smart ways to handle file and directory paths.", "exports": { diff --git a/readme.md b/readme.md index a1042ae..4cca421 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,7 @@ For cross-platform path operations that work in any JavaScript environment (Node import * as isoPath from '@push.rocks/smartpath/iso'; // Join paths with automatic platform detection -const joinedPath = isoPath.pathJoin('/home/user', 'documents', 'file.txt'); +const joinedPath = isoPath.join('/home/user', 'documents', 'file.txt'); // Unix: /home/user/documents/file.txt // Windows: C:\Users\documents\file.txt diff --git a/test/test.iso.both.ts b/test/test.iso.both.ts index 710bde4..3c8cfe1 100644 --- a/test/test.iso.both.ts +++ b/test/test.iso.both.ts @@ -3,46 +3,46 @@ import * as smartpath from '../ts_iso/index.js'; tap.test('pathJoin - should join path segments correctly', async () => { // Basic path joining - expect(smartpath.pathJoin('path', 'to', 'file.txt')).toEqual('path/to/file.txt'); - expect(smartpath.pathJoin('/path', 'to', 'file.txt')).toEqual('/path/to/file.txt'); + expect(smartpath.join('path', 'to', 'file.txt')).toEqual('path/to/file.txt'); + expect(smartpath.join('/path', 'to', 'file.txt')).toEqual('/path/to/file.txt'); // Windows paths - expect(smartpath.pathJoin('C:', 'Users', 'test')).toEqual('C:\\Users\\test'); - expect(smartpath.pathJoin('C:\\Users', 'test', 'file.txt')).toEqual('C:\\Users\\test\\file.txt'); + expect(smartpath.join('C:', 'Users', 'test')).toEqual('C:\\Users\\test'); + expect(smartpath.join('C:\\Users', 'test', 'file.txt')).toEqual('C:\\Users\\test\\file.txt'); // Empty segments - expect(smartpath.pathJoin('path', '', 'file.txt')).toEqual('path/file.txt'); - expect(smartpath.pathJoin('', 'path', 'file.txt')).toEqual('path/file.txt'); + expect(smartpath.join('path', '', 'file.txt')).toEqual('path/file.txt'); + expect(smartpath.join('', 'path', 'file.txt')).toEqual('path/file.txt'); // No segments - expect(smartpath.pathJoin()).toEqual(''); - expect(smartpath.pathJoin('')).toEqual(''); + expect(smartpath.join()).toEqual(''); + expect(smartpath.join('')).toEqual(''); // Single segment - expect(smartpath.pathJoin('path')).toEqual('path'); - expect(smartpath.pathJoin('/path')).toEqual('/path'); + expect(smartpath.join('path')).toEqual('path'); + expect(smartpath.join('/path')).toEqual('/path'); // Multiple separators - expect(smartpath.pathJoin('path/', '/to/', '/file.txt')).toEqual('path/to/file.txt'); - expect(smartpath.pathJoin('path\\\\', '\\\\to\\\\', '\\\\file.txt')).toEqual('path\\to\\file.txt'); + expect(smartpath.join('path/', '/to/', '/file.txt')).toEqual('path/to/file.txt'); + expect(smartpath.join('path\\\\', '\\\\to\\\\', '\\\\file.txt')).toEqual('path\\to\\file.txt'); // Root paths - expect(smartpath.pathJoin('/')).toEqual('/'); - expect(smartpath.pathJoin('/', 'path')).toEqual('/path'); + expect(smartpath.join('/')).toEqual('/'); + expect(smartpath.join('/', 'path')).toEqual('/path'); }); tap.test('pathJoin - should handle file:// URLs', async () => { // Unix file URLs - expect(smartpath.pathJoin('file:///home/user', 'documents', 'file.txt')).toEqual('/home/user/documents/file.txt'); - expect(smartpath.pathJoin('file:///home/user/', 'documents')).toEqual('/home/user/documents'); + expect(smartpath.join('file:///home/user', 'documents', 'file.txt')).toEqual('/home/user/documents/file.txt'); + expect(smartpath.join('file:///home/user/', 'documents')).toEqual('/home/user/documents'); // Windows file URLs - expect(smartpath.pathJoin('file:///C:/Users', 'test', 'file.txt')).toEqual('C:\\Users\\test\\file.txt'); - expect(smartpath.pathJoin('file:///D:/Projects/', 'app')).toEqual('D:\\Projects\\app'); + expect(smartpath.join('file:///C:/Users', 'test', 'file.txt')).toEqual('C:\\Users\\test\\file.txt'); + expect(smartpath.join('file:///D:/Projects/', 'app')).toEqual('D:\\Projects\\app'); // Mixed file URL and path - expect(smartpath.pathJoin('file:///home/user', '../test')).toEqual('/home/user/../test'); - expect(smartpath.pathJoin('documents', 'file:///home/user/file.txt')).toEqual('documents/home/user/file.txt'); + expect(smartpath.join('file:///home/user', '../test')).toEqual('/home/user/../test'); + expect(smartpath.join('documents', 'file:///home/user/file.txt')).toEqual('documents/home/user/file.txt'); }); tap.test('fileUrlToPath - should convert file URLs to paths', async () => { @@ -110,36 +110,36 @@ tap.test('dirname - should extract directory from paths and URLs', async () => { tap.test('edge cases - should handle edge cases correctly', async () => { // Non-string values filtered out - expect(smartpath.pathJoin('path', null as any, 'file.txt')).toEqual('path/file.txt'); - expect(smartpath.pathJoin('path', undefined as any, 'file.txt')).toEqual('path/file.txt'); - expect(smartpath.pathJoin('path', 123 as any, 'file.txt')).toEqual('path/file.txt'); + expect(smartpath.join('path', null as any, 'file.txt')).toEqual('path/file.txt'); + expect(smartpath.join('path', undefined as any, 'file.txt')).toEqual('path/file.txt'); + expect(smartpath.join('path', 123 as any, 'file.txt')).toEqual('path/file.txt'); // Very long paths const longSegment = 'a'.repeat(100); - const result = smartpath.pathJoin(longSegment, longSegment, 'file.txt'); + const result = smartpath.join(longSegment, longSegment, 'file.txt'); expect(result).toEqual(`${longSegment}/${longSegment}/file.txt`); // Unicode characters - expect(smartpath.pathJoin('path', '文件夹', 'файл.txt')).toEqual('path/文件夹/файл.txt'); + expect(smartpath.join('path', '文件夹', 'файл.txt')).toEqual('path/文件夹/файл.txt'); expect(smartpath.fileUrlToPath('file:///home/用户/文件.txt')).toEqual('/home/用户/文件.txt'); expect(smartpath.pathToFileUrl('/home/用户/文件.txt')).toEqual('file:///home/%E7%94%A8%E6%88%B7/%E6%96%87%E4%BB%B6.txt'); // Backslashes in Unix-style paths (should be preserved) - expect(smartpath.pathJoin('/home/user', 'path\\with\\backslashes')).toEqual('/home/user/path\\with\\backslashes'); + expect(smartpath.join('/home/user', 'path\\with\\backslashes')).toEqual('/home/user/path\\with\\backslashes'); }); tap.test('cross-platform behavior - should detect separators correctly', async () => { // Should detect Windows paths and use backslashes - expect(smartpath.pathJoin('C:\\Users', 'test')).toEqual('C:\\Users\\test'); - expect(smartpath.pathJoin('D:', 'Projects', 'app')).toEqual('D:\\Projects\\app'); + expect(smartpath.join('C:\\Users', 'test')).toEqual('C:\\Users\\test'); + expect(smartpath.join('D:', 'Projects', 'app')).toEqual('D:\\Projects\\app'); // Should detect Unix paths and use forward slashes - expect(smartpath.pathJoin('/home', 'user')).toEqual('/home/user'); - expect(smartpath.pathJoin('/var', 'log', 'app.log')).toEqual('/var/log/app.log'); + expect(smartpath.join('/home', 'user')).toEqual('/home/user'); + expect(smartpath.join('/var', 'log', 'app.log')).toEqual('/var/log/app.log'); // Mixed paths - first segment determines separator - expect(smartpath.pathJoin('C:\\Users', 'test/file.txt')).toEqual('C:\\Users\\test\\file.txt'); - expect(smartpath.pathJoin('/home', 'user\\documents')).toEqual('/home/user\\documents'); + expect(smartpath.join('C:\\Users', 'test/file.txt')).toEqual('C:\\Users\\test\\file.txt'); + expect(smartpath.join('/home', 'user\\documents')).toEqual('/home/user\\documents'); }); await tap.start(); \ No newline at end of file diff --git a/ts_iso/index.ts b/ts_iso/index.ts index 26f7a3a..2eee10f 100644 --- a/ts_iso/index.ts +++ b/ts_iso/index.ts @@ -4,7 +4,7 @@ * @param segments - Path segments to join * @returns Joined path string */ -export function pathJoin(...segments: string[]): string { +export function join(...segments: string[]): string { // Filter out empty strings and non-string values const validSegments = segments.filter(segment => typeof segment === 'string' && segment.length > 0