2.0.0 • Published 6 years ago

ngx-combination-generator v2.0.0

Weekly downloads
Last release
6 years ago

combination-generator - Angular Library built on the top of the combination generator package of @udjamaflip in order to generate all possible (unique) permutations of a provided list of characters.

This library allows you to provide a list of characters and a min/max length of output string to generate a list of all possible combinations (or non-unique permutations of those characters). This is useful for getting a list of characters for brute-forcing or to test password combinations (e.g: for ngx-material-password-strength)

NB: This project is originally forked from udjamaflip/combination-generator.

npm version, npm Coverage Status dependency Status devDependency Status Greenkeeper Badge


View all the directives in action at https://anthonynahas.github.io/combination-generator

Dependencies - Angular V6 is now supported

  • Angular (requires Angular 2 or higher, tested with 2.0.0)


Install above dependencies via npm.

Now install ngx-combination-generator via:

npm install --save ngx-combination-generator

NB: Global installation is required for CLI commands to work correctly

npm install -g ngx-combination-generator


Note:If you are using SystemJS, you should adjust your configuration to point to the UMD bundle. In your systemjs config file, map needs to tell the System loader where to look for ngx-combination-generator:

map: {
  'ngx-combination-generator': 'node_modules/ngx-combination-generator/bundles/ngx-combination-generator.umd.js',

Once installed you need to import the main module:

import { NgxCombinationGeneratorModule } from 'ngx-combination-generator';

The only remaining part is to list the imported module in your application module. The exact method will be slightly different for the root (top-level) module for which you should end up with the code similar to (notice NgxCombinationGeneratorModule .forRoot()):

import { NgxCombinationGeneratorModule } from 'ngx-combination-generator';

  declarations: [AppComponent, ...],
  imports: [NgxCombinationGeneratorModule.forRoot(), ...],  
  bootstrap: [AppComponent]
export class AppModule {

Other modules in your application can simply import NgxCombinationGeneratorModule:

import { NgxCombinationGeneratorModule } from 'ngx-combination-generator';

  declarations: [OtherComponent, ...],
  imports: [NgxCombinationGeneratorModule, ...], 
export class OtherModule {


with Angular

Inject the NgxCombinationGeneratorService in your component and go! See below

import {Component, OnInit} from '@angular/core';
             import {NgxCombinationGeneratorService} from 'ngx-combination-generator';

               selector: 'app-your-component',
               templateUrl: './your.component.html',
               styleUrls: ['./your.component.scss']
             export class YourComponent implements OnInit {

               min = 1;
               max = 2;
               selectedChars: string;
               charsList: string[] = ['a', 'b', 'c', '1', '2', '3'];
               combinationsList: string[] = [];

               constructor(public generator: NgxCombinationGeneratorService) {
               generate() {
                 this.combinationsList = this.generator.loadCombinationList(this.charsList, this.min, this.max);
                 console.log("this.combinationsList = ", this.combinationsList);
                 // output = ["a", "b", "c", "1", "2", "3", "aa", "ab", "ac", "a1", "a2", "a3", "ba", "bb", "bc", "b1", "b2", "b3", "ca",
                 // " cb", "cc", "c1", "c2", "c3", "1a", "1b", "1c", "11", "12", "13", "2a", "2b", "2c", "21", "22", "23", "3a", "3b", "3c",
                 // " 31", "32", "33"]


Expected input

The input is expected to be an array of characters expected to be used i.e.

var myCharacterList = ['a','0','R','3','#','f','P','x'];


Using that array we can pass it through as the first parameter, and then specify the minimum and maximum length of the combinations to be generated

var generator = require('node_modules/generator.js'),
	myCombinations = generator(myCharacterList, 1, 2); //1 is the shorted a combo will be, 2 is the longest


This will output a JSON string containing all possible combinations like so:


Using as CLI (Runtime)

You can use the command in 2 a few different ways using an input file, or an inline comma-separated list i.e. generate-combos a,0,R,3,#,f,P,x 1 2

You can pipe the output in to a file like so: generate-combos a,0,R,3,#,f,P,x 1 2 >> my-list-of-character-combinations.json

You can also specify an input file, the file must contain the same expected input i.e. my-input-list.json a,0,R,3,#,f,P,x 1 2

Then run the command: generate-combos my-input-list.json 1 2

or use the same command and pipe in to a JSON file for further usage: generate-combos my-input-list.json 1 2 >> my-list-of-character-combinations.json

Other Angular Libraries


Copyright (c) 2018 anthonynahas. Licensed under the MIT License (MIT)