An advanced url parser supporting git urls too.
For low-level path parsing, check out parse-path
. This very module is designed to parse urls. By default the urls are normalized.
# Using npm
npm install --save parse-url
# Using yarn
yarn add parse-url
// Dependencies
import parseUrl from "../lib/index.js";
console.log(parseUrl("http://ionicabizau.net/blog"))
// {
// protocols: [ 'http' ],
// protocol: 'http',
// port: '',
// resource: 'ionicabizau.net',
// user: '',
// password: '',
// pathname: '/blog',
// hash: '',
// search: '',
// href: 'http://ionicabizau.net/blog',
// query: {}
// }
console.log(parseUrl("http://domain.com/path/name?foo=bar&bar=42#some-hash"))
// {
// protocols: [ 'http' ],
// protocol: 'http',
// port: '',
// resource: 'domain.com',
// user: '',
// password: '',
// pathname: '/path/name',
// hash: 'some-hash',
// search: 'foo=bar&bar=42',
// href: 'http://domain.com/path/name?foo=bar&bar=42#some-hash',
// query: { foo: 'bar', bar: '42' }
// }
// If you want to parse fancy Git urls, turn off the automatic url normalization
console.log(parseUrl("git+ssh://git@host.xz/path/name.git", false))
// {
// protocols: [ 'git', 'ssh' ],
// protocol: 'git',
// port: '',
// resource: 'host.xz',
// user: 'git',
// password: '',
// pathname: '/path/name.git',
// hash: '',
// search: '',
// href: 'git+ssh://git@host.xz/path/name.git',
// query: {}
// }
console.log(parseUrl("git@github.com:IonicaBizau/git-stats.git", false))
// {
// protocols: [ 'ssh' ],
// protocol: 'ssh',
// port: '',
// resource: 'github.com',
// user: 'git',
// password: '',
// pathname: '/IonicaBizau/git-stats.git',
// hash: '',
// search: '',
// href: 'git@github.com:IonicaBizau/git-stats.git',
// query: {}
// }
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
- For direct and quick help, you can use Codementor. 🚀
#PURE
Parses the input url.
Note: This throws if invalid urls are provided.
-
String
url
: The input url. -
Boolean|Object
normalize
: Whether to normalize the url or not. Default isfalse
. Iftrue
, the url will be normalized. If an object, it will be the options object sent tonormalize-url
.For SSH urls, normalize won't work.
- Object An object containing the following fields:
protocols
(Array): An array with the url protocols (usually it has one element).protocol
(String): The first protocol,"ssh"
(if the url is a ssh url) or"file"
.port
(null|Number): The domain port.resource
(String): The url domain (including subdomains).host
(String): The fully qualified domain name of a network host, or its IP address.user
(String): The authentication user (usually for ssh urls).pathname
(String): The url pathname.hash
(String): The url hash.search
(String): The url querystring value.href
(String): The input url.query
(Object): The url querystring, parsed as object.parse_failed
(Boolean): Whether the parsing failed or not.
([a-z_][a-z0-9_-]{0,31}) Try to match the user ([\w.-@]+) Match the host/resource (([~,.\w,-,_,/,\s]|%[0-9A-Fa-f]{2})+?(?:.git|/)?) Match the path, allowing spaces/white
Have an idea? Found a bug? See how to contribute.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like 🚀
-
—I love books! I will remember you after years if you buy me one. 😁 📖
-
—You can make one-time donations via PayPal. I'll probably buy a
coffeetea. 🍵 -
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
Bitcoin—You can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! ❤️
If you are using this library in one of your projects, add it in this list. ✨
git-up
@semantic-release/gitlab
stun
kakapo
@open-wa/wa-automate
parse-db-uri
url-local
fuge-runner
build-plugin-ssr
egg-muc-custom-loader
hologit
miguelcostero-ng2-toasty
@praella/localisationist
normalize-ssh
@foundernetes/machines
@enkeledi/react-native-week-month-date-picker
react-native-shared-gesture
@klevn/solid-router
warp-api
robots-agent
react-native-nice-learning
warp-server
xl-git-up
normalize-id
fluent.adflow.reactnativesdk-alpha
gaurav-react-native-loop
gitlab-backup-util-harduino
griffin-ui-library
framework_test_library_sixdee
khaled-salem-custom-components
bilibili2local
begg
native-kakao-login
@_nomtek/react-native-shimmer-animation
rn-adyen-dropin
rocomp
react-native-progress-arrow
react-native-reanimated-sortable-list
react-native-rom-components
react-native-test-comlibrary
react-native-ghn-ekyc
react-native-kakao-maps
react-native-klc
react-native-module-for-testing
react-native-multiplier-component
react-native-multiplier-demo
react-native-multiplier2
react-native-multiselector
react-native-payu-payment-testing
react-native-my-first-try-arun-ramya
react-native-azure-communication-services
react-native-android-video-player-view
react-native-animate-text
react-native-arunmeena1987
react-native-basic-screen
react-native-build-vesion-getter
react-native-biometric-authenticate
react-native-check-component
react-native-bleccs-components
react-native-contact-list
react-native-create-video-thumbnail
react-native-components-design
react-native-manh-test
react-native-library-testing-422522
react-native-uvc-camera-android
react-native-withframework-check
react-native-ytximkit
@hemith/react-native-tnk
@kriblet/wa-automate
@amiruldev/wajs
@lehuyaa/my-assets
@notnuzzel/crawl
@safely-project/safely-ts
@parallelnft/web3modal
@status-im/react-native-transparent-video
cli-live-tutorial
checkbox-component
@brantalikp/rn-resize
biometric-st
apaas-track
graphmilker
jrennsoh88-react-native-scroll-indicator
fmsl
@corelmax/react-native-my2c2p-sdk
pyreswap-sdk
react-native-ticker-tape
rn_unique_device_id
soajs.repositories
vrt-cli
vue-cli-plugin-ice-builder
verify-aws-sns-signature
winx-form-winx
zeo-collect
@felipesimmi/react-native-datalogic-module
@hawkingnetwork/react-native-tab-view
rn-check-btn
react-native-arunjeyam1987
react-native-basic-app
react-native-bubble-chart
react-native-awesome-module-two
react-native-cplus
react-native-dhp-printer
react-native-flyy
react-native-innity-remaster
react-native-input-library
@jprustv/sulla-hotfix
react-native-rabbitmq-all
react-native-sandycomponent
react-native-savczuk-feature-library
test-library-123
@mergulhao/wa-automate
@oiti/rn-liveness2d
@taingo97/react-native-sunmi-printer
@taingo97/react-native-telpo-printer
@podpodium/common
@react-18-pdf/root
@navabi/react-native-ssl-pinning
candlelabssdk
blitzzz
deploy-versioning
awesome-module-kd
@aysea/react-native-ui-library
@azalpacir/react-native-dhp-printer
eval-spider
generator-bootstrap-boilerplate-template
@con-test/react-native-concent-common
iprogrammer-rn-android-location-enabler
fixed_form_builder
pasbeaucoupmoinsrave
react-native-xprinter-thermal-ble
react-native-app-bubble
react-native-bridge-package
react-native-aventonfacetec-aventon
react-native-sp-test-common
react-native-ui-components-library
reat-native-multiplierkpr
sourcecrumbs
react-native-get-countries
react-native-dsphoto-module
react-native-lib-test-rn-1
react-native-native-audio-engine
react-native-onramp
react-native-nghia-sharering
react-native-recent-framework-update
react-native-radio-bic-group-lib
react-native-responsive-size
react-native-sayhello-module
react-native-screen-idle-timer
react-native-awesome-module-latest
vision-camera-base64-resized
vision-camera-plugin-scan-faces
@damruravihara/react-native-testing-package
npm_one_12_34_1_
npm_one_2_2
native-modal-damage-vehicle
genz-native-elements
gh-monoproject-cli
payutesting
@everything-registry/sub-chunk-2411
pnm-yph-react-native-custom-components
@aabelmann/ui-layer
michael-stun
@qiwi/sourcecrumbs
@taingo97/react-native-bluetooth-xprinter
@taingo97/react-native-print-xprinter
@roshub/api
@saad27/react-native-bottom-tab-tour
@apardellass/react-native-audio-stream
microbe.js
jawwy_library
luojia-cli-dev
delta-screen
@yplabs-ltd/react-native-detector
design-system-trial-milyasbpa
get-tarball-cli
fluent.adflow.reactnativesdk
ndla-source-map-resolver
birken-react-native-community-image-editor
@foundernetes/metal-debian
zzzxxxyyy321123
wifi_configuration_package
rn-session-multiplier-demo
react-native-scroll-tab-to-index
react-native-teknoctrl-components
react-native-transtracker-library
react-native-version-app
react-native-pulsator-native
react-native-plugpag-wrapper
react-native-simple-timeline
react-native-sixdee_test_lib
react-native-wtf
react-native-xiaomi-permissions
new-awesome-4321
rn-counter-demo
reac-native-arun-ramya-test
react-native-ctp-odp
react-native-conekta-card-tokenizer
react-native-omental-framework
@tomw2w/my-nuxt-layer
angularvezba
@wecraftapps/react-native-use-keyboard
astra-ufo-sdk
ba-js-cookie-banner
api-reach-react-native-fix
fawatrak-online-payment
expo-renavigate
hubot-will-it-connect
hui-plugin-wss
@buganto/client
demo-test-scrn
scout-chatbot-widget
sushi-sdk-ftm
test-zeo-collect
test-haptik-lib
react-native-badge-control
react-native-arps-authorize-net
react-native-auth-service-client
react-native-awesome-android-123-zeotap
react-native-klarify-ui
react-native-lowlatency
react-native-manual-ios-sdk
react-native-jsi-device-info
react-native-line-login-android
native-date-picker-module
raact-native-arunramya151
react-native-return-usb-data
react-native-rtn-ips-poslin-test
react-native-test-view
react-native-volume-phisical
rn-circular-chart
react-native-bluetooth-device-detect
ts-scraper
normalize-ssh-url
nuxtpaginations
native-google-login
jordy-frijters-test-lib
l2forlerna
wander-cli
@jimengio/mocked-proxy
@ndla/source-map-resolver
@amirdiafi/react-native-ios-haptics
@mockswitch/cli
@phuocnb/semrelease-gitlab
@thinxviewx/core-rn
electron-info
react-native-is7
@positionex/position-sdk
@phpboyscout/semantic-release-gitlab
@npm_fluentco/adflow-react-native-sdk
pangeling-ui
fawaterak-online-payment
@hstech/utils
workpad
@idas1/ui-component-lib
smart_one_connect
react-native-test-module-hhh
@valifysolutions/react-native-vidvliveness
rn-tm-notify