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

simple-placeholder-slot-numberizer-pmb

v0.1.2

Published

Assign number-counting string placeholders for values, remembering the ones already seen.

Downloads

4

Readme

simple-placeholder-slot-numberizer-pmb

Assign number-counting string placeholders for values, remembering the ones already seen.

API

This module exports one function:

makeNumberizer(opt)

Return a function numb(x) that will assign distinct numbers for each distinct x and return a string based on that number.

opt is an optional options object that supports these optional keys:

  • pattern: An array of string parts that will be glued together with the counter number. Default: ['$', '']
  • values: An Array used for determining the internal next number, and collecting the encountered x values in order of discovery. Default: a new empty Array.
  • offset: Number added to the values array index in order to obtain the pattern-printed slot number. Default: 1
  • dict: A Map that maps discovered x values to an object with these keys i (index in the values array) and s (the string resulting from applying pattern). Default: new empty Map.

The numb function will carry all the keys that are supported in opt, and modifying them will modify behavior for future encounters.

In addition, the numb function will carry these other properties:

  • tag: A renderer function that will numb() all slot values in a tagged string.

Bonus knowledge

  • For arbitrarily fancy render functions, make pattern an object that has a join method. It will be invoked with one single argument, a number primitive.

  • The default pattern with default offset is useful for…

    • up to 9 JS RegExp capture groups.
    • up to 9 bash function arguments. (bash -c 'f() { echo "a$42z"; }; f b{1..100}y'ab4y2z)
      • If you want more, use pattern: ['${', '}'] (bash -c 'f() { echo "a${42}z"; }; f b{1..100}y'ab42yz)
    • PostgreSQL positional parameters up to more than 32k (haven't tested though).

Usage

See test/usage.mjs.

Known issues

  • Needs more/better tests and docs.

 

License

ISC