-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: big rework of the system and namings
- Loading branch information
Showing
16 changed files
with
787 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
export type HostId = `${string}@${string}` | ||
export function parseHostId( | ||
settings: { | ||
host: string, | ||
user?: string, | ||
port?: number, | ||
} | ||
): HostId { | ||
const value = | ||
(settings.user ?? "root") + | ||
"@" + | ||
settings.host + | ||
":" + | ||
(settings.port ?? 22) | ||
|
||
if (!isHostId(value)) { | ||
throw new Error("Value '" + value + "' is not a valid host id") | ||
} | ||
|
||
return value | ||
} | ||
|
||
export const allowedRuleChars = | ||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.:" | ||
|
||
export const allowedIdRuleChars = | ||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@" | ||
|
||
export function throwCharsetError( | ||
value: string, | ||
chatSet: string, | ||
): void | never { | ||
for (const char of value) { | ||
if (!chatSet.includes(char)) { | ||
throw new Error("Illegal character in selector value: '" + char + "'") | ||
} | ||
} | ||
} | ||
|
||
export function matchesCharset( | ||
value: string, | ||
chatSet: string, | ||
): boolean { | ||
for (const char of value) { | ||
if (!chatSet.includes(char)) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
export function isHostId( | ||
value: any | ||
): value is HostId { | ||
if (typeof value !== "string") { | ||
return false | ||
} | ||
|
||
if (!value.includes("@")) { | ||
return false | ||
} | ||
|
||
const parts = value.split("@") | ||
if ( | ||
parts.length != 2 || | ||
parts[0].length == 0 || | ||
parts[1].length == 0 | ||
) { | ||
return false | ||
} | ||
|
||
if ( | ||
!matchesCharset( | ||
parts[0], | ||
allowedRuleChars | ||
) | ||
) { | ||
return false | ||
} | ||
|
||
if ( | ||
!matchesCharset( | ||
parts[1], | ||
allowedRuleChars + ".:" | ||
) | ||
) { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.