https://github.com/heineiuo/text-parser-url
:link: text parser for url
https://github.com/heineiuo/text-parser-url
text-parser
Last synced: about 2 months ago
JSON representation
:link: text parser for url
- Host: GitHub
- URL: https://github.com/heineiuo/text-parser-url
- Owner: heineiuo
- Created: 2017-12-20T09:43:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-21T05:33:00.000Z (about 8 years ago)
- Last Synced: 2025-02-19T13:18:39.081Z (12 months ago)
- Topics: text-parser
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# text-parser-url
text parser to parse url
---
## Install
```bash
npm i text-parser-url
```
## quick start
```javascript
const textParserUrl = require('text-parser-url')
const result = textParserUrl('project address: https://github.com/heineiuo/text-parser-url, author: https://github.com/heineiuo enjoy it!')
// =>
// [
// { type: 'raw', value: 'project address: ' },
// { type: 'url', value: 'https://github.com/heineiuo/text-parser-url' },
// { type: 'raw', value: ', author: ' },
// { type: 'url', value: 'https://github.com/heineiuo' },
// { type: 'raw', value: ' enjoy it!' }
// ]
```
## Options
1. `onToken`
```javascript
const textParserUrl = require('text-parser-url')
let len = 0
const result = textParserUrl('project address: https://github.com/heineiuo/text-parser-url, author: https://github.com/heineiuo enjoy it!', {
onToken: token => {
token.len = len
len += token.value.length
return token
}
})
// =>
// [
// { type: 'raw', value: 'project address: ', len: 0 },
// { type: 'url', value: 'https://github.com/heineiuo/text-parser-url', len: 17 },
// { type: 'raw', value: ', author: ', len: 60 },
// { type: 'url', value: 'https://github.com/heineiuo', len: 70 },
// { type: 'raw', value: ' enjoy it!', len: 97 }
// ]
```
2. `requireProtocol`
```javascript
const textParserUrl = require('text-parser-url')
textParserUrl('www.github.com', {
requireProtocol: true
})
// =>
// [
// { type: 'raw', value: 'www.github.com' },
// ]
textParserUrl('www.github.com', {
requireProtocol: false
})
// =>
// [
// { type: 'url', value: 'www.github.com' },
// ]
```
3. `regex`
custom url regex. requireProtocol will be disabled
## License
MIT