fakelab 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ document.addEventListener("DOMContentLoaded", async () => {
2
+ var o = document.querySelector(".error"),
3
+ e = document.querySelector(".preview-loading"),
4
+ r = document.querySelector(".code"),
5
+ t = document.querySelector(".preview_toolbar"),
6
+ l = document.querySelector(".loader");
7
+ try {
8
+ hljs.highlightAll(), r && r.classList.remove("loading"), e && e.classList.remove("loading"), t && t.classList.remove("loading");
9
+ } catch (e) {
10
+ console.info(e), o && o.classList.add("visible"), l && l.classList.remove("visible");
11
+ }
12
+ });
@@ -0,0 +1 @@
1
+ <pre class="code loading"><code class="language-<%= lang %>"><%- code %></code></pre>
@@ -0,0 +1,23 @@
1
+ <aside class="sidebar">
2
+ <a class="logo" href="/">Fakelab</a>
3
+ <div class="sidebar_content">
4
+ <div class="sidebar_content_leading">
5
+ <div class="sidebar_content_indicator_icon"></div>
6
+ <span class="sidebar_content_title">Found interfaces</span>
7
+ </div>
8
+ <div class="sidebar_content_list">
9
+ <% entities.forEach((_,name) => { %>
10
+ <a class="sidebar_content_list_item <%= currentPath === `/${name}` ? 'active' : '' %>" href="/<%= name %>">
11
+ <span><%= name %></span>
12
+ </a>
13
+ <% }) %>
14
+ </div>
15
+ </div>
16
+ <a class="sidebar_docs" href="https://fakerjs.dev/" target="_blank" rel="noopener noreferrer">
17
+ <span>Fakerjs documents</span>
18
+ <img class="icon" src="/icons/link.svg" width="18px" height="18px" />
19
+ </a>
20
+ <div class="sidebar_footer">
21
+ <span>app version: <%= version %></span>
22
+ </div>
23
+ </aside>
@@ -0,0 +1 @@
1
+ <h1>ERROR <%= name %> data not found!</h1>
@@ -0,0 +1,9 @@
1
+ <%- include("components/sidebar", {currentPath, entities, version }) %> <% title = "Fakelab" %>
2
+ <main class="main">
3
+ <header class="header"></header>
4
+ <div class="preview">
5
+ <div class="nodata">
6
+ <span>Select a interface to load data.</span>
7
+ </div>
8
+ </div>
9
+ </main>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <link rel="preload" href="/fonts/Inter-Regular.ttf" as="font" crossorigin="anonymous" />
7
+ <link href="/css/style.css" rel="stylesheet" type="text/css" />
8
+ <link href="/css/vs2015.min.css" rel="stylesheet" type="text/css" />
9
+ <title><%= title %></title>
10
+ </head>
11
+ <body>
12
+ <div class="root"><%- body %></div>
13
+ <script src="/js/highlight.min.js"></script>
14
+ <script src="/js/reset.min.js"></script>
15
+ </body>
16
+ </html>
@@ -0,0 +1,201 @@
1
+ <%- include("components/sidebar", {currentPath, entities, version }) %> <% title = name %>
2
+ <main class="main">
3
+ <header class="header">
4
+ <span class="interface_name"><%= name %></span>
5
+ </header>
6
+ <div class="preview">
7
+ <div class="preview-loading loading">
8
+ <span class="loader visible"></span><span class="error">Some libraries could not be loaded. check your internet connection and try again.</span>
9
+ </div>
10
+ <div class="preview_toolbar loading">
11
+ <div class="toolbar_setting">
12
+ <div class="data_fetch_address">
13
+ <div class="address">
14
+ <span class="address_method">GET</span>
15
+ <span class="address_url"><%= address %><%= prefix %>/<%= name %><%= search %></span>
16
+ </div>
17
+ <img id="copy_btn" onclick="copy()" class="icon pointer_auto" src="/icons/copy.svg" width="16px" height="16px" />
18
+ </div>
19
+ <div id="overlay_trigger" class="toolbar_setting_option" onclick="open_settings()">
20
+ <img class="icon" src="/icons/settings.svg" width="18px" height="18px" />
21
+ </div>
22
+ <div id="setting_overlay" data-visible="false" class="toolbar_setting_overlay">
23
+ <span class="setting_title">Generator settings</span>
24
+ <form class="setting_form" onsubmit="submitForm(event)">
25
+ <div class="form_input">
26
+ <label for="count">Count</label>
27
+ <input id="count" autocomplete="off" name="count" type="text" />
28
+ <span>Set count field to generate array of data items.</span>
29
+ </div>
30
+ <div style="display: flex; flex-direction: column; gap: 8px">
31
+ <div class="form_input inline">
32
+ <label for="unique_id">Generate unique id</label>
33
+ <div class="switch" onclick="onChangeGenerateUniqueId()">
34
+ <input type="checkbox" id="unique_id" name="unique_id" />
35
+ <span class="slider"></span>
36
+ </div>
37
+ </div>
38
+ <div id="unique_id_key_field" class="form_input" data-visible="false">
39
+ <input id="unique_id_key" autocomplete="off" name="unique_id_key" type="text" value="_id" placeholder="unique id key" />
40
+ </div>
41
+ <div id="unique_strategy_container" class="unique_strategy" data-visible="false">
42
+ <span class="unique_id_hint">By default unique id is auto incremented integer.</span>
43
+ <div class="form_input inline">
44
+ <label for="unique_id_strategy">Generate as uuid</label>
45
+ <div class="switch" onclick="onHandleUniqueIdStrategy()">
46
+ <input type="checkbox" id="unique_id_strategy" name="unique_id_strategy" />
47
+ <span class="slider"></span>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ <div class="form_buttons">
53
+ <button class="form_reset_btn" type="button" onclick="resetForm(event)">Reset</button>
54
+ <button class="form_apply_btn" type="submit">Apply</button>
55
+ </div>
56
+ </form>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="toolbar_actions">
61
+ <div class="toolbar_action_item">
62
+ <img class="icon" src="/icons/copy.svg" width="18px" height="18px" />
63
+ </div>
64
+ <div class="divider"></div>
65
+ <div class="toolbar_action_item">
66
+ <img class="icon" src="/icons/download.svg" width="18px" height="18px" />
67
+ </div>
68
+ </div>
69
+ </div>
70
+ <%- include("components/code", { lang: "json", code: json }) %>
71
+ </div>
72
+ </main>
73
+ <script src="/js/fakelab.min.js"></script>
74
+ <!-- <script>
75
+ const address_url = document.querySelector(".address_url");
76
+
77
+ async function copy() {
78
+ try {
79
+ await navigator.clipboard.writeText(address_url.textContent);
80
+ } catch (err) {
81
+ console.info(err);
82
+ }
83
+ }
84
+
85
+ function open_settings() {
86
+ const element = document.getElementById("setting_overlay");
87
+ element.setAttribute("data-visible", "true");
88
+ }
89
+
90
+ function handleCloseSetting(event) {
91
+ const element = document.getElementById("setting_overlay");
92
+
93
+ if (!event.target) return;
94
+ if (!element.contains(event.target) && event.target.id !== "overlay_trigger") {
95
+ element.setAttribute("data-visible", "false");
96
+ }
97
+ }
98
+
99
+ window.addEventListener("click", handleCloseSetting);
100
+
101
+ window.addEventListener("DOMContentLoaded", () => {
102
+ const countEl = document.getElementById("count");
103
+ const uniqueIdEl = document.getElementById("unique_id");
104
+ const strategyEl = document.getElementById("unique_id_strategy");
105
+ const uniqueIdKeyEl = document.getElementById("unique_id_key");
106
+ const keyEl = document.getElementById("unique_id_key_field");
107
+ const strategyContainerEl = document.getElementById("unique_strategy_container");
108
+ const params = new URLSearchParams(window.location.search);
109
+ const countValue = params.get("count");
110
+ const uniqueIdValue = params.get("uid");
111
+ if (countValue) countEl.value = countValue;
112
+ if (uniqueIdValue) {
113
+ uniqueIdEl.checked = true;
114
+ uniqueIdKeyEl.value = uniqueIdValue;
115
+ keyEl.setAttribute("data-visible", "true");
116
+ strategyContainerEl.setAttribute("data-visible", "true");
117
+ if (params.has("s")) {
118
+ strategyEl.checked = true;
119
+ }
120
+ }
121
+ });
122
+
123
+ function submitForm(event) {
124
+ event.preventDefault();
125
+ const resetReasons = new Set();
126
+ const formData = new FormData(event.target);
127
+ const countValue = formData.get("count")?.trim();
128
+ const uniqueIdValue = formData.get("unique_id_key")?.trim();
129
+ const params = new URLSearchParams();
130
+
131
+ const switcher = document.getElementById("unique_id");
132
+ const strategySwitcher = document.getElementById("unique_id_strategy");
133
+
134
+ if (countValue && Number(countValue) > 0) {
135
+ const valueAsNumber = Number(countValue);
136
+
137
+ params.set("count", countValue.toString());
138
+ window.location.search = params.toString();
139
+ } else {
140
+ params.delete("count");
141
+ resetReasons.add("count");
142
+ }
143
+
144
+ if (!switcher.checked) {
145
+ params.delete("uid");
146
+ resetReasons.add("uid");
147
+ }
148
+
149
+ if (uniqueIdValue && switcher.checked) {
150
+ params.set("uid", uniqueIdValue);
151
+
152
+ if (strategySwitcher.checked) {
153
+ params.set("s", "uuid");
154
+ }
155
+
156
+ window.location.search = params.toString();
157
+ } else {
158
+ params.delete("uid");
159
+ params.delete("s");
160
+ resetReasons.add("uid");
161
+ }
162
+
163
+ const hasUidReason = resetReasons.has("uid");
164
+ const hasCountReason = resetReasons.has("count");
165
+
166
+ if (hasCountReason && hasUidReason) {
167
+ if (window.location.href.includes("?")) {
168
+ [href] = window.location.href.split("?");
169
+
170
+ window.location.href = href;
171
+ }
172
+ } else if ((hasCountReason && !hasUidReason) || (!hasCountReason && hasUidReason)) {
173
+ window.location.search = params.toString();
174
+ }
175
+ }
176
+
177
+ function resetForm(event) {
178
+ event.preventDefault();
179
+ const params = new URLSearchParams(window.location.search);
180
+ params.delete("count");
181
+ params.delete("uid");
182
+ params.delete("s");
183
+ if (window.location.href.includes("?")) {
184
+ window.location.href = window.location.href.split("?")[0];
185
+ }
186
+ }
187
+
188
+ function onChangeGenerateUniqueId(element) {
189
+ const switcher = document.getElementById("unique_id");
190
+ const key = document.getElementById("unique_id_key_field");
191
+ const strategy = document.getElementById("unique_strategy_container");
192
+ switcher.checked = !switcher.checked;
193
+ key.setAttribute("data-visible", switcher.checked.toString());
194
+ strategy.setAttribute("data-visible", switcher.checked.toString());
195
+ }
196
+
197
+ function onHandleUniqueIdStrategy(element) {
198
+ const strategy = document.getElementById("unique_id_strategy");
199
+ strategy.checked = !strategy.checked;
200
+ }
201
+ </script> -->
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "fakelab",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "lib/main.js",
7
+ "types": "lib/main.d.ts",
8
+ "engines": {
9
+ "node": ">=18"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "release": "release-it --ci",
17
+ "serve": "yarn build && node lib/cli.js serve"
18
+ },
19
+ "directories": {
20
+ "lib": "./lib"
21
+ },
22
+ "files": [
23
+ "lib"
24
+ ],
25
+ "devDependencies": {
26
+ "@release-it/conventional-changelog": "^10.0.2",
27
+ "@types/cors": "^2.8.19",
28
+ "@types/doctrine": "^0.0.9",
29
+ "@types/ejs": "^3.1.5",
30
+ "@types/express": "^5.0.6",
31
+ "@types/express-ejs-layouts": "^2.5.4",
32
+ "@types/fs-extra": "^11.0.4",
33
+ "@types/node": "^24.10.1",
34
+ "release-it": "^19.0.6",
35
+ "tsup": "^8.5.1",
36
+ "tsx": "^4.21.0",
37
+ "typescript": "~5.9.3"
38
+ },
39
+ "dependencies": {
40
+ "@faker-js/faker": "^10.1.0",
41
+ "bundle-require": "^5.1.0",
42
+ "commander": "^14.0.2",
43
+ "cors": "^2.8.5",
44
+ "doctrine": "^3.0.0",
45
+ "ejs": "^3.1.10",
46
+ "express": "^5.2.1",
47
+ "express-ejs-layouts": "^2.5.1",
48
+ "fast-glob": "^3.3.3",
49
+ "figlet": "^1.9.4",
50
+ "fs-extra": "^11.3.2",
51
+ "joycon": "^3.1.1",
52
+ "picocolors": "^1.1.1",
53
+ "qs": "^6.14.0",
54
+ "ts-morph": "^27.0.2",
55
+ "uglify-js": "^3.19.3",
56
+ "uuid": "^13.0.0",
57
+ "zod": "^4.1.13"
58
+ },
59
+ "bin": {
60
+ "fakelab": "bin/run.js"
61
+ }
62
+ }