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

streader

v1.0.1

Published

A simple String Reader for a Convenient way to read through strings

Downloads

4,020

Readme

Basic Overview

Streader is a String Reader which simplifies the way we read through strings.

Library can be used both in Node.js and directly in Browser. It is well-documented and completely covered with test specs (excluding webpack bundling definitions and expressions).

If you want to add some features or to suggest any idea, feel free ? contributions are always welcome.

How to Install

Using NPM

To use Streader with NPM simply call:

npm install --save streader

In Browser

To use Streader directly in browser simply download this repository and copy dist/streader.js into your project. Next, include it on your .html page:

<script src="path/to/your/js/streader.js"></script>

Get Started

You are able to use Streader as the importable npm package or directly in browser.

In Node.js

import Streader from "streader";

var reader = new Streader("example");

while( !reader.eof() ) {
 var char = reader.read();
 // Do something with each char
}

In Browser

<script>
var reader = new Streader("example");

while( !reader.eof() ) {
 var char = reader.read();
 // Do something with each char
}
</script>

API

read(count)

Reads the next characters. Count - optional count of characters to read

var reader = new Streader("Example");

var chars = reader.read(7); // chars => "Example"

peek(count, offset)

Reads the next character without advancing the cursor. Count - optional count of characters to read; Offset - optional offset to start read at

var reader = new Streader("Example");

var chars = reader.peek(3, 2); // chars => "amp"

skip(count)

Skips the next characters. Count - optional count of characters to read.

var reader = new Streader("Example");

var skipped = reader.skip(3); // skipped => 3

readPattern(pattern)

Reads characters that match either string or regexp pattern.

var reader = new Streader("Pattern Example");

var chars = reader.readPattern("Pattern"); // chars => "Pattern"
var index = reader.getIndex(); // index => 7

var chars = reader.readPattern(/\s+/); // chars => " "
var index = reader.getIndex(); // index => 8

peekPattern(pattern, offset)

Reads characters that match either string or regexp pattern without advancing the cursor.

var reader = new Streader("Pattern Example");

var chars = reader.peekPattern("Ex", 8); // chars => "Ex"
var index = reader.getIndex(); // index => 0

var chars = reader.peekPattern(/\w+/); // chars => "Pattern"
var index = reader.getIndex(); // index => 0

skipPattern(pattern)

Skips characters that match either string or regexp.

var reader = new Streader("Pattern Example");

var skipped = reader.skipPattern("Pattern"); // skipped => 7

var skipped = reader.skipPattern(/\s|\n/); // skipped => 1

eof()

Checks if we're at the end of the source

var reader = new Streader("example");
reader.read(100); // Read all characters

var isEof = reader.eof(); // isEof => true

reset()

Resets current cursor position

var reader = new Streader("example");
reader.read(5); // Read 5 characters for example

reader.reset();

var index = reader.getIndex(); // index => 0

getSource()

Gets the current reader's source string.

var reader = new Streader("example");

var source = reader.getSource(); // source => "example"

getIndex()

Gets the current index of the cursor.

var reader = new Streader("example");
reader.read(5); // shift cursor for example

var index = reader.getIndex(); // index => 5

setSource(text)

Loads the new text source to StringReader. Method resets current cursor data. Useful for deferred read.

var reader = new Streader("old");
reader.read(2); // shift cursor for example

reader.setSource("new");

var source = reader.getSource(); // source => "new"
var index = reader.getIndex(); // index => 0

Contributing to Streader

Contributions are always welcome. Before contributing please read the code of conduct & search the issue tracker (your issue may have already been discussed or fixed).

To contribute, follow next steps:

  • Fork Streader
  • Commit your changes
  • Open a Pull Request.

Feature Requests

Feature requests should be submitted in the issue tracker, with a description of the expected behavior & use case, where they?ll remain closed until sufficient interest (e.g. ? reactions). Before submitting a feature request, please search for similar ones in the closed issues.

License

Released under the MIT License