@shriyanss/js-recon 1.0.0

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,25 @@
1
+ import 'ses';
2
+
3
+ // Lock down the global environment for security
4
+ lockdown();
5
+
6
+ /**
7
+ * Executes a given function in a sandboxed environment.
8
+ * @param {string} code - The code to execute.
9
+ * @param {any} param - The parameter to pass to the function.
10
+ * @returns {any} The result of the function execution.
11
+ */
12
+ const execFunc = (code, param) => {
13
+ const c = new Compartment({
14
+ console,
15
+ });
16
+ const wrappedCode = `
17
+ (${code})
18
+ `;
19
+ const func = c.evaluate(wrappedCode);
20
+ const output = func(param);
21
+
22
+ return output;
23
+ };
24
+
25
+ export default execFunc;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Extracts the host and directory path from a given URL.
3
+ *
4
+ * @param {string} url - The URL to be processed.
5
+ * @returns {Object} An object containing:
6
+ * - host: The hostname of the URL (e.g., "vercel.com" or "localhost:3000").
7
+ * - directory: The directory path, excluding the filename if present (e.g., "/static/js").
8
+ */
9
+ const getURLDirectory = (url) => {
10
+ const u = new URL(url);
11
+ const pathname = u.pathname;
12
+
13
+ // Remove filename (last part after final /) if it ends with .js or any file extension
14
+ const dir = pathname.replace(/\/[^\/?#]+\.[^\/?#]+$/, "");
15
+
16
+ return {
17
+ host: u.host, // e.g., "vercel.com" or "localhost:3000"
18
+ directory: dir, // e.g., "/static/js"
19
+ };
20
+ };
21
+
22
+ export { getURLDirectory };