identifier-js 0.0.9 → 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.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identifier-js",
3
- "version": "0.0.9",
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",
@@ -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
  });