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

each-part-capture

v0.5.2

Published

Transform uses array of regex's to run exec() on each part and pass on capture results to next stream.

Downloads

5

Readme

each-part-capture

Build Status Dependency Status npm version

Transform uses array of regex's to run exec() on each part and pass on capture results to next stream.

Install

npm install each-part-capture --save

Usage: Simplified

# get builder function
buildCapturer = require 'each-part-capture'

# build capturer transform with array of regular expressions
capturer = buildCapturer [ /(\w+)=(\d+)/ ]

# write a string which will match the regular expression
capturer.write 'num=12345'

# capturer will push an object, `result` to the next stream with
# the `capture` property containing the regex.exec(string) result:
result =
  capture:
  # capture[1] = 'num'
  # capture[2] = 12345

# write a string which does *NOT* match any of the regex's
capturer.write 'wont match any pattern'
# *nothing* is pushed to the next stream. non-matching strings are *ignored*
# by default. override this via the `ignore` option at creation time:
nonIgnoringCapturer = buildCapturer [/some regex/], ignore:false
# this capturer will provide unmatchable strings in a `unknown` property on `result`
result =
  unknown: 'wont match any pattern'

Usage: Stream Pipeline

# get the each-part module to breakup the parts
buildEacher = require 'each-part'
# make an eacher transform
eacher = buildEacher()

# get this module
buildCapturer = require 'each-part-capture'

# get module to enhance regex's exec() to use names for the capture groups
buildNameCapture = require 'regex-named-groups'

# build a capturer transform with an array of regular expressions which are
# enhanced to use capture group names
capturer = buildCapturer [
  # three words separated by spaces
  buildNameCapture /^(\w+)\s+(\w+)\s+(\w+)$/, ['first', 'second', 'third']
  # three numbers separated by spaces
  buildNameCapture /^([+-]?\d+(?:\.\d*)*)\s+([+-]?\d+(?:\.\d*)*)\s+([+-]?\d+(?:\.\d*)*)$/,
    ['d1', 'd2', 'd3']
]

# test strings to write thru transforms:
words = 'one two three'
nums = '-1.23 +81742.2153 7028261.3'
nomatch = 'some non-matching text which gets ignored'
testString = words + '\n' + nomatch + '\n' + nums

# create a target stream, as a sample, to receive the capture results
target = thru.obj (result, _, next) ->
  # first result is the words capture:
  result.capture.first  = 'one'
  result.capture.second = 'two'
  result.capture.third  = 'three'

  # NOTE: the 'nomatch' string is ignored because it didn't match any regex

  # second result (next time this function is called) is the nums.
  result.capture.d1 = -1.23
  result.capture.d2 = 81742.2153
  result.capture.d3 = 7028261.3

# pipe them together
eacher.pipe(capturer).pipe(target)

# write our test string to the pipeline
eacher.end testString

MIT License