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

buffer-nexter

v0.1.0

Published

A basic template for deving an ES6 app

Downloads

4

Readme

Buffer Nexter Build Status

About

Buffer Nexter will allow you to manually iterate a buffer based on an arbitrary separator (defaulting to \n). Alternatively, you can stream the buffer based on the same separator. The next() method behaves very similarly to an ES6 generator.

Use

import BufferNexter from 'buffer-nexter';

let lines = new Buffer('line1\nline2\line3');

let buf = new BufferNexter(lines);

console.log(buf.next()); // -> line1
console.log(buf.next()); // -> line2
console.log(buf.next()); // -> line3
console.log(buf.next()); // -> null

Example

let buf = new BufferNexter(buffer[, options]);

buffer (type: Buffer)

A standard buffer, typically a String, containing some value to use as a separator to iterate with.

options (type: Object, optional)

  • separator - The string value to use for iteration, default \n.
  • index - The buffer index within the buffer to begin iteration, default 0.
  • encoding - The encoding type to use to read the buffer, default utf8.

Code

let buf = new BufferNexter('1,2,3', { separator: ',' });

console.log(buf.next()); // -> 1
console.log(buf.next()); // -> 2
console.log(buf.next()); // -> 3
console.log(buf.next()); // -> null

Instance Methods

next()

Calling next() will return the 'next' value from the provided buffer.

  • Returns: String or Null

skip(n)

This will call next() 'n' times and return this so you can chain next() calls.

  • Returns: this

peek()

This will give you a look at the 'next' value that will be returned on the subsequent next() call.

  • Returns: String or Null without iterating

stream()

This returns a Readable stream for piping or whatever you want to use a stream for. The stream emits data events for each iteration of the buffer.

  • Returns: Stream.Readable

Static Methods

BufferNexter.readFile(file[, options])

If you just want to read a file and iterate next() calls on \n, then this is the easiest way to do that.

  • Returns: Promise -> BufferNexter instance
/* sample.txt
foo
bar
baz
 */

import { readFile } from 'buffer-nexter';

readFile('sample.txt')
  .then((buf) => {
    console.log(buf.next()); // -> foo
    console.log(buf.next()); // -> bar
    console.log(buf.next()); // -> baz
  })
/* sample.csv
foo,bar,baz
 */

import { readFile } from 'buffer-nexter';

readFile('sample.csv', { separator: ',' })
  .then((buf) => {
    console.log(buf.next()); // -> foo
    console.log(buf.next()); // -> bar
    console.log(buf.next()); // -> baz
  })

What about readFileSync()? If there's a demand for it or if someone submits a PR, I'll add it, but I prefer to use Promises wherever possible.

Versions

  • 0.1.0 - 20151222 - Added static readFile()
  • 0.0.1 - 20151221 - Initial release

Credits

  • Mark - Thanks for the encouragement!