Skip to content

heineiuo/text-parser-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

text-parser-url

text parser to parse url


Install

npm i text-parser-url

quick start

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
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 }  // ]
  1. requireProtocol
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' }, // ]
  1. regex custom url regex. requireProtocol will be disabled

License

MIT

About

🔗 text parser for url

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published