@ossintel/input-parser 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ossintel
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 all
13
+ 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 THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # @ossintel/input-parser <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>
2
+
3
+ <p className="flex gap-2">
4
+ <a href="https://github.com/ossintel/ossintel/actions/workflows/ci.yml" rel="noopener noreferrer">
5
+ <img alt="CI" src="https://github.com/ossintel/ossintel/actions/workflows/ci.yml/badge.svg" />
6
+ </a>
7
+ <a href="https://codecov.io/gh/ossintel/ossintel/tree/main/packages/@ossintel/input-parser" rel="noopener noreferrer">
8
+ <img alt="codecov" src="https://codecov.io/gh/ossintel/ossintel/graph/badge.svg?flag=@ossintel/input-parser" />
9
+ </a>
10
+ <a href="https://npmjs.com/package/@ossintel/input-parser" rel="noopener noreferrer">
11
+ <img alt="npm version" src="https://img.shields.io/npm/v/@ossintel/input-parser" />
12
+ </a>
13
+ <a href="https://npmjs.com/package/@ossintel/input-parser" rel="noopener noreferrer">
14
+ <img alt="npm downloads" src="https://img.shields.io/npm/d18m/@ossintel/input-parser" />
15
+ </a>
16
+ <a href="https://npmjs.com/package/@ossintel/input-parser" rel="noopener noreferrer">
17
+ <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@ossintel/input-parser" />
18
+ </a>
19
+ <img alt="license" src="https://img.shields.io/npm/l/@ossintel/input-parser" />
20
+ </p>
21
+
22
+ > @ossintel/input-parser: Lightweight and extensible input query parser for resolving developer, repository, organization, and package paths across multiple ecosystems (GitHub, NPM, StackOverflow, VS Code).
23
+
24
+ ---
25
+
26
+ ## ✨ Why @ossintel/input-parser?
27
+
28
+ - **Ecosystem Agnostic**: Parses query strings, profiles, and URLs across GitHub, NPM, StackOverflow, VS Code, Medium, and LeetCode.
29
+ - **URL Auto-Healing**: Extracts platform, owner, repo, package name, or user IDs directly from browser copy-pasted URLs.
30
+ - **Prefix Shortcuts**: Handles intuitive prefix syntax (e.g. `org:react18-tools`, `npm:~isaacs`, `so:12345`).
31
+ - **Fully Typed & Lightweight**: Zero external dependencies, compiling to highly optimized, type-safe ESM/CJS bundles.
32
+
33
+ ---
34
+
35
+ ## 🚀 Usage
36
+
37
+ ```typescript
38
+ import { detectInput } from "@ossintel/input-parser";
39
+
40
+ // Parse a repository URL
41
+ const repo = detectInput("https://github.com/react18-tools/kosha");
42
+ // => { platform: "github", type: "repo", owner: "react18-tools", repo: "kosha", rawInput: "..." }
43
+
44
+ // Parse a GitHub Organization prefix
45
+ const org = detectInput("org:react18-tools");
46
+ // => { platform: "github", type: "org", owner: "react18-tools", rawInput: "..." }
47
+
48
+ // Parse an NPM user shortcut
49
+ const npmUser = detectInput("npm:~mayank1513");
50
+ // => { platform: "npm", type: "user", name: "mayank1513", rawInput: "..." }
51
+ ```
52
+
53
+ ---
54
+
55
+ ## 📦 Installation
56
+
57
+ ```bash
58
+ $ pnpm add @ossintel/input-parser
59
+ ```
60
+
61
+ **_or_**
62
+
63
+ ```bash
64
+ $ npm install @ossintel/input-parser
65
+ ```
66
+
67
+ **_or_**
68
+
69
+ ```bash
70
+ $ yarn add @ossintel/input-parser
71
+ ```
72
+
73
+
74
+ ## License
75
+
76
+ This library is licensed under the MIT open-source license.
77
+
78
+ <hr />
79
+
80
+ <p align="center">with 💖 by <a href="https://mayankchaudhari.com" target="_blank">Mayank Kumar Chaudhari</a></p>
@@ -0,0 +1,52 @@
1
+ interface InputDetectionResult {
2
+ /**
3
+ * Target platform: "github" | "npm" | "stackoverflow" | "vscode" | "medium" | "leetcode" | "unknown"
4
+ */
5
+ platform: "github" | "npm" | "stackoverflow" | "vscode" | "medium" | "leetcode" | "unknown";
6
+ /**
7
+ * Target type: "user" | "org" | "repo" | "package" | "unknown"
8
+ */
9
+ type: "user" | "org" | "repo" | "package" | "unknown";
10
+ /**
11
+ * GitHub owner/username or organization login
12
+ */
13
+ owner?: string;
14
+ /**
15
+ * GitHub repository name
16
+ */
17
+ repo?: string;
18
+ /**
19
+ * NPM package or user name
20
+ */
21
+ name?: string;
22
+ /**
23
+ * StackOverflow user profile ID
24
+ */
25
+ profileId?: string;
26
+ /**
27
+ * Raw input search query
28
+ */
29
+ rawInput: string;
30
+ }
31
+ /**
32
+ * Parses and resolves search query strings into platform and type targets.
33
+ * Supporting URLs, prefixes, and fallback shorthands.
34
+ *
35
+ * @param input - The raw search query entered by the user
36
+ * @returns An object containing the platform, target type, parsed identifiers, and the raw input.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * detectInput("react18-tools/kosha")
41
+ * // => { platform: "github", type: "repo", owner: "react18-tools", repo: "kosha", rawInput: "react18-tools/kosha" }
42
+ *
43
+ * detectInput("org:react18-tools")
44
+ * // => { platform: "github", type: "org", owner: "react18-tools", rawInput: "org:react18-tools" }
45
+ *
46
+ * detectInput("npm:kosha")
47
+ * // => { platform: "npm", type: "package", name: "kosha", rawInput: "npm:kosha" }
48
+ * ```
49
+ */
50
+ declare function detectInput(input: string): InputDetectionResult;
51
+
52
+ export { type InputDetectionResult, detectInput };
@@ -0,0 +1,52 @@
1
+ interface InputDetectionResult {
2
+ /**
3
+ * Target platform: "github" | "npm" | "stackoverflow" | "vscode" | "medium" | "leetcode" | "unknown"
4
+ */
5
+ platform: "github" | "npm" | "stackoverflow" | "vscode" | "medium" | "leetcode" | "unknown";
6
+ /**
7
+ * Target type: "user" | "org" | "repo" | "package" | "unknown"
8
+ */
9
+ type: "user" | "org" | "repo" | "package" | "unknown";
10
+ /**
11
+ * GitHub owner/username or organization login
12
+ */
13
+ owner?: string;
14
+ /**
15
+ * GitHub repository name
16
+ */
17
+ repo?: string;
18
+ /**
19
+ * NPM package or user name
20
+ */
21
+ name?: string;
22
+ /**
23
+ * StackOverflow user profile ID
24
+ */
25
+ profileId?: string;
26
+ /**
27
+ * Raw input search query
28
+ */
29
+ rawInput: string;
30
+ }
31
+ /**
32
+ * Parses and resolves search query strings into platform and type targets.
33
+ * Supporting URLs, prefixes, and fallback shorthands.
34
+ *
35
+ * @param input - The raw search query entered by the user
36
+ * @returns An object containing the platform, target type, parsed identifiers, and the raw input.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * detectInput("react18-tools/kosha")
41
+ * // => { platform: "github", type: "repo", owner: "react18-tools", repo: "kosha", rawInput: "react18-tools/kosha" }
42
+ *
43
+ * detectInput("org:react18-tools")
44
+ * // => { platform: "github", type: "org", owner: "react18-tools", rawInput: "org:react18-tools" }
45
+ *
46
+ * detectInput("npm:kosha")
47
+ * // => { platform: "npm", type: "package", name: "kosha", rawInput: "npm:kosha" }
48
+ * ```
49
+ */
50
+ declare function detectInput(input: string): InputDetectionResult;
51
+
52
+ export { type InputDetectionResult, detectInput };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var l=(n,t)=>{for(var r in t)s(n,r,{get:t[r],enumerable:!0})},f=(n,t,r,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of o(t))!u.call(n,e)&&e!==r&&s(n,e,{get:()=>t[e],enumerable:!(p=i(t,e))||p.enumerable});return n};var m=n=>f(s({},"__esModule",{value:!0}),n);var h={};l(h,{detectInput:()=>c});module.exports=m(h);function c(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),a=e[0]?.startsWith("@")?e[0].slice(1):e[0];if(a)return{platform:"medium",type:"user",profileId:a,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});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ function a(s){let t=s.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),p=e[0]?.startsWith("@")?e[0].slice(1):e[0];if(p)return{platform:"medium",type:"user",profileId:p,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{a as detectInput};
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@ossintel/input-parser",
3
+ "author": "Mayank Kumar Chaudhari <https://mayankchaudhari.com>",
4
+ "private": false,
5
+ "version": "0.1.0",
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
+ "license": "MIT",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.mts",
15
+ "default": "./dist/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/ossintel/ossintel",
27
+ "directory": "packages/input-parser"
28
+ },
29
+ "bugs": "https://github.com/ossintel/ossintel/issues",
30
+ "homepage": "https://github.com/ossintel/ossintel/blob/main/packages/input-parser/README.md",
31
+ "sideEffects": false,
32
+ "files": [
33
+ "dist/**"
34
+ ],
35
+ "devDependencies": {
36
+ "@types/node": "latest",
37
+ "tsup": "latest",
38
+ "typescript": "latest"
39
+ },
40
+ "forge": {
41
+ "aliases": [],
42
+ "icon": "LibraryBig",
43
+ "description": "Extensible input query parser"
44
+ },
45
+ "funding": [
46
+ {
47
+ "type": "github",
48
+ "url": "https://github.com/sponsors/ossintel"
49
+ },
50
+ {
51
+ "type": "github",
52
+ "url": "https://github.com/sponsors/mayank1513"
53
+ }
54
+ ],
55
+ "keywords": [
56
+ "ossintel",
57
+ "parser",
58
+ "input-detection",
59
+ "github",
60
+ "npm",
61
+ "stackoverflow",
62
+ "vscode",
63
+ "monorepo"
64
+ ],
65
+ "scripts": {
66
+ "build": "tsup && gzip -c dist/index.js | wc -c",
67
+ "clean": "rm -rf dist",
68
+ "dev": "tsup --watch"
69
+ }
70
+ }