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 🙏

© 2026 – Pkg Stats / Ryan Hefner

log-tokenizer

v0.0.3

Published

Extract IP addresses and Cisco interface names from the text

Downloads

4

Readme

This module solves the problem of extracing IP addresses and Cisco / Arista interface names from a text. It was initially written to be used for parsing syslog files, but can be used anywhere such need exists.

Installation

npm install log-tokenizer

Usage

Functionality of this module has been split into three functions

Convert string into tokens

tokenizer.tokenize(txt, extractors)

Params

  • txt - (Required) raw string that is to be parsed
  • extractors - (Optional) - array of functions that perform extraction and return list of objects describing extracted fields. If not provided, by default extractIPs and extractInterfaces are used. If you want to write your own method, have a look at one of those functions.

Returns

Returns an array of objects describing consecutive fields. Each object contains at least following attributes:

  • index - start position in input string
  • len - length of extracted field
  • type - set to appropriate type of the extraction. All parts of the string that have not been matched by extractors have this parameter set to 'text'

Example

> tokenizer.tokenize("2015-03-21 Android 1.1.3.3 connected through Fa1/13 to host 5.5.5.5, interface Gi3/1")
[
   {
      "type":"text",
      "txt":"2015-03-21 Android ",
      "len":19,
      "index":0
   },
   {
      "index":19,
      "len":7,
      "txt":"1.1.3.3",
      "type":"ipaddress"
   },
   {
      "type":"text",
      "txt":" connected through ",
      "len":19,
      "index":26
   },
   {
      "index":45,
      "len":6,
      "txt":"Fa1/13",
      "type":"interface"
   },
   {
      "type":"text",
      "txt":" to host ",
      "len":9,
      "index":51
   },
   {
      "index":60,
      "len":7,
      "txt":"5.5.5.5",
      "type":"ipaddress"
   },
   {
      "type":"text",
      "txt":", interface ",
      "len":12,
      "index":67
   },
   {
      "index":79,
      "len":5,
      "txt":"Gi3/1",
      "type":"interface"
   }
]
>

Extract list of Cisco/Arista interface names

tokenizer.extractInterfaces(txt)

Params

  • txt - (Required) - string to be parsed

Returns

Array with list of extracted IP address objects. Each object has following attributes:

  • index - start position in input string
  • len - length of extracted field
  • type - set to 'interface'

Example

> tokenizer.extractInterfaces('2014-03-12 host.com Interface Ethernet1/4 went down')
[ { index: 30,
    len: 11,
    txt: 'Ethernet1/4',
    type: 'interface' } ]
>

Extract IP addresses

tokenizer.extractIPs(txt)

Params

  • txt - (Required) - string to be parsed

Returns

Array with list of extracted IP address objects. Each object has following attributes:

  • index - start position in input string
  • len - length of extracted field
  • type - set to 'ipaddress'

Example

> tokenizer.extractIPs("this is a test text with IP address of 4.4.4.4 and some other irrelevant SNMP OID .1.2.3.4.5.6")
[{"index":39,"len":7,"txt":"4.4.4.4","type":"ipaddress"}]