npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

irc-formatting

v1.0.0-rc3

Published

IRC formatting parser

Downloads

103

Readme

IRC Formatting

Turns IRC formatted text into easy to use blocks. This library is meant to parse and facilitate compiling to and from the irc caret notation. If you're looking for a means to style messages that your bot sends out, or merely strip the formatting, I'd suggest you check out irc-colors instead.

Installation

npm install irc-formatting --save

Usage

> var ircf = require('irc-formatting');
> s = "Hello, \x02World\x0304,07!\x03\x02";
> b = ircf.parse(s);
[ Block {
    text: 'Hello, ',
    bold: false,
    italic: false,
    underline: false,
    reverse: false,
    color: -1,
    highlight: -1 },
  Block {
    text: 'World',
    bold: true,
    italic: false,
    underline: false,
    reverse: false,
    color: -1,
    highlight: -1 },
  Block {
    text: '!',
    bold: true,
    italic: false,
    underline: false,
    reverse: false,
    color: 4,
    highlight: 7 } ]
> ircf.renderIrc(b);
'Hello, \u0002World\u000304,07!\u000f'
> ircf.renderHtml(b);
'Hello, <b>World</b><span class="ircf-fg-4 ircf-bg-7"><b>!</b></span>'

Methods

  • Block[] .parse(string text): Parse text into blocks
  • string .renderIrc(Block[] blocks): Turn blocks back into irc-formatted text.
  • string .renderHtml(Block[] blocks): Convert blocks into html (see below)
  • string .renderHtml(string text): Convert text into html (see below)
  • string .strip(Block[] blocks): Same as compile, but leaving out all formatting carets
  • string .strip(string text): Parse text and turn result into unformatted text
  • Block[] .removeStyle(Block[] blocks): Remove all non-color formatting from blocks
  • Block[] .removeColor(Block[] blocks): Remove all color from blocks
  • Block[] .compress(Block[] blocks): Merges adjacent blocks that have equal color and style, which can happen after the two first functions or when this library is used to render.
  • string .swigFilter(string input, bool inline): Convert irc-formatted text into html. If inline is set, it will concaterate each line instead of wrapping them in <p> tags.
  • string .swigInline(string input): Calls the above function with true as the second argument.

Note: .removeStyle, .compress and .removeColor does not clone the block array. .strip does not alter the blocks, however.

Block Class

  • Block(Block prev, string text): Constructs a block. If prev is not null, the block will inherit style and color from it.
  • .equals(Block other): Returns true if block's style and color equals the other's. It does not check for text equality.
  • .isPlain(): Return true if the block has no style or color.
  • .hasSameColor(Block other, bool reversed): Returns true if the blocks has the same color. If reversed argument is true and the current block has .reverse set, it will only return true if the colors are reversed.
  • .getColorString(): Returns XX or XX,YY formatted string where XX is .color and YY is .highlight. Both numbers are padded to 2 length.

Constants

  • .U: Underline
  • .B: Bold
  • .I: Italic
  • .C: Color
  • .R: Reverse
  • .O: Reset (CTRL + O on mIRC)

HTML Rendering

.U, .B and .I will use <u>, <b> and <i> tags respectively, while the others will use <span>-tags with the following classes.

  • ircf-reverse: Reversing is applied (color and higliht are swapped)
  • ircf-no-color: The above class is set, but neither of the below are.
  • ircf-fg-X: Foreground color (X = block.color)
  • ircf-bg-X: Background color (X = block.highlight)

The output of .renderHtml is a string of tags without a tag wrapping all of it. .swigFilter will use the class ircf-line on its <p> tags.

Using with swig

In the initialization phase of your swig instance, you can add custom filters to swig like this. Make note of the first parameter.

swig.setFilter('ircf', require('irc-formatting').swigFilter);

Then you can use it in your templates like this.

<!-- ... -->
<h1>Log file</h1>
{{logcontent|ircf}}
<!-- ... -->

ISC License

Copyright (c) 2016, Gisle Aune

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE