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-position-chooser

v1.0.0

Published

Allows an easy and simple way to choose multiple positions using a string or an array with the desired rules.

Downloads

1

Readme

Simple Position Chooser

This package allows for an easy and simple way to choose multiple positions using a string or an array with the desired rules.

How to use

The way to choose the desired positions is by using any of the rules seperated by a comma in a string or by having the rules in an array. Then you use the generated function with the start position and end position to generate the derised positions.

Rules

(X and Y represent an non negative integer number)

  1. * : adds all positions. This is a special rule because it cannot be used with any other rule.

  2. X : adds the position X.

  3. X-Y : adds all positions between X and Y (X and Y included).

  4. -X : adds all positions between 0 and X (same as 0-X)

  5. X- : adds all positions between X and the last positions (X included)

  6. /X : adds all positions that are multiple of X

  7. even -> adds all even positions

  8. odd -> adds all odd positions

Notes

  1. Any invalid rule will simply be ignored.
  2. Any position will only be added once, even if there are more than one rule defining it.
  3. 0 is a univerval multiple
  4. The list of desired positions is always ordered.

Example: '1,3,7-9' will adds positions 1,3,7,8 and 9.

How to use

var processPositionsString = require('simple-position-chooser').processPositionsString;

//The rule list can be a string or an array
var processor=processPositionsString('1,5,/4,13-17');
//or
var processor=processPositionsString([1,5,'/4','13-17']);

// Note: The end value is excluded
//processor(start,end)

processor(0,30)
//generates [ 0, 1, 4, 5, 8, 12, 13, 14, 15, 16, 17, 20, 24, 28 ]

processor(15,40)
//generates [ 15, 16, 17, 20, 24, 28, 32, 36 ]

Example

// In this example 

var array

var processPositionsString = require('simple-position-chooser').processPositionsString;

//The rule returns all possitions from 0 to 10 and all multiples of 5
var processor=processPositionsString('-10,/5');

//goes trough all the array positions that are between 0 and 10 or are multiple of 5
processor(0,array.length).forEach(function(pos){
    var element=array[pos]
    // code
})