Skip to content

Commit 37997d8

Browse files
committed
first commit
0 parents  commit 37997d8

5 files changed

Lines changed: 212 additions & 0 deletions

File tree

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Menula De Silva
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the “Software”), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# 🎉 Fake Error Generator
2+
3+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
4+
5+
**`fake-error-generator`** is a lightweight, fun npm package that lets you generate **fake console errors, warnings, logs, and info messages** — perfect for **pranking your friends, demos, or just for laughs**! 😎
6+
7+
> ⚠️ Note: This package is purely for **fun and educational purposes**. Don’t use it in production for real error handling.
8+
9+
---
10+
11+
## 🚀 Features
12+
13+
* Generate **fake errors, warnings, logs, or info messages**
14+
* Customizable messages, types, count, and delay
15+
* Randomized messages for maximum fun
16+
* Works in **Node.js** (and can be bundled for the browser)
17+
* Lightweight and zero dependencies
18+
19+
---
20+
21+
## 💿 Installation
22+
23+
```bash
24+
npm install fake-error-generator
25+
```
26+
27+
---
28+
29+
## 🧩 Usage
30+
31+
### 1. Generate a single fake error
32+
33+
```js
34+
const { fakeError } = require("fake-error-generator");
35+
36+
fakeError({ message: "Something went wrong!", type: "error" });
37+
```
38+
39+
### 2. Generate multiple warnings with a delay
40+
41+
```js
42+
fakeError({ message: "Watch out!", type: "warn", count: 3, delay: 500 });
43+
```
44+
45+
### 3. Generate random fake errors
46+
47+
```js
48+
const { randomFakeError } = require("fake-error-generator");
49+
50+
randomFakeError({
51+
messages: ["Oops!", "Crash!", "404 Not Found!"],
52+
count: 5,
53+
delay: 300
54+
});
55+
```
56+
57+
---
58+
59+
## 🎨 Message Types
60+
61+
| Type | Console Output |
62+
| ------- | -------------- |
63+
| `log` | ✅ Normal log |
64+
| `warn` | ⚠️ Warning |
65+
| `error` | ❌ Error |
66+
| `info` | ℹ️ Info |
67+
68+
---
69+
70+
## 😎 Example
71+
72+
```js
73+
const { fakeError, randomFakeError } = require("fake-error-generator");
74+
75+
fakeError({ message: "Server failed to respond!", type: "error" });
76+
fakeError({ message: "Check your input!", type: "warn", count: 3, delay: 1000 });
77+
randomFakeError({ messages: ["Crash!", "Oops!", "Fail!"], count: 5, delay: 500 });
78+
```
79+
80+
Output in console:
81+
82+
```
83+
❌ Server failed to respond!
84+
⚠️ Check your input!
85+
⚠️ Check your input!
86+
⚠️ Check your input!
87+
⚠️ Crash!
88+
❌ Oops!
89+
ℹ️ Fail!
90+
...
91+
```
92+
93+
---
94+
95+
## 💡 Tips for Fun
96+
97+
* Use in **demo projects** to fake errors for UI testing
98+
* **Prank friends** with funny “critical errors”
99+
* Combine with `setInterval` for continuous chaos 😏
100+
101+
---
102+
103+
## 📄 License
104+
105+
MIT License © 2025 Menula De Silva
106+
107+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
108+
109+
---

index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// fake-error-generator/index.js
2+
3+
const types = ["log", "warn", "error", "info"];
4+
5+
function fakeError({
6+
message = "Something went wrong!",
7+
type = "error",
8+
count = 1,
9+
delay = 0
10+
} = {}) {
11+
if (!types.includes(type)) type = "error";
12+
13+
for (let i = 0; i < count; i++) {
14+
setTimeout(() => {
15+
if (type === "log") console.log(`✅ ${message}`);
16+
if (type === "warn") console.warn(`⚠️ ${message}`);
17+
if (type === "error") console.error(`❌ ${message}`);
18+
if (type === "info") console.info(`ℹ️ ${message}`);
19+
}, delay * i);
20+
}
21+
}
22+
23+
// Generate random fake errors
24+
function randomFakeError({
25+
messages = ["Oops!", "Unexpected error!", "Failed to load data!"],
26+
count = 1,
27+
delay = 0
28+
} = {}) {
29+
for (let i = 0; i < count; i++) {
30+
const msg = messages[Math.floor(Math.random() * messages.length)];
31+
const type = types[Math.floor(Math.random() * types.length)];
32+
fakeError({ message: msg, type, count: 1, delay: delay * i });
33+
}
34+
}
35+
36+
module.exports = {
37+
fakeError,
38+
randomFakeError
39+
};

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "fake-error-generator",
3+
"version": "1.0.0",
4+
"description": "Generate fake console errors, warnings, logs, and info messages for pranking or fun demos.",
5+
"main": "index.js",
6+
"keywords": [
7+
"fake",
8+
"error",
9+
"console",
10+
"prank",
11+
"fun",
12+
"demo",
13+
"node",
14+
"developer",
15+
"logs"
16+
],
17+
"author": "Menula De Silva",
18+
"license": "MIT",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/DMS-Menula/fake-error-generator.git"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/DMS-Menula/fake-error-generator/issues"
25+
},
26+
"homepage": "https://github.com/DMS-Menula/fake-error-generator#readme",
27+
"scripts": {
28+
"test": "node test.js"
29+
},
30+
"engines": {
31+
"node": ">=14"
32+
}
33+
}

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { fakeError, randomFakeError } = require("./index");
2+
3+
// Single custom error
4+
fakeError({ message: "This is a test error!", type: "error" });
5+
6+
// Multiple warnings with delay
7+
fakeError({ message: "Watch out!", type: "warn", count: 3, delay: 500 });
8+
9+
// Random fake errors
10+
randomFakeError({ messages: ["Fail!", "Crash!", "404 Not Found!"], count: 5, delay: 300 });

0 commit comments

Comments
 (0)