@forklaunch/common
Advanced tools
+100
-9
@@ -228,8 +228,10 @@ "use strict"; | ||
| const fnStr = func.toString(); | ||
| const args = fnStr.match(/\(([^)]*)\)/); | ||
| if (!args) return []; | ||
| const argsStr = args[1]; | ||
| const parameterList = findParameterList(fnStr); | ||
| if (parameterList == null) return []; | ||
| const argsStr = fnStr.slice(parameterList.start + 1, parameterList.end); | ||
| const result = []; | ||
| let currentArg = ""; | ||
| let braceCount = 0; | ||
| let bracketCount = 0; | ||
| let parenCount = 0; | ||
| for (let i = 0; i < argsStr.length; i++) { | ||
@@ -239,16 +241,105 @@ const char = argsStr[i]; | ||
| if (char === "}") braceCount--; | ||
| if (char === "," && braceCount === 0) { | ||
| result.push(currentArg.trim()); | ||
| if (char === "[") bracketCount++; | ||
| if (char === "]") bracketCount--; | ||
| if (char === "(") parenCount++; | ||
| if (char === ")") parenCount--; | ||
| if (char === "," && braceCount === 0 && bracketCount === 0 && parenCount === 0) { | ||
| result.push(normalizeArgument(currentArg)); | ||
| currentArg = ""; | ||
| } else { | ||
| if (char === " " || char === "\n" || char === " " || char === "\r") | ||
| continue; | ||
| currentArg += char; | ||
| } | ||
| } | ||
| if (currentArg) { | ||
| result.push(currentArg.trim()); | ||
| if (currentArg.trim()) { | ||
| result.push(normalizeArgument(currentArg)); | ||
| } | ||
| return result; | ||
| } | ||
| function findParameterList(fnStr) { | ||
| for (let i = 0; i < fnStr.length; i++) { | ||
| if (fnStr[i] !== "(") continue; | ||
| const end = findMatchingParen(fnStr, i); | ||
| if (end === -1) continue; | ||
| if (isParameterList(fnStr, end)) { | ||
| return { start: i, end }; | ||
| } | ||
| } | ||
| } | ||
| function isParameterList(fnStr, closingParenIndex) { | ||
| let nextIndex = skipWhitespace(fnStr, closingParenIndex + 1); | ||
| if (fnStr.startsWith("=>", nextIndex)) return true; | ||
| if (fnStr[nextIndex] === "{") return true; | ||
| if (fnStr[nextIndex] !== ":") return false; | ||
| nextIndex++; | ||
| let braceCount = 0; | ||
| let bracketCount = 0; | ||
| let parenCount = 0; | ||
| for (let i = nextIndex; i < fnStr.length - 1; i++) { | ||
| const char = fnStr[i]; | ||
| if (char === "{") braceCount++; | ||
| if (char === "}") braceCount--; | ||
| if (char === "[") bracketCount++; | ||
| if (char === "]") bracketCount--; | ||
| if (char === "(") parenCount++; | ||
| if (char === ")") parenCount--; | ||
| if (braceCount === 0 && bracketCount === 0 && parenCount === 0 && fnStr.startsWith("=>", i)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| function findMatchingParen(fnStr, openingParenIndex) { | ||
| let depth = 0; | ||
| let quote; | ||
| let escaped = false; | ||
| for (let i = openingParenIndex; i < fnStr.length; i++) { | ||
| const char = fnStr[i]; | ||
| if (quote != null) { | ||
| if (escaped) { | ||
| escaped = false; | ||
| } else if (char === "\\") { | ||
| escaped = true; | ||
| } else if (char === quote) { | ||
| quote = void 0; | ||
| } | ||
| continue; | ||
| } | ||
| if (char === '"' || char === "'" || char === "`") { | ||
| quote = char; | ||
| continue; | ||
| } | ||
| if (char === "(") depth++; | ||
| if (char === ")") { | ||
| depth--; | ||
| if (depth === 0) return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
| function skipWhitespace(value, startIndex) { | ||
| let index = startIndex; | ||
| while (/\s/.test(value[index] ?? "")) index++; | ||
| return index; | ||
| } | ||
| function normalizeArgument(arg) { | ||
| return stripTopLevelTypeAnnotation(arg).replace(/\s+/g, ""); | ||
| } | ||
| function stripTopLevelTypeAnnotation(arg) { | ||
| let braceCount = 0; | ||
| let bracketCount = 0; | ||
| let parenCount = 0; | ||
| for (let i = 0; i < arg.length; i++) { | ||
| const char = arg[i]; | ||
| if (char === "{") braceCount++; | ||
| if (char === "}") braceCount--; | ||
| if (char === "[") bracketCount++; | ||
| if (char === "]") bracketCount--; | ||
| if (char === "(") parenCount++; | ||
| if (char === ")") parenCount--; | ||
| if (char === ":" && braceCount === 0 && bracketCount === 0 && parenCount === 0) { | ||
| return arg.slice(0, i); | ||
| } | ||
| } | ||
| return arg; | ||
| } | ||
@@ -255,0 +346,0 @@ // src/getEnvVar.ts |
+100
-9
@@ -171,8 +171,10 @@ // src/camelCase.ts | ||
| const fnStr = func.toString(); | ||
| const args = fnStr.match(/\(([^)]*)\)/); | ||
| if (!args) return []; | ||
| const argsStr = args[1]; | ||
| const parameterList = findParameterList(fnStr); | ||
| if (parameterList == null) return []; | ||
| const argsStr = fnStr.slice(parameterList.start + 1, parameterList.end); | ||
| const result = []; | ||
| let currentArg = ""; | ||
| let braceCount = 0; | ||
| let bracketCount = 0; | ||
| let parenCount = 0; | ||
| for (let i = 0; i < argsStr.length; i++) { | ||
@@ -182,16 +184,105 @@ const char = argsStr[i]; | ||
| if (char === "}") braceCount--; | ||
| if (char === "," && braceCount === 0) { | ||
| result.push(currentArg.trim()); | ||
| if (char === "[") bracketCount++; | ||
| if (char === "]") bracketCount--; | ||
| if (char === "(") parenCount++; | ||
| if (char === ")") parenCount--; | ||
| if (char === "," && braceCount === 0 && bracketCount === 0 && parenCount === 0) { | ||
| result.push(normalizeArgument(currentArg)); | ||
| currentArg = ""; | ||
| } else { | ||
| if (char === " " || char === "\n" || char === " " || char === "\r") | ||
| continue; | ||
| currentArg += char; | ||
| } | ||
| } | ||
| if (currentArg) { | ||
| result.push(currentArg.trim()); | ||
| if (currentArg.trim()) { | ||
| result.push(normalizeArgument(currentArg)); | ||
| } | ||
| return result; | ||
| } | ||
| function findParameterList(fnStr) { | ||
| for (let i = 0; i < fnStr.length; i++) { | ||
| if (fnStr[i] !== "(") continue; | ||
| const end = findMatchingParen(fnStr, i); | ||
| if (end === -1) continue; | ||
| if (isParameterList(fnStr, end)) { | ||
| return { start: i, end }; | ||
| } | ||
| } | ||
| } | ||
| function isParameterList(fnStr, closingParenIndex) { | ||
| let nextIndex = skipWhitespace(fnStr, closingParenIndex + 1); | ||
| if (fnStr.startsWith("=>", nextIndex)) return true; | ||
| if (fnStr[nextIndex] === "{") return true; | ||
| if (fnStr[nextIndex] !== ":") return false; | ||
| nextIndex++; | ||
| let braceCount = 0; | ||
| let bracketCount = 0; | ||
| let parenCount = 0; | ||
| for (let i = nextIndex; i < fnStr.length - 1; i++) { | ||
| const char = fnStr[i]; | ||
| if (char === "{") braceCount++; | ||
| if (char === "}") braceCount--; | ||
| if (char === "[") bracketCount++; | ||
| if (char === "]") bracketCount--; | ||
| if (char === "(") parenCount++; | ||
| if (char === ")") parenCount--; | ||
| if (braceCount === 0 && bracketCount === 0 && parenCount === 0 && fnStr.startsWith("=>", i)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| function findMatchingParen(fnStr, openingParenIndex) { | ||
| let depth = 0; | ||
| let quote; | ||
| let escaped = false; | ||
| for (let i = openingParenIndex; i < fnStr.length; i++) { | ||
| const char = fnStr[i]; | ||
| if (quote != null) { | ||
| if (escaped) { | ||
| escaped = false; | ||
| } else if (char === "\\") { | ||
| escaped = true; | ||
| } else if (char === quote) { | ||
| quote = void 0; | ||
| } | ||
| continue; | ||
| } | ||
| if (char === '"' || char === "'" || char === "`") { | ||
| quote = char; | ||
| continue; | ||
| } | ||
| if (char === "(") depth++; | ||
| if (char === ")") { | ||
| depth--; | ||
| if (depth === 0) return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
| function skipWhitespace(value, startIndex) { | ||
| let index = startIndex; | ||
| while (/\s/.test(value[index] ?? "")) index++; | ||
| return index; | ||
| } | ||
| function normalizeArgument(arg) { | ||
| return stripTopLevelTypeAnnotation(arg).replace(/\s+/g, ""); | ||
| } | ||
| function stripTopLevelTypeAnnotation(arg) { | ||
| let braceCount = 0; | ||
| let bracketCount = 0; | ||
| let parenCount = 0; | ||
| for (let i = 0; i < arg.length; i++) { | ||
| const char = arg[i]; | ||
| if (char === "{") braceCount++; | ||
| if (char === "}") braceCount--; | ||
| if (char === "[") bracketCount++; | ||
| if (char === "]") bracketCount--; | ||
| if (char === "(") parenCount++; | ||
| if (char === ")") parenCount--; | ||
| if (char === ":" && braceCount === 0 && bracketCount === 0 && parenCount === 0) { | ||
| return arg.slice(0, i); | ||
| } | ||
| } | ||
| return arg; | ||
| } | ||
@@ -198,0 +289,0 @@ // src/getEnvVar.ts |
+7
-7
| { | ||
| "name": "@forklaunch/common", | ||
| "version": "1.2.17", | ||
| "version": "1.2.18", | ||
| "description": "Common package for base types, interfaces, implementations.", | ||
@@ -32,12 +32,12 @@ "homepage": "https://github.com/forklaunch/forklaunch-js#readme", | ||
| "@eslint/js": "^10.0.1", | ||
| "@types/node": "^25.6.0", | ||
| "@typescript/native-preview": "7.0.0-dev.20260417.1", | ||
| "@types/node": "^25.7.0", | ||
| "@typescript/native-preview": "7.0.0-dev.20260511.1", | ||
| "depcheck": "^1.4.7", | ||
| "eslint": "^10.2.1", | ||
| "globals": "^17.5.0", | ||
| "eslint": "^10.3.0", | ||
| "globals": "^17.6.0", | ||
| "tsup": "^8.5.1", | ||
| "typedoc": "^0.28.19", | ||
| "typescript": "^6.0.3", | ||
| "typescript-eslint": "^8.58.2", | ||
| "vitest": "^4.1.4" | ||
| "typescript-eslint": "^8.59.3", | ||
| "vitest": "^4.1.6" | ||
| }, | ||
@@ -44,0 +44,0 @@ "scripts": { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
84411
6.91%1656
12.35%11
57.14%