Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osslate/irc-message
Performant, streaming IRC message parser
https://github.com/osslate/irc-message
Last synced: 2 days ago
JSON representation
Performant, streaming IRC message parser
- Host: GitHub
- URL: https://github.com/osslate/irc-message
- Owner: osslate
- License: bsd-2-clause
- Created: 2013-12-01T18:51:03.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-08T17:33:28.000Z (over 9 years ago)
- Last Synced: 2024-11-30T13:57:55.112Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 326 KB
- Stars: 92
- Watchers: 7
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-twitch-dev - osslate/irc-message - Performant, streaming IRC message parser. (Libraries / JavaScript (Node.js))
README
# irc-message [![Build Status](https://travis-ci.org/expr/irc-message.svg?branch=master)](https://travis-ci.org/expr/irc-message)
> Performant, streaming IRC message parserirc-message provides an object stream capable of parsing [RFC1459-compliant IRC messages](http://tools.ietf.org/html/rfc2812#section-2.3.1), with support for [IRCv3 message tags](https://github.com/ircv3/ircv3-specifications/blob/master/specification/message-tags-3.2.md). This also includes server-to-server protocols such as TS6, Spanning Tree, and the UnrealIRCd protocol.
## Installation
npm install irc-message
## Usage
### `createStream(options)`
Returns an object stream, taking in `Buffer`s/`String`s of raw IRC data. Data should not be line-buffered, this stream handles splitting and buffering automatically. and pushing objects containing the following keys.
* `raw` - unparsed IRC message (string)
* `tags` - IRCv3 message tags
* `prefix` - message prefix/source
* `command` - message command/verb
* `params` - an array of middle and trailing parametersOptional `options` object supports
* `parsePrefix` - replace the prefix with an object generated by _[irc-prefix-parser](https://github.com/expr/irc-prefix-parser)_. Defaults to `false`.
* `convertTimestamp` - if the message has a _time_ tag, convert it into a JavaScript `Date` object (see _[server-time](https://github.com/ircv3/ircv3-specifications/blob/master/extensions/server-time-3.2.md)_ spec for reference). Defaults to `false`.```js
var net = require('net')
var ircMsg = require('irc-message')net.connect(6667, 'irc.freenode.net')
.pipe(ircMsg.createStream())
.on('data', function(message) {
console.log(message)
})
```### `parse(data)`
You can also access the message parser directly. The parser function expects a string without any CRLF sequences. If the string is malformed, `null` is returned. Otherwise, an object representing the message is returned (see `createStream()` for format).
```js
var parse = require('irc-message').parseconsole.log(parse(':hello!sir@madam PRIVMSG #test :Hello, world!'))
/* {
* raw: ':hello!sir@madam PRIVMSG #test :Hello, world!',
* tags: {},
* prefix: 'hello!sir@madam',
* command: 'PRIVMSG',
* params: ['#test', 'Hello, world!']
* }
*/
```