social-profile-url-parser 0.1.1 → 2.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 +110 -29
- package/data/properties.json +58145 -0
- package/lib/index.js +71 -155
- package/lib/removeEmpty.js +29 -0
- package/package.json +26 -33
- package/README.hbs +0 -18
- package/lib/index.d.ts +0 -47
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,29 +1,110 @@
|
|
|
1
|
-
# Social Profile URL Parser
|
|
2
|
-
|
|
3
|
-
The `Social Profile URL Parser` is a Node.js library that allows you to extract social media profile URLs from a block of text. It is useful for situations where you have a large amount of text that contains multiple social media profile links and you want to extract and organize them in a structured way.
|
|
4
|
-
|
|
5
|
-
To use the library, you can simply pass in a string of text and the library will return an array of objects containing the social media platform name, profile URL, and username for each link found. You can also specify which platforms you want to extract links for by passing in an array of platform names.
|
|
6
|
-
|
|
7
|
-
The library supports a wide range of popular social media platforms, including Facebook, Twitter, Instagram, LinkedIn, and more. It is easy to use and can save you a lot of time and effort when working with large amounts of text containing social media profile links.
|
|
8
|
-
|
|
9
|
-
## Support the project
|
|
10
|
-
|
|
11
|
-
There are many ways you can contribute to the development and improvement of the Social Profile URL Parser library. One way is by submitting code changes and bug fixes through pull requests.
|
|
12
|
-
Your pull request will be reviewed by the project maintainers and, if accepted, will be merged into the main codebase.
|
|
13
|
-
|
|
14
|
-
Another way you can support the project is by providing feedback and suggestions. You can do this by opening an issue in the repository and describing your suggestion or problem. This allows the maintainers to track and address your feedback in a structured way.
|
|
15
|
-
|
|
16
|
-
## Documentation
|
|
17
|
-
|
|
18
|
-
<a name="parser"></a>
|
|
19
|
-
|
|
20
|
-
## parser(inputText) ⇒ <code>Array.<ParseResult></code>
|
|
21
|
-
**Kind**: global function
|
|
22
|
-
**Returns**: <code>Array.<ParseResult></code> - an array with all the found social links
|
|
23
|
-
|
|
24
|
-
| Param | Type | Description |
|
|
25
|
-
| --- | --- | --- |
|
|
26
|
-
| inputText | <code>string</code> | the input text that will be parsed. |
|
|
27
|
-
|
|
28
|
-
**Example**
|
|
29
|
-
```js
|
|
30
1
|
slack facebook https://www.facebook.com/slackhq/
|
|
31
2
|
SlackHQ twitter https://twitter.com/SlackHQ
|
|
32
3
|
{
|
|
33
4
|
type: 'facebook',
|
|
34
5
|
name: 'Facebook',
|
|
35
6
|
username: 'slack',
|
|
36
7
|
url: 'https://www.facebook.com/slackhq/'
|
|
37
8
|
},
|
|
38
9
|
{
|
|
39
10
|
type: 'twitter',
|
|
40
11
|
name: 'Twitter',
|
|
41
12
|
username: 'SlackHQ',
|
|
42
13
|
url: 'https://twitter.com/SlackHQ'
|
|
43
14
|
}
|
|
15
|
+
# Social Profile URL Parser
|
|
16
|
+
|
|
17
|
+
`social-profile-url-parser` extracts social profile URLs and usernames from plain text.
|
|
18
|
+
|
|
19
|
+
It works in both Node.js and browser environments, has no runtime dependencies, and ships with regex patterns sourced from Wikidata.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install social-profile-url-parser
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage (Node.js)
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { parser } from "social-profile-url-parser";
|
|
31
|
+
|
|
32
|
+
const text =
|
|
33
|
+
"Find me at https://twitter.com/jack and https://github.com/octocat";
|
|
34
|
+
const results = parser(text);
|
|
35
|
+
|
|
36
|
+
console.log(results);
|
|
37
|
+
// [
|
|
38
|
+
// {
|
|
39
|
+
// type: 'P2002',
|
|
40
|
+
// name: 'X username',
|
|
41
|
+
// url: 'https://twitter.com/jack',
|
|
42
|
+
// username: 'jack'
|
|
43
|
+
// },
|
|
44
|
+
// ...
|
|
45
|
+
// ]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage (Browser, no bundler)
|
|
49
|
+
|
|
50
|
+
You can use an ESM CDN to run this package directly in the browser.
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<script type="module">
|
|
54
|
+
import { parser } from "https://esm.sh/social-profile-url-parser";
|
|
55
|
+
|
|
56
|
+
const text = "https://www.instagram.com/zuck/";
|
|
57
|
+
console.log(parser(text));
|
|
58
|
+
</script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Data source: Wikidata regex patterns
|
|
62
|
+
|
|
63
|
+
The URL regex patterns are collected from Wikidata property `P8966` (URL match pattern) and stored in `data/properties.json`.
|
|
64
|
+
|
|
65
|
+
This library intentionally does **not** maintain custom regex fixes in code. If a pattern is wrong, the long-term fix should happen on Wikidata.
|
|
66
|
+
|
|
67
|
+
## Missing URL or incorrect match
|
|
68
|
+
|
|
69
|
+
If a URL is not detected or is detected incorrectly:
|
|
70
|
+
|
|
71
|
+
1. Open an issue in this repository with an example URL.
|
|
72
|
+
2. Optionally (and preferred), fix the pattern on Wikidata first.
|
|
73
|
+
3. Then open/update the GitHub issue so we can refresh `data/properties.json` and publish the update.
|
|
74
|
+
|
|
75
|
+
This keeps fixes upstream so everyone using Wikidata-backed tooling benefits.
|
|
76
|
+
|
|
77
|
+
## Exports
|
|
78
|
+
|
|
79
|
+
- `parser(inputText: string): ParseResult[]` — parse social profile URLs from text.
|
|
80
|
+
- `regexes: RegexDefinition[]` — compiled regex definitions loaded from `data/properties.json`.
|
|
81
|
+
|
|
82
|
+
## Support the project
|
|
83
|
+
|
|
84
|
+
Issues and pull requests are welcome. For URL matching problems, please include concrete examples and preferably a Wikidata reference/update link.
|
|
85
|
+
|
|
86
|
+
## API
|
|
87
|
+
|
|
88
|
+
### `parser(inputText: string): ParseResult[]`
|
|
89
|
+
|
|
90
|
+
Parses a string and returns all recognized social profile matches.
|
|
91
|
+
|
|
92
|
+
- Matches are deduplicated by `type + username`.
|
|
93
|
+
- `username` is extracted from capture groups in the Wikidata regex pattern.
|
|
94
|
+
- If a pattern has no capture groups, the full matched URL is returned as `username`.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
type ParseResult = {
|
|
98
|
+
type: string;
|
|
99
|
+
name: string;
|
|
100
|
+
url: string;
|
|
101
|
+
username: string;
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
import { parser } from "social-profile-url-parser";
|
|
109
|
+
|
|
110
|
+
const result = parser("See https://twitter.com/jack for details");
|
|
111
|
+
// [{ type: 'P2002', name: 'X username', url: 'https://twitter.com/jack', username: 'jack' }]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `regexes: RegexDefinition[]`
|
|
115
|
+
|
|
116
|
+
Compiled regex definitions loaded from `data/properties.json`.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
type RegexDefinition = {
|
|
120
|
+
type: string;
|
|
121
|
+
name: string;
|
|
122
|
+
regex: RegExp;
|
|
123
|
+
};
|
|
124
|
+
```
|