Improve relay validation and add sort function

This commit is contained in:
Jon Staab
2024-05-24 08:53:36 -07:00
parent c5e3f6d5a4
commit 5ec54e3204
4 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -207,8 +207,10 @@ export const uniqBy = <T>(f: (x: T) => any, xs: T[]) => {
return r
}
export const sort = <T>(xs: T[]) => [...xs].sort()
export const sortBy = <T>(f: (x: T) => number, xs: T[]) =>
xs.sort((a: T, b: T) => f(a) - f(b))
[...xs].sort((a: T, b: T) => f(a) - f(b))
export const groupBy = <T, K>(f: (x: T) => K, xs: T[]) => {
const r = new Map<K, T[]>()
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/lib",
"version": "0.0.7",
"version": "0.0.8",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities.",
+2
View File
@@ -19,6 +19,8 @@ export const isShareableRelayUrl = (url: string) =>
!url.match(/\s|%/) &&
// Don't match stuff with a port number
!url.slice(6).match(/:\d+/) &&
// Don't match stuff with a numeric tld
!url.slice(6).match(/\.\d+\b/) &&
// Don't match raw ip addresses
!url.slice(6).match(/\d+\.\d+\.\d+\.\d+/) &&
// Skip nostr.wine's virtual relays
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/util",
"version": "0.0.10",
"version": "0.0.11",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of nostr-related utilities.",