Counter
A simple and lightweight Node.js module for maintaining and incrementing a counter. Ideal for scenarios where you need a straightforward way to track counts without the overhead of more complex state management solutions.
Table of Contents
- Installation
- Usage
- Basic Example
- API
- Contributing
- License
Installation
You can install the counter package via npm:
Copy code
npm install counter
Or using yarn:
Copy code
yarn add counter
- Usage
Import the counter module into your project and start using the counter function to increment and retrieve the count.
Basic Example
javascript
Copy code
// Import the counter module
const counter = require("counter");
// Initialize the counter (optional, as it starts at -1 by default) let currentCount = counter();
console.log(currentCount); // Outputs: 0
currentCount = counter(); console.log(currentCount); // Outputs: 1
currentCount = counter(); console.log(currentCount); // Outputs: 2
// You can use it in different parts of your
application function logCount() {
console.log(`Current Count: ${counter()}`);
}
logCount(); // Outputs: Current Count: 3
logCount(); // Outputs: Current Count: 4
// API
counter()
Increments the internal count by 1 and returns the updated value.
- Returns: number - The current count after incrementing.
Example:
javascript
Copy code
const count = counter();
console.log(count); // Outputs: next count value
Contributing
Contributions are welcome! If you'd like to contribute to the counter package, please follow these steps:
- Fork the repository.
- Create a new branch: git checkout -b feature/YourFeature.
- Make your changes and commit them: git commit -m 'Add some feature'.
- Push to the branch: git push origin feature/YourFeature.
- Open a pull request.
Please ensure your code follows the existing code style and includes relevant tests.
License
This project is licensed under the MIT License. Happy Counting!