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

deliminator

v3.2.0

Published

Delimit your data...

Downloads

11

Readme

NPM version Downloads License Build Status Dependencies Status Maintainability Codecov Package Quality

Deliminator

Node module for delimiting and parsing delimited fields...

    ___       ___       ___     ___       ___       ___       ___       ___      ___       ___       ___   
   /\  \     /\  \     /\__\   /\  \     /\__\     /\  \     /\__\     /\  \    /\  \     /\  \     /\  \  
  /::\  \   /::\  \   /:/  /  _\:\  \   /::L_L_   _\:\  \   /:| _|_   /::\  \   \:\  \   /::\  \   /::\  \ 
 /:/\:\__\ /::\:\__\ /:/__/  /\/::\__\ /:/L:\__\ /\/::\__\ /::|/\__\ /::\:\__\  /::\__\ /:/\:\__\ /::\:\__\
 \:\/:/  / \:\:\/  / \:\     \::/\/__/ \/_/:/  / \::/\/__/ \/|::/  / \/\::/  / /:/\/__/ \:\/:/  / \;:::/  /
  \::/  /   \:\/  /   \:\__\  \:\__\     /:/  /   \:\__\     |:/  /    /:/  /  \/__/     \::/  /   |:\/__/ 
   \/__/     \/__/     \/__/   \/__/     \/__/     \/__/     \/__/     \/__/              \/__/     \|__|  

Features 🔥

  • Zero dependencies
  • Asynchronous and Synchronous options
  • Builds for Node.js 6,8,9,10,11 and beyond

Installation 🔧

npm install deliminator

Usage 📦

Functionality Examples

const deliminator = require('deliminator');

const d = deliminator.create(';;;');  // Create a delimiter

let received = '';

received += d.delimit('Hello, ');     // 'Hello, ;;;'
received += d.delimit('World!');      // 'Hello, ;;;World!;;;'

d.dice(received);                     // ['Hello, ', 'World!', '']

received += 'incomplete data';        // Un-delimited data

d.dice(received);                     // ['Hello, ', 'World!', 'incomplete data']

let leftOver = '';

d.diceAndTrim(received, leftOver);    /* 
                                      {
                                          complete: ['Hello, ', 'World!'], 
                                          pending: 'incomplete data'
                                      } 
                                      */

Socket Callbacks 🔌

const topology = require('fully-connected-topology');
const deliminator = require('deliminator');

const t = topology(/* ... */);
const delim = deliminator.create(';');

/* ... */

let waitingOn = '';

t.on('connection', socket => {
  socket.on('data', data => {
    const dataStr = data.toString();

    // Separate completed data from pending data
    const { complete, pending } = delim.diceAndTrim(dataStr, waitingOn);
    
    // Save pending data to be concatenated with future incoming data
    waitingOn = pending;

    // Process completed data
    complete.map(handleMsg);
  });
});

The example above shows how Deliminator can simplify handling communication between peers using packages like fully-connected-topology. You could also do this in an asynchronous manner using createAsync like in the example below.

const topology = require('fully-connected-topology');
const deliminator = require('deliminator');

const t = topology(/* ... */);
const delim = deliminator.createAsync(';');

/* ... */

let waitingOn = '';

t.on('connection', socket => {
  socket.on('data', async data => {
    const dataStr = data.toString();

    // Separate completed data from pending data
    const { complete, pending } = await delim.diceAndTrim(dataStr, waitingOn);
      
    // Save pending data to be concatenated with future incoming data
    waitingOn = pending;

    // Process completed data
    complete.map(handleMsg);
  });
});

API 🎛

const d = deliminator.create(str);

Creates and returns a new delimiter object. The string used as a delimiter is specified by the parameter str.

const d = deliminator.createAsync(str);

Creates and returns a new asynchronous delimiter object. Both dice() and diceAndTrim() will return non-blocking promises for their results. The string used as a delimiter is specified by the parameter str.

d.delimit(str);

Returns delimited result of given string str.

d.dice(str);

Parses given string str based on the defined delimit string of the delimiter d and returns the results in the form of an array. The last element of the returned array contains any pending data that is still incomplete. If the last element is an empty string then all preceding elements are complete packets.

In the case that you created an asynchronous delimiter object, the results described above will come wrapped in a promise.

d.diceAndTrim(str, waitingOn);

Parses in the same way that .dice() does but returns an object instead of an array. This object contains two properties: complete and pending. The complete property contains an array of all completed (delimited) data from the given strings waitingOn and str when concatenated, respectively. The pending property contains a string of any incomplete (un-delimited) data.

In the case that you created an asynchronous delimiter object, the results described above will come wrapped in a promise.

Author ☕️

@ekschro

License 🔑

Copyright © 2020, Ericsson Schroeter. Released under the MIT License.