This repository has been archived by the owner on May 23, 2022. It is now read-only.
generated from pikadun/template
-
-
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.
- Loading branch information
Showing
7 changed files
with
107 additions
and
7 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ node_modules/ | |
|
||
# Compile output | ||
lib/ | ||
types/ | ||
types/*.ts | ||
!types/internal/commands.d.ts |
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 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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,36 @@ | ||
import axios from 'axios'; | ||
import { parse, Node } from 'node-html-parser'; | ||
|
||
interface Commands { | ||
command: string; | ||
args: string | null; | ||
summary: string; | ||
} | ||
|
||
async function dodo() { | ||
const res = await axios.get('https://redis.io/commands'); | ||
const html = await res.data; | ||
const root = parse(html); | ||
const commands = root.querySelectorAll('#commands li a') | ||
.map(e => e.childNodes.filter(cn => cn.nodeType === 1)) | ||
.map(e => handleHTMLElement(e)); | ||
|
||
convertCommandsToTypeScript(commands); | ||
} | ||
|
||
function handleHTMLElement(datas: Node[]) { | ||
const command = datas[0]?.childNodes[0]?.rawText.trim(); | ||
const args = datas[0]?.childNodes[1]?.childNodes[0]?.rawText.trim().split(/(\n| )+/).join('') || null; | ||
const summary = datas[1]?.childNodes[0]?.rawText.trim(); | ||
return { | ||
command, | ||
args, | ||
summary | ||
} as Commands; | ||
} | ||
|
||
function convertCommandsToTypeScript(commands: Commands[]) { | ||
console.log(commands); | ||
} | ||
|
||
dodo(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Socket } from 'net'; | ||
|
||
export interface IClientOptions { | ||
host?: string; | ||
port?: number; | ||
auth?: string; | ||
} | ||
|
||
interface IClient { | ||
connect(): void; | ||
} | ||
|
||
export class Client implements IClient { | ||
private socket = new Socket(); | ||
constructor( | ||
private readonly options: IClientOptions = {} | ||
) { | ||
this.initOptions(options); | ||
} | ||
|
||
public connect(): void { | ||
this.socket.connect( | ||
this.options.port as number, | ||
this.options.host as string | ||
); | ||
} | ||
|
||
private initOptions(options: IClientOptions): void { | ||
options.host = options.host || '127.0.0.1'; | ||
options.port = options.port || 6379; | ||
} | ||
} |
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 @@ | ||
export { Client, IClientOptions } from './client'; |