All Projects → GoogleChromeLabs → Native Url

GoogleChromeLabs / Native Url

Licence: apache-2.0
Node's url module implemented using the built-in URL API.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Native Url

postcss-inline-base64
PostCSS plugin used to replace value inside of url function to base64
Stars: ✭ 23 (-91.64%)
Mutual labels:  url
Netswift
A type-safe, high-level networking solution for Swift apps
Stars: ✭ 21 (-92.36%)
Mutual labels:  url
Parse Domain
Splits a hostname into subdomains, domain and (effective) top-level domains.
Stars: ✭ 261 (-5.09%)
Mutual labels:  url
anikimiapi
A Simple, LightWeight, Statically-Typed Python3 API wrapper for GogoAnime.
Stars: ✭ 15 (-94.55%)
Mutual labels:  url
cpplipa
C++ library package
Stars: ✭ 17 (-93.82%)
Mutual labels:  url
ngx-linkifyjs
Angular V8 wrapper for linkifyjs - library for finding links in plain text and converting them to HTML <a> tags via linkifyjs
Stars: ✭ 40 (-85.45%)
Mutual labels:  url
doi2bib
📝 Easily convert Digital Object Identifier (DOI) and Uniform Resource Locator (URL) to BibTeX and DOI to plain text.
Stars: ✭ 28 (-89.82%)
Mutual labels:  url
Django Multiurl
Have you ever wanted multiple views to match to the same URL? Now you can.
Stars: ✭ 268 (-2.55%)
Mutual labels:  url
requrl
Grab full URL from request.
Stars: ✭ 17 (-93.82%)
Mutual labels:  url
Uri
🌏 Functions for making sense out of URIs in PHP
Stars: ✭ 259 (-5.82%)
Mutual labels:  url
uri-parse-lib
Library for parse URI
Stars: ✭ 24 (-91.27%)
Mutual labels:  url
urley
📦 An easy cross-platform utility library to work with URLs in Javascript.
Stars: ✭ 14 (-94.91%)
Mutual labels:  url
custom-permalinks
Set custom permalinks on a per-post basis in WordPress
Stars: ✭ 17 (-93.82%)
Mutual labels:  url
node-parameterize
parameterize.js
Stars: ✭ 36 (-86.91%)
Mutual labels:  url
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (-4.36%)
Mutual labels:  url
Slugify
Simple Slug / Clean URL generator helper for Microsoft .NET framework / .NET Standard.
Stars: ✭ 53 (-80.73%)
Mutual labels:  url
tall
Promise-based, No-dependency URL unshortner (expander) module for Node.js
Stars: ✭ 56 (-79.64%)
Mutual labels:  url
Url Signer
Create and validate signed URLs with a limited lifetime
Stars: ✭ 273 (-0.73%)
Mutual labels:  url
Ffrouter
Powerful and easy-to-use URL routing library in iOS that supports URL Rewrite(强大、易用、支持 URL Rewrite的 iOS 路由库)
Stars: ✭ 263 (-4.36%)
Mutual labels:  url
UnChain
A tool to find redirection chains in multiple URLs
Stars: ✭ 77 (-72%)
Mutual labels:  url

native-url npm package version bundle size github license

A lightweight implementation of Node's url interface atop the URL API. Use it instead of the url module to reduce your bundle size by around 7.5 kB.

Weighs 1.6 kB gzipped, works in Node.js 7+ and all modern browsers:

Chrome 32, Firefox 19, Safari 7, Edge 12, Opera 19

Older browsers can be easily polyfilled without new browsers loading the code.

Installation

npm i native-url

Usage

const url = require('native-url');

url.parse('https://example.com').host; // example.com
url.parse('/?a=b', true).query; // { a: 'b' }

Usage with Webpack

When you use the url module, webpack bundles node-url for the browser. You can alias webpack to use native-url instead, saving around 7.5kB:

// webpack.config.js
module.exports = {
  // ...
  resolve: {
    alias: {
      url: 'native-url',
    },
  },
};

The result is functionally equivalent in Node 7+ and all modern browsers.

Usage with Rollup

Rollup does not bundle shims for Node.js modules like url by default, but we can add url support via native-url using aliases:

// rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
import alias from '@rollup/plugin-alias';

module.exports = {
  // ...
  plugins: [
    resolve(),
    alias({
      entries: {
        url: 'native-url',
      },
    }),
  ],
};

With this in place, import url from 'url' will use native-url and keep your bundle small.

API

Refer Node's legacy url documentation for detailed API documentation.

url.parse(urlStr, [parseQueryString], [slashesDenoteHost])

Parses a URL string and returns a URL object representation:

url.parse('https://example.com');
// {
//   href: 'http://example.com/',
//   protocol: 'http:',
//   slashes: true,
//   host: 'example.com',
//   hostname: 'example.com',
//   query: {},
//   search: null,
//   pathname: '/',
//   path: '/'
// }

url.parse('/foo?a=b', true).query.a; // "b"

url.format(urlObj)

Given a parsed URL object, returns its corresponding URL string representation:

url.format({ protocol: 'https', host: 'example.com' });
// "https://example.com"

url.resolve(from, to)

Resolves a target URL based on the provided base URL:

url.resolve('/a/b', 'c');
// "/a/b/c"
url.resolve('/a/b', '/c#d');
// "/c#d"

Polyfill for Older Browsers

native-url relies on the DOM URL API to work. For older browsers that don't support the URL API, a polyfill is available.

Conveniently, a polyfill is never needed for browsers that support ES Modules, so we can use <script nomodule> to conditionally load it for older browsers:

<script nomodule src="/path/to/url-polyfill.js"></script>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].