igrecent-profile-name 0.0.0-stage → 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.
- package/README.md +14 -2
- package/index.js +16 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# igrecent-profile-name
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Extract a lowercase username from a handle or an Instagram profile link. Runs locally without making network requests. For public Instagram profile lookup on the web, visit [IGRecent](https://www.igrecent.com/).
|
|
4
|
+
|
|
5
|
+
Install with `npm install igrecent-profile-name`.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { profileName } from 'igrecent-profile-name'
|
|
9
|
+
|
|
10
|
+
profileName('https://www.instagram.com/Example/?hl=en') // 'example'
|
|
11
|
+
profileName('@Example') // 'example'
|
|
12
|
+
profileName('https://www.instagram.com/p/abc/') // null
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Returns null for unsupported inputs. A parsed username does not establish that the account exists.
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const reserved = new Set(['p', 'reel', 'reels', 'stories', 'accounts', 'direct', 'explore', 'tv', 'about', 'developer', 'legal', 'privacy', 'terms', 'web'])
|
|
2
|
+
|
|
3
|
+
export function profileName(input) {
|
|
4
|
+
if (typeof input !== 'string') return null
|
|
5
|
+
let value = input.trim()
|
|
6
|
+
if (/^https?:\/\//i.test(value)) {
|
|
7
|
+
let url
|
|
8
|
+
try { url = new URL(value) } catch { return null }
|
|
9
|
+
if (!['instagram.com', 'www.instagram.com'].includes(url.hostname)) return null
|
|
10
|
+
value = url.pathname.replace(/^\//, '').replace(/\/$/, '')
|
|
11
|
+
if (reserved.has(value.toLowerCase())) return null
|
|
12
|
+
} else {
|
|
13
|
+
value = value.replace(/^@/, '')
|
|
14
|
+
}
|
|
15
|
+
return /^[a-z0-9._]{1,30}$/i.test(value) ? value.toLowerCase() : null
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igrecent-profile-name",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Extract a username from an Instagram profile URL or handle.",
|
|
5
|
+
"homepage": "https://www.igrecent.com/",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": "./index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js"
|
|
10
|
+
]
|
|
11
|
+
}
|