Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions src/Util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,50 +259,50 @@ describe('Util', () => {

it('should throw on error response', async () => {
await expect(Util.fetch('https://¤.com')).rejects.toThrow(Error);
});
});

describe('path functions', () => {
it('should get extension from path', () => {
expect(Util.getExtension('file.txt')).toBe('.txt');
expect(Util.getExtension('path/to/file.txt')).toBe('.txt');
expect(Util.getExtension('file')).toBe('');
expect(Util.getExtension('path/to/file.txt')).toBe('.txt');
expect(Util.getExtension('path/to/.txt')).toBe('.txt');
expect(Util.getExtension('.txt')).toBe('.txt');
expect(Util.getExtension('path/to/file.txt.')).toBe('.');
});

it('should get file from path', () => {
expect(Util.getFile('file.txt')).toBe('file.txt');
expect(Util.getFile('path/to/file.txt')).toBe('file.txt');
});

it('should get base file without extension', () => {
expect(Util.getBaseFile('file.txt')).toBe('file');
expect(Util.getBaseFile('path/to/file.txt')).toBe('file');
expect(Util.getBaseFile('file')).toBe('file');
});
});
describe('path functions', () => {
it('should get extension from path', () => {
expect(Util.getExtension('file.txt')).toBe('.txt');
expect(Util.getExtension('path/to/file.txt')).toBe('.txt');
expect(Util.getExtension('file')).toBe('');
expect(Util.getExtension('path/to/file.txt')).toBe('.txt');
expect(Util.getExtension('path/to/.txt')).toBe('.txt');
expect(Util.getExtension('.txt')).toBe('.txt');
expect(Util.getExtension('path/to/file.txt.')).toBe('.');
});

describe('string trim functions', () => {
it('should trim spaces', () => {
expect(Util.trim(' hello ')).toBe('hello');
});

it('should trim custom characters', () => {
expect(Util.trim('xxhelloxx', 'x')).toBe('hello');
expect(Util.trim('xxhello😭xx', 'x😭')).toBe('hello');
});

it('should trim start only', () => {
expect(Util.trimStart(' hello ')).toBe('hello ');
expect(Util.trimStart('😭hello😭', '😭')).toBe('hello😭');
});

it('should trim end only', () => {
expect(Util.trimEnd(' hello ')).toBe(' hello');
expect(Util.trimEnd('😭hello😭', '😭')).toBe('😭hello');
});
});
it('should get file from path', () => {
expect(Util.getFile('file.txt')).toBe('file.txt');
expect(Util.getFile('path/to/file.txt')).toBe('file.txt');
});

it('should get base file without extension', () => {
expect(Util.getBaseFile('file.txt')).toBe('file');
expect(Util.getBaseFile('path/to/file.txt')).toBe('file');
expect(Util.getBaseFile('file')).toBe('file');
});
});

describe('string trim functions', () => {
it('should trim spaces', () => {
expect(Util.trim(' hello ')).toBe('hello');
});

it('should trim custom characters', () => {
expect(Util.trim('xxhelloxx', 'x')).toBe('hello');
expect(Util.trim('xxhello😭xx', 'x😭')).toBe('hello');
});

it('should trim start only', () => {
expect(Util.trimStart(' hello ')).toBe('hello ');
expect(Util.trimStart('😭hello😭', '😭')).toBe('hello😭');
});

it('should trim end only', () => {
expect(Util.trimEnd(' hello ')).toBe(' hello');
expect(Util.trimEnd('😭hello😭', '😭')).toBe('😭hello');
});
});

Expand Down
7 changes: 3 additions & 4 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,10 @@ export function trimEnd(value: string, chars: string = ' '): string {
* Property lookup (e.g. `obj.Foo` or `obj.foo`) will resolve to the same underlying key, regardless of casing.
* Only affects string-based property access (not symbols).
*
* @template T
* @param {T} obj - The original object.
* @returns {T} A proxied object with case-insensitive property access.
* @param obj - The original object.
* @returns A proxied object with case-insensitive property access.
*/
export function caseInsensitive<T extends Record<string, any>>(obj: any): T {
export function caseInsensitive(obj: any): Record<string, any> {
return new Proxy(obj, {
get(target, prop, receiver) {
if (typeof prop === 'string') {
Expand Down
Loading