Skip to content
/ unuri Public
generated from antfu/starter-ts

Typescript library for managing URIs, ensuring they meet RFC 3986 standards. Features include parsing, validating, and normalizing URIs, with support for custom schemes.

License

Notifications You must be signed in to change notification settings

zamanapp/unuri

Repository files navigation

unuri

npm version npm downloads bundle JSDocs

An RFC 3986 compliant, scheme extendable URI parsing, serializing and resolving library for both node and the browser.

This project is a based of uri-js and aims to modernize it and extend it with new schemas/features.

The project is meant to be used by Zamical to parse and validate URIs in compliance with the ICalendar specifications in RFC 5545

Features

  • Compliant with the following RFCs:
    • RFC 3986 Uniform Resource Identifier (URI): Generic Syntax
    • RFC 3987 Internationalized Resource Identifiers (IRIs)
    • RFC 5890 Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework
    • RFC 5952 A Recommendation for IPv6 Address Text Representation
    • RFC 6874 Representing IPv6 Zone Identifiers in Address Literals and Uniform Resource Identifiers (URIs)
  • Supports the following schemes:
  • Scheme extendable
  • Resolve
  • Parse
  • Serialize
  • Normalize

Install

npm install unuri

Usage

Import

import * URI from 'unuri';
import { parse, serialize, resolve, resolveComponents, normalize, equal, removeDotSegments, pctEncChar, pctDecChars, escapeComponent, unescapeComponent } from "unuri";

Parse

const uri = URI.parse('uri://user:[email protected]:123/one/two.three?q1=a1&q2=a2#body');
console.log({ uri }); // scheme: 'uri', userinfo: 'user:pass', host: 'example.com', port: 123, path: '/one/two.three', query: 'q1=a1&q2=a2', fragment: 'body', reference: 'uri' }

Resolve

const base = 'uri://a/b/c/d;p?q';
const uri = URI.resolve(base, '../../g'); // uri://a/g

Serialize

const toSerialize = {
  scheme: 'uri',
  userinfo: 'foo:bar',
  host: 'example.com',
  port: 1,
  path: 'path',
  query: 'query',
  fragment: 'fragment',
}
uri.serialize(toSerialize); // uri://foo:[email protected]:1/path?query#fragment

Normalize

URI.normalize('//192.068.001.000'); // //192.68.1.0

Extend

TODO

Roadmap

The following feature will be added in the future. Any help is appreciated.

  • port all tets to Vitest
  • refactor the code to be more modular and possibly tree-shakeable
  • turn the URI into a class
  • make parsing as static methods
  • create schema specific classes that extend the URI class
  • create schema detector
  • add validation functions
  • add parseSecure which will throw an error if the URI invalid

The following schemas are not supported yet, but may be needed in the future. Any help is appreciated.

  • Add support for ftp scheme
  • Add support for file scheme
  • Add support for data scheme
  • Add support for tel scheme

License

Original Work License

The original work in this project is licensed under the following license:

Copyright 2011 Gary Court. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1.	Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2.	Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY GARY COURT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Gary Court.

Modifications License

The modifications made to this project are licensed under the MIT License, as follows:

Modifications Copyright Notice and MIT License

Copyright (c) (2023) WhiteRock. All rights reserved. <https://github.com/whiterocktech>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

When using or redistributing this project, you may choose to follow either the BSD License for the original work or the MIT License for the subsequent modifications, in compliance with the terms set forth in each license.

About

Typescript library for managing URIs, ensuring they meet RFC 3986 standards. Features include parsing, validating, and normalizing URIs, with support for custom schemes.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published