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

p-c

v1.0.5

Published

permutation, combination and lot more.

Downloads

2

Readme

p-c

permuations, combinations, rankName and lot more: (in development mode) all use cases not completed yet

Installation

npm install p-c

Testing (after installing)

npm test

Start using (after installing) (trying)

you can try as soon as you install the package with your own input. :smile:

npm start
npm start <method> <input-string>
npm start rank rohan
npm start count rohan
npm start all rohan
npm start list rohan

Usage

var pc = require('p-c');

pc('cab').list(); /* [ 'aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'baa', 'bab', 'bac', 'bba',
  'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc' ] */
pc(10).list(); // [ '00', '01', '10', '11' ]
pc(['a','b']).list(); /* [ 'aa', 'ab', 'ba', 'bb' ] */
pc(['c','b']).list(); /* [ 'bb', 'bc', 'cb', 'cc' ] */
pc('cacb').list(); /* [ 'aaaa', 'aaab', 'aaac', 'aaba', 'aabb', 'aabc', 'aaca', 'aacb', 'aacc', 'abaa', 'abab', 'abac',
 ... ,
 'cbbc', 'cbca', 'cbcb', 'cbcc', 'ccaa', 'ccab', 'ccac', 'ccba', 'ccbb', 'ccbc', 'ccca', 'cccb', 'cccc' ]
 81 permutations */

pc('cab').rank(); // 19
pc('cacb').rank(); // 61

pc('cab').count(); // 27 (= 3^3)
pc('cacb').count(); // 81 (= 3^4)

var result = pc.permute('cab'); // returns an object
result.count();
result.rank();

var result = pc('cab'); // returns an object
result.count();
result.rank();

//examples with length
pc('01', 3).list() // [ '000', '001', '010', '011', '100', '101', '110', '111' ]
pc('cbad', 2).list() // [ 'aa', 'ab', 'ac', 'ad', 'ba', 'bb', 'bc', 'bd', 'ca', 'cb', 'cc', 'cd', 'da', 'db', 'dc', 'dd' ]

Notes

all 3: pc(args), pc.permute(args) & pc.name(args) are equivalent

  • args: param1

  • args: param1, len(number)

  • args: param1, opts(object)

  • param1: string // string or convertible to string

  • param1: array // array of chars // joined using no seperator

Advanced

//examples with opts
pc('cbad', {length:2, sortChars:false}); // [ 'cc', 'cb', 'ca', 'cd', 'bc', 'bb', 'ba', 'bd', 'ac', 'ab', 'aa', 'ad', 'dc', 'db', 'da', 'dd' ]
pc('cbad', {length:2, repeatChars:false}); // [ 'ab', 'ac', 'ad', 'ba', 'bc', 'bd', 'ca', 'cb', 'cd', 'da', 'db', 'dc' ]
pc('cbad', {length:2, sortChars:false, repeatChars:false}); // [ 'cb', 'ca', 'cd', 'bc', 'ba', 'bd', 'ac', 'ab', 'ad', 'dc', 'db', 'da' ]

Defaults

  • repeatChars: true
  • sortChars: true
  • length: length of input string

Examples explained in AMAP detail

AMAP: as much as possible :wink:

  1. var string = 'cab'; pc(string).list();
    • will produce same result if string = 'cba' or 'abc' or 'acb' ..
    • Objective: get an array of all the permutations made by characters (sorted) of input string
    • process:
      • save length of string
      • find distinct characters, sort these
      • repeat is ON
      • push permutations of saved length in array, return it
  • var string = 'cab'; pc(string).rank();
    • will NOT produce same result if string = 'cba' or 'abc' or 'acb' ..
    • Objective: find position of input string in such list()
    • notes:
      • other than string's length is not recommended
      • sortChars=false is highly discouraged, while rank(), BECAUSE you will get 1 always.