generated from TypeScriptPlayground/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* This function generates the body part with indentation. | ||
*/ | ||
export default function bodyPart( | ||
content : string, | ||
indentation : number = 2 | ||
): string { | ||
return `${' '.repeat(indentation)}${content}\n` | ||
} |
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,3 @@ | ||
export default function footer() : string { | ||
return '\n' | ||
} |
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,5 @@ | ||
import timestamp from './timestamp.ts'; | ||
|
||
export default function header(title : string) : string { | ||
return `[${timestamp()}] ${title}:\n` | ||
} |
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,17 @@ | ||
/** | ||
* This function generates the timestamp prefix for logging. Format: `<date>, <time>` | ||
*/ | ||
export default function timestamp() : string { | ||
return new Date().toLocaleDateString( | ||
undefined, | ||
{ | ||
day: '2-digit', | ||
month: '2-digit', | ||
year: 'numeric', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit', | ||
hour12: false | ||
} | ||
) | ||
} |
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,12 @@ | ||
import bodyPart from './generator/body_part.ts'; | ||
import footer from './generator/footer.ts'; | ||
import header from './generator/header.ts'; | ||
|
||
export default function newRequest() : void { | ||
console.log( | ||
header('New Request') + | ||
bodyPart('Type: ') + | ||
bodyPart('Type: ') + | ||
footer() | ||
) | ||
} |
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,15 @@ | ||
import { DNSRecord } from '../record/dns_record.ts'; | ||
import timestamp from './generator/timestamp.ts'; | ||
|
||
export default function recordUpdated(record : DNSRecord) : void { | ||
console.group(`[${timestamp()}] Record Updated`) | ||
console.info(`Type: \t${record.type}`) | ||
console.info(`Content: \t${record.content}`) | ||
console.info(`Name: \t${record.name}`) | ||
record.proxied !== undefined && console.info(`Proxied: \t${record.proxied ? 'yes' : 'no'}`) | ||
record.comment !== undefined && console.info(`Comment: \t"${record.comment}"`) | ||
record.ttl !== undefined && console.info(`TTL: \t${record.ttl === 0 ? 'auto' : record.ttl}`) | ||
console.groupEnd() | ||
} | ||
|
||
recordUpdated({type: 'A', content: '1.1.1.1', name: 'example.com'}) |