# pstrscan

> A simple, fast string tokenizer for lexical scanning operations.

Latest version **0.1.6** (published 2013-07-08) · 0 weekly downloads

## Install

```sh
npm install pstrscan
pnpm add pstrscan
yarn add pstrscan
bun add pstrscan
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2013-07-08 |
| First published | 2012-02-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Maintainers | jhamlet |
| Keywords | regular, expression, tokenizer, text, string, scanner |

## Links

- npm: https://www.npmjs.com/package/pstrscan
- Repository: http://github.com/jhamlet/node-pstrscan
- npm.io page: https://npm.io/package/pstrscan

## Dependencies (1)

- [proteus](https://npm.io/package/proteus.md) 0.1.x

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.1.6 (latest) — 2013-07-08
- 0.1.5 — 2013-01-16
- 0.1.4 — 2013-01-10
- 0.1.3 — 2012-03-20
- 0.1.2 — 2012-03-17
- 0.1.0 — 2012-02-24
- 0.0.1 — 2012-02-21

## README

## PStringScanner

### Overview

**PStringScanner** is a simple string tokenizer that provides for lexical scanning operations on a string.

It's the _third_ port of the [Ruby  library](http://corelib.rubyonrails.org/classes/StringScanner.html) into JavaScript. However, where the other ports concentrated on the interface, this one concentrates on **speed**.

The original Ruby version was written in C, and is very fast. This version, while not in C, is as fast on short strings (under 32 Kb of characters), and almost **twice as fast** on large strings (million+ characters) than the other ports.

### Installation

~~~
npm install -g pstrscan
~~~

### Quick start

Scanning a string means keeping track of and advancing a position (a zero-based index into the source string) and matching regular expressions against the portion of the source string after the position.

~~~js
var PStrScan = require("pstrscan");
var s = new PStrScan("This is a test");
s.scan(/\w+/);             // = "This"
s.scan(/\w+/);             // = null
s.scan(/\s+/);             // = " "
s.scan(/\s+/);             // = null
s.scan(/\w+/);             // = "is"
s.hasTerminated();         // = false
s.scan(/\s+/);             // = " "
s.scan(/(\w+)\s+(\w+)/);   // = "a test"
s.getMatch();              // = "a test"
s.getCapture(1);           // = "a"
s.getCapture(2);           // = "test"
s.hasTerminated();         // = true
~~~

### Documentation

The [interface should be familiar](http://sstephenson.github.com/strscan-js/) to those familiar with the [original library](http://corelib.rubyonrails.org/classes/StringScanner.html), and the one originally ported to [JavaScript/Node](http://sstephenson.github.com/strscan-js/). There are some slight differences, but you should be able to gleam those from the [source file](https://github.com/jhamlet/node-pstrscan/blob/master/lib/pstrscan.js).

### To Do

1.  More documentation specific to this implementation.
2.  Add a more comprehensive `unscan` history/capability.

---
_Source: https://npm.io/package/pstrscan · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
