@ossintel/input-parser 0.2.1 → 0.3.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.
package/README.md CHANGED
@@ -28,12 +28,15 @@
28
28
  - **Ecosystem Agnostic**: Parses query strings, profiles, and URLs across GitHub, NPM, StackOverflow, VS Code, Medium, and LeetCode.
29
29
  - **URL Auto-Healing**: Extracts platform, owner, repo, package name, or user IDs directly from browser copy-pasted URLs.
30
30
  - **Prefix Shortcuts**: Handles intuitive prefix syntax (e.g. `org:react18-tools`, `npm:~isaacs`, `so:12345`).
31
+ - **Manifest Auto-Detection**: Inspects `package.json` contents to distinguish standard npm libraries from VS Code extensions (via `engines.vscode`, `publisher`, and `name`) for repository ingestion workflows.
31
32
  - **Fully Typed & Lightweight**: Zero external dependencies, compiling to highly optimized, type-safe ESM/CJS bundles.
32
33
 
33
34
  ---
34
35
 
35
36
  ## 🚀 Usage
36
37
 
38
+ ### 1. Parsing User Queries and URLs
39
+
37
40
  ```typescript
38
41
  import { detectInput } from "@ossintel/input-parser";
39
42
 
@@ -50,6 +53,48 @@ const npmUser = detectInput("npm:~mayank1513");
50
53
  // => { platform: "npm", type: "user", name: "mayank1513", rawInput: "..." }
51
54
  ```
52
55
 
56
+ ### 2. Auto-Detecting Manifests (Repository Ingestion)
57
+
58
+ When analyzing repositories during ingestion, pass the repository's `package.json` manifest (either as a parsed object or raw JSON string) to identify package identity and VS Code extension targets:
59
+
60
+ ```typescript
61
+ import { detectManifest } from "@ossintel/input-parser";
62
+
63
+ // Detect a VS Code extension manifest
64
+ const extensionResult = detectManifest({
65
+ name: "promptshield-vscode",
66
+ publisher: "mayank1513",
67
+ version: "0.2.0",
68
+ engines: { vscode: "^1.80.0" },
69
+ });
70
+ // => {
71
+ // isPackage: true,
72
+ // isVsCodeExtension: true,
73
+ // isNpmPackage: true,
74
+ // packageName: "promptshield-vscode",
75
+ // vscodeExtensionId: "mayank1513.promptshield-vscode",
76
+ // publisher: "mayank1513",
77
+ // version: "0.2.0"
78
+ // }
79
+
80
+ // Detect a standard NPM package manifest
81
+ const pkgResult = detectManifest({
82
+ name: "@ossintel/scoring",
83
+ version: "1.0.0",
84
+ });
85
+ // => {
86
+ // isPackage: true,
87
+ // isVsCodeExtension: false,
88
+ // isNpmPackage: true,
89
+ // packageName: "@ossintel/scoring",
90
+ // vscodeExtensionId: undefined,
91
+ // publisher: undefined,
92
+ // version: "1.0.0"
93
+ // }
94
+ ```
95
+
96
+ > **Note**: `detectInput` also supports raw JSON strings as an opportunistic fallback, automatically routing to `platform: "vscode"` or `platform: "npm"`.
97
+
53
98
  ---
54
99
 
55
100
  ## 📦 Installation
package/dist/index.d.mts CHANGED
@@ -28,6 +28,53 @@ interface InputDetectionResult {
28
28
  */
29
29
  rawInput: string;
30
30
  }
31
+ interface PackageManifest {
32
+ name?: string;
33
+ publisher?: string;
34
+ version?: string;
35
+ engines?: {
36
+ vscode?: string;
37
+ };
38
+ private?: boolean;
39
+ workspaces?: string[] | {
40
+ packages?: string[];
41
+ };
42
+ }
43
+ interface ManifestDetectionResult {
44
+ isPackage: boolean;
45
+ isVsCodeExtension: boolean;
46
+ isNpmPackage: boolean;
47
+ isMonorepo?: boolean;
48
+ isPrivate?: boolean;
49
+ packageName?: string;
50
+ vscodeExtensionId?: string;
51
+ publisher?: string;
52
+ version?: string;
53
+ }
54
+ interface MultiManifestDetectionResult {
55
+ isMonorepo: boolean;
56
+ totalPackages: number;
57
+ npmPackages: ManifestDetectionResult[];
58
+ vscodeExtensions: ManifestDetectionResult[];
59
+ all: ManifestDetectionResult[];
60
+ }
61
+ /**
62
+ * Auto-detects package ecosystem and identity from a package.json manifest.
63
+ * Inspects `name`, `publisher`, and `engines.vscode` to distinguish between
64
+ * standard npm packages and VS Code extensions.
65
+ *
66
+ * @param manifestInput - Raw JSON string or parsed package.json manifest object
67
+ * @returns Detection result identifying package flags, name, and VS Code extension ID
68
+ */
69
+ declare const detectManifest: (manifestInput: string | PackageManifest | Record<string, unknown> | null | undefined) => ManifestDetectionResult;
70
+ /**
71
+ * Analyzes multiple manifests (e.g. from monorepos or multi-package workspaces).
72
+ * Identifies whether the workspace is a monorepo and categorizes subpackages.
73
+ *
74
+ * @param manifestsInput - Array of manifest objects or JSON strings
75
+ * @returns Aggregated multi-manifest detection result
76
+ */
77
+ declare const detectManifests: (manifestsInput: Array<string | PackageManifest | Record<string, unknown> | null | undefined>) => MultiManifestDetectionResult;
31
78
  /**
32
79
  * Parses and resolves search query strings into platform and type targets.
33
80
  * Supporting URLs, prefixes, and fallback shorthands.
@@ -49,4 +96,5 @@ interface InputDetectionResult {
49
96
  */
50
97
  declare const detectInput: (input: string) => InputDetectionResult;
51
98
 
52
- export { type InputDetectionResult, detectInput };
99
+ export { detectInput, detectManifest, detectManifests };
100
+ export type { InputDetectionResult, ManifestDetectionResult, MultiManifestDetectionResult, PackageManifest };
package/dist/index.d.ts CHANGED
@@ -28,6 +28,53 @@ interface InputDetectionResult {
28
28
  */
29
29
  rawInput: string;
30
30
  }
31
+ interface PackageManifest {
32
+ name?: string;
33
+ publisher?: string;
34
+ version?: string;
35
+ engines?: {
36
+ vscode?: string;
37
+ };
38
+ private?: boolean;
39
+ workspaces?: string[] | {
40
+ packages?: string[];
41
+ };
42
+ }
43
+ interface ManifestDetectionResult {
44
+ isPackage: boolean;
45
+ isVsCodeExtension: boolean;
46
+ isNpmPackage: boolean;
47
+ isMonorepo?: boolean;
48
+ isPrivate?: boolean;
49
+ packageName?: string;
50
+ vscodeExtensionId?: string;
51
+ publisher?: string;
52
+ version?: string;
53
+ }
54
+ interface MultiManifestDetectionResult {
55
+ isMonorepo: boolean;
56
+ totalPackages: number;
57
+ npmPackages: ManifestDetectionResult[];
58
+ vscodeExtensions: ManifestDetectionResult[];
59
+ all: ManifestDetectionResult[];
60
+ }
61
+ /**
62
+ * Auto-detects package ecosystem and identity from a package.json manifest.
63
+ * Inspects `name`, `publisher`, and `engines.vscode` to distinguish between
64
+ * standard npm packages and VS Code extensions.
65
+ *
66
+ * @param manifestInput - Raw JSON string or parsed package.json manifest object
67
+ * @returns Detection result identifying package flags, name, and VS Code extension ID
68
+ */
69
+ declare const detectManifest: (manifestInput: string | PackageManifest | Record<string, unknown> | null | undefined) => ManifestDetectionResult;
70
+ /**
71
+ * Analyzes multiple manifests (e.g. from monorepos or multi-package workspaces).
72
+ * Identifies whether the workspace is a monorepo and categorizes subpackages.
73
+ *
74
+ * @param manifestsInput - Array of manifest objects or JSON strings
75
+ * @returns Aggregated multi-manifest detection result
76
+ */
77
+ declare const detectManifests: (manifestsInput: Array<string | PackageManifest | Record<string, unknown> | null | undefined>) => MultiManifestDetectionResult;
31
78
  /**
32
79
  * Parses and resolves search query strings into platform and type targets.
33
80
  * Supporting URLs, prefixes, and fallback shorthands.
@@ -49,4 +96,5 @@ interface InputDetectionResult {
49
96
  */
50
97
  declare const detectInput: (input: string) => InputDetectionResult;
51
98
 
52
- export { type InputDetectionResult, detectInput };
99
+ export { detectInput, detectManifest, detectManifests };
100
+ export type { InputDetectionResult, ManifestDetectionResult, MultiManifestDetectionResult, PackageManifest };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var m=(n,t)=>{for(var r in t)a(n,r,{get:t[r],enumerable:!0})},f=(n,t,r,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of u(t))!l.call(n,e)&&e!==r&&a(n,e,{get:()=>t[e],enumerable:!(p=o(t,e))||p.enumerable});return n};var c=n=>f(a({},"__esModule",{value:!0}),n);var I={};m(I,{detectInput:()=>h});module.exports=c(I);var h=n=>{let t=n.trim();if(t.startsWith("npm:pkg:"))return{platform:"npm",type:"package",name:t.slice(8),rawInput:t};if(t.startsWith("npm:")){let r=t.slice(4);return r.startsWith("~")?{platform:"npm",type:"user",name:r.slice(1),rawInput:t}:{platform:"npm",type:"package",name:r,rawInput:t}}if(t.startsWith("~"))return{platform:"npm",type:"user",name:t.slice(1),rawInput:t};if(t.startsWith("so:")||t.startsWith("stackoverflow:")){let r=t.startsWith("so:")?3:14;return{platform:"stackoverflow",type:"user",profileId:t.slice(r),rawInput:t}}if(t.startsWith("org:")||t.startsWith("github:org:")){let r=t.startsWith("org:")?4:11;return{platform:"github",type:"org",owner:t.slice(r),rawInput:t}}if(t.startsWith("user:")||t.startsWith("github:user:")){let r=t.startsWith("user:")?5:12;return{platform:"github",type:"user",owner:t.slice(r),rawInput:t}}if(t.startsWith("github:repo:")){let r=t.slice(12).split("/");return{platform:"github",type:"repo",owner:r[0]||"",repo:r[1]||"",rawInput:t}}if(t.startsWith("github:")){let r=t.slice(7).split("/");return r.length>=2?{platform:"github",type:"repo",owner:r[0],repo:r[1],rawInput:t}:{platform:"github",type:"unknown",owner:r[0],rawInput:t}}if(t.startsWith("vscode:")){let r=t.slice(7).split("/");return{platform:"vscode",type:r.length>=2?"package":"user",name:r.join("."),rawInput:t}}if(t.startsWith("medium:"))return{platform:"medium",type:"user",profileId:t.slice(7),rawInput:t};if(t.startsWith("leetcode:"))return{platform:"leetcode",type:"user",profileId:t.slice(9),rawInput:t};try{let r=new URL(t.match(/^https?:\/\//i)?t:`https://${t}`),p=r.hostname.toLowerCase();if(p.includes("github.com")){let e=r.pathname.split("/").filter(Boolean);if(e[0]==="organizations"||e[0]==="orgs")return{platform:"github",type:"org",owner:e[1]||"",rawInput:t};if(e.length===1)return{platform:"github",type:"unknown",owner:e[0],rawInput:t};if(e.length>=2)return{platform:"github",type:"repo",owner:e[0],repo:e[1],rawInput:t}}if(p.includes("npmjs.com")){let e=r.pathname.split("/").filter(Boolean);if(e[0]==="package")return{platform:"npm",type:"package",name:e.slice(1).join("/"),rawInput:t};if(e[0].startsWith("~"))return{platform:"npm",type:"user",name:e[0].slice(1),rawInput:t};if(e[0].startsWith("@"))return e.length===1?{platform:"npm",type:"org",name:e[0],rawInput:t}:{platform:"npm",type:"package",name:`${e[0]}/${e[1]}`,rawInput:t}}if(p.includes("stackoverflow.com")){let e=r.pathname.split("/").filter(Boolean);if(e[0]==="users"&&e[1])return{platform:"stackoverflow",type:"user",profileId:e[1],name:e[2]||void 0,rawInput:t}}if(p.includes("medium.com")){let e=r.pathname.split("/").filter(Boolean),i=e[0]?.startsWith("@")?e[0].slice(1):e[0];if(i)return{platform:"medium",type:"user",profileId:i,rawInput:t}}}catch{}if(t.startsWith("organizations/")||t.startsWith("orgs/"))return{platform:"github",type:"org",owner:t.split("/")[1]||"",rawInput:t};if(t.startsWith("@")&&t.includes("/"))return{platform:"npm",type:"package",name:t,rawInput:t};if(t.includes("/")){let r=t.split("/");return{platform:"github",type:"repo",owner:r[0],repo:r[1],rawInput:t}}return{platform:"github",type:"unknown",owner:t,rawInput:t}};0&&(module.exports={detectInput});
1
+ "use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var d=(s,e)=>{for(var t in e)l(s,t,{get:e[t],enumerable:!0})},w=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!h.call(s,r)&&r!==t&&l(s,r,{get:()=>e[r],enumerable:!(n=g(e,r))||n.enumerable});return s};var k=s=>w(l({},"__esModule",{value:!0}),s);var P={};d(P,{detectInput:()=>E,detectManifest:()=>u,detectManifests:()=>I});module.exports=k(P);var u=s=>{if(!s)return{isPackage:!1,isVsCodeExtension:!1,isNpmPackage:!1};let e;if(typeof s=="string")try{e=JSON.parse(s)}catch{return{isPackage:!1,isVsCodeExtension:!1,isNpmPackage:!1}}else if(typeof s=="object")e=s;else return{isPackage:!1,isVsCodeExtension:!1,isNpmPackage:!1};let t=typeof e.name=="string"?e.name.trim():void 0,n=typeof e.publisher=="string"?e.publisher.trim():void 0,r=typeof e.version=="string"?e.version.trim():void 0,i=e.engines&&typeof e.engines=="object"?e.engines:void 0,o=!!(i&&typeof i.vscode=="string"),a=!!t,f=!!(e.workspaces&&(Array.isArray(e.workspaces)||typeof e.workspaces=="object"&&Array.isArray(e.workspaces.packages))),c;return o&&(n&&t?c=`${n}.${t}`:t&&(c=t)),{isPackage:a||o,isVsCodeExtension:o,isNpmPackage:a,...f?{isMonorepo:!0}:{},...e.private?{isPrivate:!0}:{},packageName:t,vscodeExtensionId:c,publisher:n,version:r}},I=s=>{if(!Array.isArray(s)||s.length===0)return{isMonorepo:!1,totalPackages:0,npmPackages:[],vscodeExtensions:[],all:[]};let e=[],t=[],n=[],r=!1;for(let o of s){let a=u(o);a.isMonorepo&&(r=!0),a.isPackage&&(e.push(a),a.isVsCodeExtension&&n.push(a),a.isNpmPackage&&t.push(a))}return{isMonorepo:r||e.length>1,totalPackages:e.length,npmPackages:t,vscodeExtensions:n,all:e}},E=s=>{let e=s.trim();if(e.startsWith("{")&&e.endsWith("}")){let t=u(e);if(t.isVsCodeExtension&&t.vscodeExtensionId)return{platform:"vscode",type:"package",name:t.vscodeExtensionId,rawInput:e};if(t.isNpmPackage&&t.packageName)return{platform:"npm",type:"package",name:t.packageName,rawInput:e}}if(e.startsWith("npm:pkg:"))return{platform:"npm",type:"package",name:e.slice(8),rawInput:e};if(e.startsWith("npm:")){let t=e.slice(4);return t.startsWith("~")?{platform:"npm",type:"user",name:t.slice(1),rawInput:e}:{platform:"npm",type:"package",name:t,rawInput:e}}if(e.startsWith("~"))return{platform:"npm",type:"user",name:e.slice(1),rawInput:e};if(e.startsWith("so:")||e.startsWith("stackoverflow:")){let t=e.startsWith("so:")?3:14;return{platform:"stackoverflow",type:"user",profileId:e.slice(t),rawInput:e}}if(e.startsWith("org:")||e.startsWith("github:org:")){let t=e.startsWith("org:")?4:11;return{platform:"github",type:"org",owner:e.slice(t),rawInput:e}}if(e.startsWith("user:")||e.startsWith("github:user:")){let t=e.startsWith("user:")?5:12;return{platform:"github",type:"user",owner:e.slice(t),rawInput:e}}if(e.startsWith("github:repo:")){let t=e.slice(12).split("/");return{platform:"github",type:"repo",owner:t[0]||"",repo:t[1]||"",rawInput:e}}if(e.startsWith("github:")){let t=e.slice(7).split("/");return t.length>=2?{platform:"github",type:"repo",owner:t[0],repo:t[1],rawInput:e}:{platform:"github",type:"unknown",owner:t[0],rawInput:e}}if(e.startsWith("vscode:")){let t=e.slice(7).split("/");return{platform:"vscode",type:t.length>=2?"package":"user",name:t.join("."),rawInput:e}}if(e.startsWith("medium:"))return{platform:"medium",type:"user",profileId:e.slice(7),rawInput:e};if(e.startsWith("leetcode:"))return{platform:"leetcode",type:"user",profileId:e.slice(9),rawInput:e};try{let t=new URL(e.match(/^https?:\/\//i)?e:`https://${e}`),n=t.hostname.toLowerCase();if(n.includes("github.com")){let r=t.pathname.split("/").filter(Boolean);if(r[0]==="organizations"||r[0]==="orgs")return{platform:"github",type:"org",owner:r[1]||"",rawInput:e};if(r.length===1)return{platform:"github",type:"unknown",owner:r[0],rawInput:e};if(r.length>=2)return{platform:"github",type:"repo",owner:r[0],repo:r[1],rawInput:e}}if(n.includes("npmjs.com")){let r=t.pathname.split("/").filter(Boolean);if(r[0]==="package")return{platform:"npm",type:"package",name:r.slice(1).join("/"),rawInput:e};if(r[0].startsWith("~"))return{platform:"npm",type:"user",name:r[0].slice(1),rawInput:e};if(r[0].startsWith("@"))return r.length===1?{platform:"npm",type:"org",name:r[0],rawInput:e}:{platform:"npm",type:"package",name:`${r[0]}/${r[1]}`,rawInput:e}}if(n.includes("stackoverflow.com")){let r=t.pathname.split("/").filter(Boolean);if(r[0]==="users"&&r[1])return{platform:"stackoverflow",type:"user",profileId:r[1],name:r[2]||void 0,rawInput:e}}if(n.includes("medium.com")){let r=t.pathname.split("/").filter(Boolean),i=r[0]?.startsWith("@")?r[0].slice(1):r[0];if(i)return{platform:"medium",type:"user",profileId:i,rawInput:e}}}catch{}if(e.startsWith("organizations/")||e.startsWith("orgs/"))return{platform:"github",type:"org",owner:e.split("/")[1]||"",rawInput:e};if(e.startsWith("@")&&e.includes("/"))return{platform:"npm",type:"package",name:e,rawInput:e};if(e.includes("/")){let t=e.split("/");return{platform:"github",type:"repo",owner:t[0],repo:t[1],rawInput:e}}return{platform:"github",type:"unknown",owner:e,rawInput:e}};0&&(module.exports={detectInput,detectManifest,detectManifests});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var y=a=>{let t=a.trim();if(t.startsWith("npm:pkg:"))return{platform:"npm",type:"package",name:t.slice(8),rawInput:t};if(t.startsWith("npm:")){let r=t.slice(4);return r.startsWith("~")?{platform:"npm",type:"user",name:r.slice(1),rawInput:t}:{platform:"npm",type:"package",name:r,rawInput:t}}if(t.startsWith("~"))return{platform:"npm",type:"user",name:t.slice(1),rawInput:t};if(t.startsWith("so:")||t.startsWith("stackoverflow:")){let r=t.startsWith("so:")?3:14;return{platform:"stackoverflow",type:"user",profileId:t.slice(r),rawInput:t}}if(t.startsWith("org:")||t.startsWith("github:org:")){let r=t.startsWith("org:")?4:11;return{platform:"github",type:"org",owner:t.slice(r),rawInput:t}}if(t.startsWith("user:")||t.startsWith("github:user:")){let r=t.startsWith("user:")?5:12;return{platform:"github",type:"user",owner:t.slice(r),rawInput:t}}if(t.startsWith("github:repo:")){let r=t.slice(12).split("/");return{platform:"github",type:"repo",owner:r[0]||"",repo:r[1]||"",rawInput:t}}if(t.startsWith("github:")){let r=t.slice(7).split("/");return r.length>=2?{platform:"github",type:"repo",owner:r[0],repo:r[1],rawInput:t}:{platform:"github",type:"unknown",owner:r[0],rawInput:t}}if(t.startsWith("vscode:")){let r=t.slice(7).split("/");return{platform:"vscode",type:r.length>=2?"package":"user",name:r.join("."),rawInput:t}}if(t.startsWith("medium:"))return{platform:"medium",type:"user",profileId:t.slice(7),rawInput:t};if(t.startsWith("leetcode:"))return{platform:"leetcode",type:"user",profileId:t.slice(9),rawInput:t};try{let r=new URL(t.match(/^https?:\/\//i)?t:`https://${t}`),n=r.hostname.toLowerCase();if(n.includes("github.com")){let e=r.pathname.split("/").filter(Boolean);if(e[0]==="organizations"||e[0]==="orgs")return{platform:"github",type:"org",owner:e[1]||"",rawInput:t};if(e.length===1)return{platform:"github",type:"unknown",owner:e[0],rawInput:t};if(e.length>=2)return{platform:"github",type:"repo",owner:e[0],repo:e[1],rawInput:t}}if(n.includes("npmjs.com")){let e=r.pathname.split("/").filter(Boolean);if(e[0]==="package")return{platform:"npm",type:"package",name:e.slice(1).join("/"),rawInput:t};if(e[0].startsWith("~"))return{platform:"npm",type:"user",name:e[0].slice(1),rawInput:t};if(e[0].startsWith("@"))return e.length===1?{platform:"npm",type:"org",name:e[0],rawInput:t}:{platform:"npm",type:"package",name:`${e[0]}/${e[1]}`,rawInput:t}}if(n.includes("stackoverflow.com")){let e=r.pathname.split("/").filter(Boolean);if(e[0]==="users"&&e[1])return{platform:"stackoverflow",type:"user",profileId:e[1],name:e[2]||void 0,rawInput:t}}if(n.includes("medium.com")){let e=r.pathname.split("/").filter(Boolean),s=e[0]?.startsWith("@")?e[0].slice(1):e[0];if(s)return{platform:"medium",type:"user",profileId:s,rawInput:t}}}catch{}if(t.startsWith("organizations/")||t.startsWith("orgs/"))return{platform:"github",type:"org",owner:t.split("/")[1]||"",rawInput:t};if(t.startsWith("@")&&t.includes("/"))return{platform:"npm",type:"package",name:t,rawInput:t};if(t.includes("/")){let r=t.split("/");return{platform:"github",type:"repo",owner:r[0],repo:r[1],rawInput:t}}return{platform:"github",type:"unknown",owner:t,rawInput:t}};export{y as detectInput};
1
+ var l=s=>{if(!s)return{isPackage:!1,isVsCodeExtension:!1,isNpmPackage:!1};let e;if(typeof s=="string")try{e=JSON.parse(s)}catch{return{isPackage:!1,isVsCodeExtension:!1,isNpmPackage:!1}}else if(typeof s=="object")e=s;else return{isPackage:!1,isVsCodeExtension:!1,isNpmPackage:!1};let t=typeof e.name=="string"?e.name.trim():void 0,n=typeof e.publisher=="string"?e.publisher.trim():void 0,r=typeof e.version=="string"?e.version.trim():void 0,i=e.engines&&typeof e.engines=="object"?e.engines:void 0,o=!!(i&&typeof i.vscode=="string"),a=!!t,u=!!(e.workspaces&&(Array.isArray(e.workspaces)||typeof e.workspaces=="object"&&Array.isArray(e.workspaces.packages))),c;return o&&(n&&t?c=`${n}.${t}`:t&&(c=t)),{isPackage:a||o,isVsCodeExtension:o,isNpmPackage:a,...u?{isMonorepo:!0}:{},...e.private?{isPrivate:!0}:{},packageName:t,vscodeExtensionId:c,publisher:n,version:r}},_=s=>{if(!Array.isArray(s)||s.length===0)return{isMonorepo:!1,totalPackages:0,npmPackages:[],vscodeExtensions:[],all:[]};let e=[],t=[],n=[],r=!1;for(let o of s){let a=l(o);a.isMonorepo&&(r=!0),a.isPackage&&(e.push(a),a.isVsCodeExtension&&n.push(a),a.isNpmPackage&&t.push(a))}return{isMonorepo:r||e.length>1,totalPackages:e.length,npmPackages:t,vscodeExtensions:n,all:e}},M=s=>{let e=s.trim();if(e.startsWith("{")&&e.endsWith("}")){let t=l(e);if(t.isVsCodeExtension&&t.vscodeExtensionId)return{platform:"vscode",type:"package",name:t.vscodeExtensionId,rawInput:e};if(t.isNpmPackage&&t.packageName)return{platform:"npm",type:"package",name:t.packageName,rawInput:e}}if(e.startsWith("npm:pkg:"))return{platform:"npm",type:"package",name:e.slice(8),rawInput:e};if(e.startsWith("npm:")){let t=e.slice(4);return t.startsWith("~")?{platform:"npm",type:"user",name:t.slice(1),rawInput:e}:{platform:"npm",type:"package",name:t,rawInput:e}}if(e.startsWith("~"))return{platform:"npm",type:"user",name:e.slice(1),rawInput:e};if(e.startsWith("so:")||e.startsWith("stackoverflow:")){let t=e.startsWith("so:")?3:14;return{platform:"stackoverflow",type:"user",profileId:e.slice(t),rawInput:e}}if(e.startsWith("org:")||e.startsWith("github:org:")){let t=e.startsWith("org:")?4:11;return{platform:"github",type:"org",owner:e.slice(t),rawInput:e}}if(e.startsWith("user:")||e.startsWith("github:user:")){let t=e.startsWith("user:")?5:12;return{platform:"github",type:"user",owner:e.slice(t),rawInput:e}}if(e.startsWith("github:repo:")){let t=e.slice(12).split("/");return{platform:"github",type:"repo",owner:t[0]||"",repo:t[1]||"",rawInput:e}}if(e.startsWith("github:")){let t=e.slice(7).split("/");return t.length>=2?{platform:"github",type:"repo",owner:t[0],repo:t[1],rawInput:e}:{platform:"github",type:"unknown",owner:t[0],rawInput:e}}if(e.startsWith("vscode:")){let t=e.slice(7).split("/");return{platform:"vscode",type:t.length>=2?"package":"user",name:t.join("."),rawInput:e}}if(e.startsWith("medium:"))return{platform:"medium",type:"user",profileId:e.slice(7),rawInput:e};if(e.startsWith("leetcode:"))return{platform:"leetcode",type:"user",profileId:e.slice(9),rawInput:e};try{let t=new URL(e.match(/^https?:\/\//i)?e:`https://${e}`),n=t.hostname.toLowerCase();if(n.includes("github.com")){let r=t.pathname.split("/").filter(Boolean);if(r[0]==="organizations"||r[0]==="orgs")return{platform:"github",type:"org",owner:r[1]||"",rawInput:e};if(r.length===1)return{platform:"github",type:"unknown",owner:r[0],rawInput:e};if(r.length>=2)return{platform:"github",type:"repo",owner:r[0],repo:r[1],rawInput:e}}if(n.includes("npmjs.com")){let r=t.pathname.split("/").filter(Boolean);if(r[0]==="package")return{platform:"npm",type:"package",name:r.slice(1).join("/"),rawInput:e};if(r[0].startsWith("~"))return{platform:"npm",type:"user",name:r[0].slice(1),rawInput:e};if(r[0].startsWith("@"))return r.length===1?{platform:"npm",type:"org",name:r[0],rawInput:e}:{platform:"npm",type:"package",name:`${r[0]}/${r[1]}`,rawInput:e}}if(n.includes("stackoverflow.com")){let r=t.pathname.split("/").filter(Boolean);if(r[0]==="users"&&r[1])return{platform:"stackoverflow",type:"user",profileId:r[1],name:r[2]||void 0,rawInput:e}}if(n.includes("medium.com")){let r=t.pathname.split("/").filter(Boolean),i=r[0]?.startsWith("@")?r[0].slice(1):r[0];if(i)return{platform:"medium",type:"user",profileId:i,rawInput:e}}}catch{}if(e.startsWith("organizations/")||e.startsWith("orgs/"))return{platform:"github",type:"org",owner:e.split("/")[1]||"",rawInput:e};if(e.startsWith("@")&&e.includes("/"))return{platform:"npm",type:"package",name:e,rawInput:e};if(e.includes("/")){let t=e.split("/");return{platform:"github",type:"repo",owner:t[0],repo:t[1],rawInput:e}}return{platform:"github",type:"unknown",owner:e,rawInput:e}};export{M as detectInput,l as detectManifest,_ as detectManifests};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ossintel/input-parser",
3
3
  "author": "Mayank Kumar Chaudhari <https://mayankchaudhari.com>",
4
4
  "private": false,
5
- "version": "0.2.1",
5
+ "version": "0.3.0",
6
6
  "description": "Lightweight and extensible input query parser for resolving developer, repository, organization, and package paths across multiple ecosystems (GitHub, NPM, StackOverflow, VS Code).",
7
7
  "license": "MIT",
8
8
  "main": "./dist/index.js",