Skip to content

Commit

Permalink
Update example codes
Browse files Browse the repository at this point in the history
  • Loading branch information
simnalamburt committed Feb 5, 2025
1 parent b09ba62 commit 2df77c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ pnpm add -D slate-irc-parser
```
```js
import Parser from 'slate-irc-parser'
import net from 'net'

const client = net.connect({
port: 6667,
host: 'irc.freenode.org'
})
import { connect } from 'node:tls'

const parser = new Parser()

client.pipe(parser)

parser.on('message', (msg) => {
console.log()
console.log(msg)
})

const client = connect({
port: 6697,
host: 'irc.libera.chat',
})
client.pipe(parser)
```

--------
Expand Down
19 changes: 7 additions & 12 deletions examples/net.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
const Parser = require('..')
const net = require('net')

const client = net.connect({
port: 6667,
host: 'irc.freenode.org',
})
import Parser from '../dist/slate-irc-parser.modern.mjs'
import { connect } from 'node:tls'

const parser = new Parser()
parser.on('message', console.log)

client.pipe(parser)

parser.on('message', (msg) => {
console.log()
console.log(msg)
const client = connect({
port: 6697,
host: 'irc.libera.chat',
})
client.pipe(parser)
24 changes: 13 additions & 11 deletions examples/string.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const Parser = require('..')
import Parser from '../dist/slate-irc-parser.modern.mjs'

const parser = new Parser()
const lines = [
`:molybdenum.libera.chat NOTICE * :*** Checking Ident\r\n`,
`:molybdenum.libera.chat NOTICE * :*** Looking up your hostname...\r\n`,
`:molybdenum.libera.chat NOTICE * :*** No Ident response\r\n`,
`:molybdenum.libera.chat NOTICE * :*** Couldn't look up your hostname\r\n`,
`ERROR :Closing Link: 127.0.0.1 (Connection timed out)\r\n`,
]

parser.on('message', (msg) => {
console.log()
console.log(msg)
})
const parser = new Parser()
parser.on('message', console.log)

parser.write(
':hitchcock.freenode.net NOTICE * :*** Looking up your hostname...\r\n',
)
parser.write(':hitchcock.freenode.net NOTICE * :*** Checking Ident\r\n')
parser.write('ERROR :Closing Link: 127.0.0.1 (Connection timed out)\r\n')
for (const line of lines) {
parser.write(line)
}

0 comments on commit 2df77c5

Please sign in to comment.