identifier-js 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -2,10 +2,11 @@
2
2
  // a valid URI is always a valid IRI
3
3
  const { recursiveCompile } = require('url-templates');
4
4
  const patterns = new Map();
5
+ const implemented_schemes = '(?:[hH][tT][tT][pP][sS]?|[wW][sS][sS]?|[fF][iI][lL][eE])';
5
6
  // RFC3986/RFC3987 common rules + https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2:~:text=DNS%29%2E-,A,of%20%5BRFC1123%5D%2E
6
7
  const commonRules = {
7
- implemented_schemes: '(?:[hH][tT][tT][pP][sS]?|[wW][sS][sS]?|[fF][iI][lL][eE]):',
8
- scheme: '(?!{implemented_schemes})[a-zA-Z][a-zA-Z0-9+.-]*',
8
+ implemented_schemes,
9
+ scheme: '(?!{implemented_schemes}:)[a-zA-Z][a-zA-Z0-9+.-]*',
9
10
  port: '(?:0|[1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])?',
10
11
  IP_literal: '\\[(?:{IPv6address}|{IPvFuture})\\]',
11
12
  IPv6address: '(?:(?:{h16}:){6}{ls32}|::(?:{h16}:){5}{ls32}|(?:(?:{h16})?)::(?:{h16}:){4}{ls32}|(?:(?:{h16}:)?{h16})?::(?:{h16}:){3}{ls32}|(?:(?:{h16}:){0,2}{h16})?::(?:{h16}:){2}{ls32}|(?:(?:{h16}:){0,3}{h16})?::(?:{h16}:){1}{ls32}|(?:(?:{h16}:){0,4}{h16})?::{ls32}|(?:(?:{h16}:){0,5}{h16})?::{h16}|(?:(?:{h16}:){0,6}{h16})?::)',
@@ -79,7 +80,7 @@ const iriRules = {
79
80
  };
80
81
  // scheme specific URI reg_name and IRI ireg_name
81
82
  const schemeSpecificRules = {
82
- scheme: '(?:https?|wss?|file)',
83
+ scheme: implemented_schemes,
83
84
  reg_name: '(?:(?=.{1,255}(?:[:/?#]|$))(?:{a_label})(?:\\.{a_label})*)',
84
85
  a_label: '(?:{alpha_digit})(?:(?:{alpha_digit}|-){0,61}(?:{alpha_digit}))?',
85
86
  ireg_name: '(?:(?=.{1,255}(?:[:/?#]|$))(?:{u_label})(?:{u_separator}(?:{u_label}))*)',
@@ -113,8 +114,8 @@ const groupNames = {
113
114
  ipath_empty: 'path',
114
115
  };
115
116
  // all rules into one map
116
- const isSpecificScheme = (string) => new RegExp('^' + schemeSpecificRules.scheme + ':').test(string);
117
- const rules = (specific) => specific ? Object.assign({}, commonRules, uriRules, iriRules, schemeSpecificRules) : Object.assign({}, commonRules, uriRules, iriRules);
117
+ const isSpecificScheme = (string) => new RegExp('^' + implemented_schemes + ':').test(string);
118
+ const rules = (specific) => (specific ? Object.assign({}, commonRules, uriRules, iriRules, schemeSpecificRules) : Object.assign({}, commonRules, uriRules, iriRules));
118
119
  // parse (slower, it uses regex.exec and includes named capture groups)
119
120
  const parse = (string, rule) => {
120
121
  if (typeof string !== 'string') throw new TypeError(`Invalid ${rule.replace('_', '-')} type: must be a string.`);
@@ -283,8 +284,9 @@ module.exports = {
283
284
  parseIri: (string) => parse(string, 'IRI'),
284
285
  parseIriReference: (string) => parse(string, 'IRI_reference'),
285
286
  parseAbsoluteIri: (string) => parse(string, 'absolute_IRI'),
286
- resolveReference, // not yet decided if the return should be normalized or not, and in what extent
287
+ resolveReference,
287
288
  normalizeReference: (string) => string, // not done yet
288
289
  toAbsoluteReference: (string) => resolveReference('', string),
289
290
  toRelativeReference,
290
291
  };
292
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identifier-js",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "A RFC3986 / RFC3987 compliant fast parser/validator/resolver/composer for NodeJS and browser.",
5
5
  "keywords": [
6
6
  "IRI",
@@ -12,10 +12,8 @@
12
12
  "uuid",
13
13
  "parser",
14
14
  "validator",
15
- "RFC",
16
- "3987",
17
- "RFC",
18
- "3986"
15
+ "RFC3986",
16
+ "RFC3987"
19
17
  ],
20
18
  "homepage": "https://github.com/SorinGFS/identifier-js#readme",
21
19
  "bugs": {
package/readme.md CHANGED
@@ -8,7 +8,14 @@ description: A RFC3986 / RFC3987 compliant fast parser/validator/resolver/compos
8
8
 
9
9
  ## Overview
10
10
 
11
- A fully RFC [3986](https://datatracker.ietf.org/doc/html/rfc3986.html)/[3897](https://datatracker.ietf.org/doc/html/rfc3987.html) compliant URI/IRI parser, validator, resolver and composer, along with other identifier utilities.
11
+ A fully RFC [3986](https://datatracker.ietf.org/doc/html/rfc3986.html)/[3897](https://datatracker.ietf.org/doc/html/rfc3987.html) compliant URI/IRI parser, validator, resolver and composer, along with other identifier utilities. This library implements the following [IANA registered](https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml) schemes:
12
+ - `http` defined by [RFC9110, Section 4.2.1](https://datatracker.ietf.org/doc/html/rfc9110#section-4.2.1)
13
+ - `https` defined by [RFC9110, Section 4.2.2](https://datatracker.ietf.org/doc/html/rfc9110#section-4.2.2)
14
+ - `ws` defined by [RFC6455, Section 3](https://datatracker.ietf.org/doc/html/rfc6455#section-3)
15
+ - `wss` defined by [RFC6455, Section 3](https://datatracker.ietf.org/doc/html/rfc6455#section-3)
16
+ - `file` defined by [RFC8089, Section 2](https://datatracker.ietf.org/doc/html/rfc8089#section-2)
17
+
18
+ Other schemes that are `IANA registered` schemes and compliant with the generic `URI` or `IRI` syntax are also supported. As for the identifiers that are not `IANA registered`, but compliant with the generic `URI` or `IRI` syntax, the preferred schemes are `uri` and respectively `iri`.
12
19
 
13
20
  ## Install
14
21
 
@@ -81,8 +88,8 @@ Resolve a reference against a base identifier:
81
88
  - resolveReference: (reference: string, base: string, strict?: boolean, returnParts?: boolean) => string
82
89
 
83
90
  **Note:**
84
- - strict enables strict resolution behavior.
85
- - returnParts returns structured components instead of a string.
91
+ - strict (default: `true`) enables strict resolution behavior.
92
+ - returnParts (default: `false`) returns structured components instead of a string.
86
93
 
87
94
  Convert a reference into absolute form:
88
95
  - toAbsoluteReference: (reference: string) => string
@@ -269,6 +269,27 @@ describe('isUri with hostnames', () => {
269
269
  test('Invalid - = character (sub-delims) in file reg_name', () => {
270
270
  expect(() => id.isUri('file://exa=mple')).to.throw(Error, 'Invalid URI: file://exa=mple');
271
271
  });
272
+
273
+ test('Valid case insensitive http scheme', () => {
274
+ expect(id.isUri('httP://example')).to.equal(true);
275
+ });
276
+
277
+ test('Valid case insensitive https scheme', () => {
278
+ expect(id.isUri('httPs://example')).to.equal(true);
279
+ });
280
+
281
+ test('Valid case insensitive ws scheme', () => {
282
+ expect(id.isUri('WS://example')).to.equal(true);
283
+ });
284
+
285
+ test('Valid case insensitive wss scheme', () => {
286
+ expect(id.isUri('WSs://example')).to.equal(true);
287
+ });
288
+
289
+ test('Valid case insensitive file scheme', () => {
290
+ expect(id.isUri('fILE://example')).to.equal(true);
291
+ });
292
+
272
293
  });
273
294
 
274
295
  describe('isIri with hostnames', () => {
@@ -551,4 +572,25 @@ describe('isIri with hostnames', () => {
551
572
  test('Invalid - = character (sub-delims) in file reg_name', () => {
552
573
  expect(() => id.isIri('file://exa=mple')).to.throw(Error, 'Invalid IRI: file://exa=mple');
553
574
  });
575
+
576
+ test('Valid case insensitive http scheme', () => {
577
+ expect(id.isIri('httP://example')).to.equal(true);
578
+ });
579
+
580
+ test('Valid case insensitive https scheme', () => {
581
+ expect(id.isIri('httPs://example')).to.equal(true);
582
+ });
583
+
584
+ test('Valid case insensitive ws scheme', () => {
585
+ expect(id.isIri('WS://example')).to.equal(true);
586
+ });
587
+
588
+ test('Valid case insensitive wss scheme', () => {
589
+ expect(id.isIri('WSs://example')).to.equal(true);
590
+ });
591
+
592
+ test('Valid case insensitive file scheme', () => {
593
+ expect(id.isIri('fILE://example')).to.equal(true);
594
+ });
595
+
554
596
  });