Skip to content

Commit

Permalink
add format_url and module /url.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Mar 26, 2024
1 parent 969fe66 commit 1843c6c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-cherries-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ryanatkn/belt": patch
---

add `format_url` and module `$lib/url.ts`
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
"./types.js": {
"default": "./dist/types.js",
"types": "./dist/types.d.ts"
},
"./url.js": {
"default": "./dist/url.js",
"types": "./dist/url.d.ts"
}
}
}
17 changes: 17 additions & 0 deletions src/lib/url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {test} from 'uvu';
import * as assert from 'uvu/assert';

import {format_url} from './url.js';

test('format_url', () => {
assert.is(format_url('https://www.fuz.dev/'), 'fuz.dev');
assert.is(format_url('www.fuz.dev/'), 'fuz.dev');
assert.is(format_url('www.fuz.dev'), 'fuz.dev');
assert.is(format_url('https://fuz.dev/'), 'fuz.dev');
assert.is(format_url('https://fuz.dev'), 'fuz.dev');
assert.is(format_url('fuz.dev'), 'fuz.dev');
assert.is(format_url('http://fuz.dev'), 'http://fuz.dev');
assert.is(format_url('/'), '');
});

test.run();
4 changes: 4 additions & 0 deletions src/lib/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {strip_end, strip_start} from './string.js';

export const format_url = (url: string): string =>
strip_end(strip_start(strip_start(url, 'https://'), 'www.'), '/');
2 changes: 2 additions & 0 deletions src/routes/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const package_json = {
'./string.js': {default: './dist/string.js', types: './dist/string.d.ts'},
'./timings.js': {default: './dist/timings.js', types: './dist/timings.d.ts'},
'./types.js': {default: './dist/types.js', types: './dist/types.d.ts'},
'./url.js': {default: './dist/url.js', types: './dist/url.d.ts'},
},
} satisfies Package_Json;

Expand Down Expand Up @@ -385,6 +386,7 @@ export const src_json = {
{name: 'Brand', kind: 'type'},
],
},
'./url.js': {path: 'url.ts', declarations: [{name: 'format_url', kind: 'function'}]},
},
} satisfies Src_Json;

Expand Down

0 comments on commit 1843c6c

Please sign in to comment.