permugenjs
v1.1.0
Published
permugenjs is an NPM package that generates all possible permutations (not just combinations) of a given string.
Readme
permugenjs
permugenjs is an NPM package that generates all possible permutations (not just combinations) of a given string.
📌 What Does “All Possible Combinations” Mean?
Given an input string, this tool returns all the possible unique permutations of its characters.
Example: If the input string is: ABCD Then the total number of permutations is 4! = 24.
Sample output:
[
"1342",
"1432",
"2341",
"2431",
"1243",
"1423",
"3241",
"3421",
"2143",
"2413",
"3142",
"3412",
"4231",
"4321",
"1234",
"1324",
"4132",
"4312",
"2134",
"2314",
"4123",
"4213",
"3124",
"3214"
]✅ Validation Rules The input string must satisfy the following conditions: 1.Input must be a valid string 2.Only letters and numbers are allowed (a-z, A-Z, 0-9) 3.Special characters like &^%@#$!~,/|{}](*)+-` are not allowed 4.The input string must contain at least 2 and at most 10 characters
📦 Installation
npm install permugenjs
🧑💻 TypeScript Support
This package is fully compatible with TypeScript.
📘 Usage
React ->
import { getCombinationsGenerator } from "permugenjs";
export default function MainComponent() {
return (
<div>
<label>Enter a number </label>
<input name="val" id="val" />
<button
onClick={(e) => {
let inputParam = document.getElementById("val").value;
const promiseData = getCombinationsGenerator(inputParam);
promiseData
.then(function (res) {
console.log("res====>", res);
})
.catch((err) => {
console.log(err);
});
}}
>
Enter
</button>
</div>
);
}
Node JS with .js file (with CommonJS)
const express = require('express');
const pkg = require('permugenjs');
const app = express ();
const {getCombinationsGenerator} = pkg;
app.use(express.json());
const PORT = process.env.PORT || 6000;
app.listen(PORT, () => {
console.log("Server Listening on PORT:", PORT);
});
app.get("/status", async (request, response) => {
const req = request.query.input;
const combinations=getCombinationsGenerator(String(req));
combinations.then((res)=>{
const status = {
combinations: res,
Status: "Running"
};
response.send(status);
})
});
Node JS with .mjs file (with ESM)
import express from 'express';
import {getCombinationsGenerator} from 'permugenjs';
const app = express ();
app.use(express.json());
const PORT = process.env.PORT || 6000;
app.listen(PORT, () => {
console.log("Server Listening on PORT:", PORT);
});
app.get("/status", async (request, response) => {
const req = request.query.input;
const combinations=getCombinationsGenerator(String(req));
combinations.then((res)=>{
const status = {
combinations: res,
Status: "Running"
};
response.send(status);
})
});
Output -->
{
"combinations": [
"airb",
"arib",
"bira",
"bria",
"abri",
"arbi",
"ibra",
"irba",
"bari",
"brai",
"iarb",
"irab",
"rbia",
"riba",
"abir",
"aibr",
"raib",
"riab",
"bair",
"biar",
"rabi",
"rbai",
"iabr",
"ibar"
],
"Status": "Running"
}
✅ The function has built-in type definitions: generateCombinations(input: string): string[]
🚀 Performance Notes The function uses a recursive algorithm to generate all permutations. The time complexity is O(n!), where n is the number of characters in the string. For performance reasons, it's recommended to limit input length to 10 characters or fewer. Generating permutations for strings longer than 10 characters may cause performance issues or memory exhaustion.
Input Length Estimated Permutations
| Time | Memory | Usage | |------:|------------:|:------------ | | 4 | 24 | Fast(🟢) | | 6 | 720 | Moderate(🟡) | | 8 | 40,320 | High(🔴) | | 10 | 3,628,800 | Very High(🚨)|
Creator's Note
Dear user,
Thank you for visiting and using the permugenjs npm package.
Currently, the repository is private due to certain reasons.
If you encounter any issues, please feel free to email me at [email protected] with the subject line:
Current Date|Permugenjs Issue – Your Name
I’ll do my best to address and resolve the issue as soon as possible.
Best regards,
Abirlal Mukherjee
Contribution is Close
