| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
View all the directives in action at https://anthonynahas.github.io/combination-generator
Install above dependencies via npm.
Now install ngx-combination-generator via:
npm install --save ngx-combination-generatorNB: Global installation is required for CLI commands to work correctly
npm install -g ngx-combination-generatorNote: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';
@NgModule({
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';
@NgModule({
declarations: [OtherComponent, ...],
imports: [NgxCombinationGeneratorModule, ...],
})
export class OtherModule {
}Inject the NgxCombinationGeneratorService in your component and go! See below
import {Component, OnInit} from '@angular/core';
import {NgxCombinationGeneratorService} from 'ngx-combination-generator';
@Component({
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"]
}
}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
console.log(myCombinations);This will output a JSON string containing all possible combinations like so:
["a","0","R","3","#","f","P","x","aa","a0","aR","a3","a#","af","aP","ax","0a","00","0R","03",
"0#","0f","0P","0x","Ra","R0","RR","R3","R#","Rf","RP","Rx","3a","30","3R","33","3#","3f","3P","3x","#a","#0","#R","#3","##","#f","#P","#x","fa","f0","fR","f3","f#","ff","fP","fx","Pa","P0","PR","P3","P#","Pf","PP","Px","xa","x0","xR","x3","x#","xf","xP","xx"]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
Copyright (c) 2018 anthonynahas. Licensed under the MIT License (MIT)
| Back | FazBrowse Home | New Git URL |