Skip to content

ViishSensei/coupon_crafter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coupon_crafter - Modernized Code Generator Library

License Discord

A lightweight, customizable, and efficient code generation library written in JavaScript. This modernized version preserves all the original functionality while enhancing readability, maintainability, and compatibility with ES6+ standards.


✨ Features

  • Generate random codes with custom lengths, charsets, and patterns.
  • Supports prefixes, postfixes, and unique sequential code generation.
  • Handles alphanumeric, numeric, and alphabetic charsets.
  • Fully backward-compatible with legacy implementations.
  • Detects infeasible configurations to avoid errors.
  • Modernized with ES6+ features for cleaner and more efficient code.

📦 Installation

npm install coupon_crafter

🚀 Usage

Import the Library

For Node.js

const coupon_crafter = require("coupon_crafter");

For Browsers

Include the script file:

<script src="path/to/coupon_crafter.js"></script>
<script>
  const code = coupon_crafter.generate({ length: 6 });
</script>

Generate a Code

const code = coupon_crafter.generate({
  length: 8,
  prefix: "promo-",
  postfix: "-end",
})[0];

console.log(code); // Example: promo-Ab12Cd34-end

Generate Multiple Unique Codes

const codes = coupon_crafter.generate({
  count: 5,
  length: 6,
  charset: coupon_crafter.charset("alphabetic"),
});

console.log(codes);
// Example: ['AbCdEf', 'GhIjKl', 'MnOpQr', 'StUvWx', 'YzAbCd']

Sequential Code Generation

const config = {
  pattern: "A###Z",
  charset: coupon_crafter.charset("numbers"),
};

console.log(coupon_crafter.generate(config, 0)); // ['A000Z']
console.log(coupon_crafter.generate(config, 1)); // ['A001Z']
console.log(coupon_crafter.generate(config, 10)); // ['A010Z']

🛠️ Modernization Improvements

The library has been upgraded to use:

  • ES6+ Syntax: Arrow functions, template literals, class, and const/let.
  • Improved Efficiency: Leveraging modern features like Set for uniqueness checks.
  • Enhanced Readability: Cleaner and more modular code structure.
  • Backward Compatibility: Fully supports legacy environments and usage patterns.

⚡ Tests

The library includes a comprehensive test suite. Run the tests using:

npm test

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published