@react-foundry/uri 0.1.0
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/LICENSE +22 -0
- package/README.md +49 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/index.mjs +2 -0
- package/dist/query-string.d.ts +4 -0
- package/dist/query-string.js +10 -0
- package/dist/query-string.mjs +5 -0
- package/dist/uri.d.ts +27 -0
- package/dist/uri.js +136 -0
- package/dist/uri.mjs +132 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2019-2025 Crown Copyright
|
|
4
|
+
Copyright (C) 2019-2026 Daniel A.C. Martin
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
the Software without restriction, including without limitation the rights to
|
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
React Foundry - URI
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
A more forgiving alternative to JavaScript's standard URL class.
|
|
5
|
+
Supports nested structures in the query-strings.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Using this package
|
|
9
|
+
------------------
|
|
10
|
+
|
|
11
|
+
First install the package into your project:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install -S @react-foundry/uri
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then use it in your code as follows:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { URI } from '@react-foundry/uri';
|
|
21
|
+
|
|
22
|
+
// WRITEME
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Working on this package
|
|
28
|
+
-----------------------
|
|
29
|
+
|
|
30
|
+
Before working on this package you must install its dependencies using
|
|
31
|
+
the following command:
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
pnpm install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Building
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
npm run build
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Clean-up
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
npm run clean
|
|
49
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./query-string"), exports);
|
|
18
|
+
__exportStar(require("./uri"), exports);
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryString = exports.qsParse = void 0;
|
|
4
|
+
const qs_1 = require("qs");
|
|
5
|
+
const qsParse = (s) => (0, qs_1.parse)(s && s[0] === '?'
|
|
6
|
+
? s?.substring(1)
|
|
7
|
+
: s);
|
|
8
|
+
exports.qsParse = qsParse;
|
|
9
|
+
const queryString = (obj) => '?' + (0, qs_1.stringify)(obj);
|
|
10
|
+
exports.queryString = queryString;
|
package/dist/uri.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Query } from './query-string';
|
|
2
|
+
export declare class URI extends Object {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(uri: string, base?: string);
|
|
5
|
+
get href(): string;
|
|
6
|
+
get protocol(): string;
|
|
7
|
+
set protocol(v: string);
|
|
8
|
+
get username(): string;
|
|
9
|
+
set username(v: string);
|
|
10
|
+
get password(): string;
|
|
11
|
+
set password(v: string);
|
|
12
|
+
get hostname(): string;
|
|
13
|
+
set hostname(v: string);
|
|
14
|
+
get port(): string;
|
|
15
|
+
set port(v: string);
|
|
16
|
+
get pathname(): string;
|
|
17
|
+
set pathname(v: string);
|
|
18
|
+
get search(): string;
|
|
19
|
+
set search(v: string);
|
|
20
|
+
get hash(): string;
|
|
21
|
+
set hash(v: string);
|
|
22
|
+
get query(): Query;
|
|
23
|
+
set query(v: Query);
|
|
24
|
+
toString(): string;
|
|
25
|
+
valueOf(): object;
|
|
26
|
+
static parse(s: string, base?: string): URI;
|
|
27
|
+
}
|
package/dist/uri.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.URI = void 0;
|
|
4
|
+
const query_string_1 = require("./query-string");
|
|
5
|
+
class URI extends Object {
|
|
6
|
+
#url;
|
|
7
|
+
#noHostname = false;
|
|
8
|
+
#noPathname = false;
|
|
9
|
+
#query;
|
|
10
|
+
constructor(uri, base) {
|
|
11
|
+
super();
|
|
12
|
+
try {
|
|
13
|
+
this.#url = new URL(uri, base);
|
|
14
|
+
}
|
|
15
|
+
catch (_e) {
|
|
16
|
+
const dummyOrigin = 'http://a';
|
|
17
|
+
this.#noHostname = true;
|
|
18
|
+
try {
|
|
19
|
+
const newBase = (base
|
|
20
|
+
? (base[0] === '/'
|
|
21
|
+
? dummyOrigin + base
|
|
22
|
+
: dummyOrigin + '/' + base)
|
|
23
|
+
: dummyOrigin);
|
|
24
|
+
this.#url = new URL(uri, newBase);
|
|
25
|
+
this.#noPathname = this.#url.pathname === '/' && uri[0] !== '/';
|
|
26
|
+
}
|
|
27
|
+
catch (_e) {
|
|
28
|
+
this.#url = new URL('', dummyOrigin);
|
|
29
|
+
this.#noPathname = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this.#query = (0, query_string_1.qsParse)(this.#url.search);
|
|
33
|
+
}
|
|
34
|
+
get href() {
|
|
35
|
+
const targetHref = this.#url.href;
|
|
36
|
+
const hash = (targetHref[targetHref.length - 1] === '#'
|
|
37
|
+
? '#'
|
|
38
|
+
: this.#url.hash);
|
|
39
|
+
return (this.#noHostname
|
|
40
|
+
? this.pathname + this.#url.search + hash
|
|
41
|
+
: targetHref);
|
|
42
|
+
}
|
|
43
|
+
get protocol() {
|
|
44
|
+
return (this.#noHostname
|
|
45
|
+
? ''
|
|
46
|
+
: this.#url.protocol);
|
|
47
|
+
}
|
|
48
|
+
set protocol(v) {
|
|
49
|
+
this.#url.protocol = v;
|
|
50
|
+
}
|
|
51
|
+
get username() {
|
|
52
|
+
return (this.#noHostname
|
|
53
|
+
? ''
|
|
54
|
+
: this.#url.username);
|
|
55
|
+
}
|
|
56
|
+
set username(v) {
|
|
57
|
+
this.#url.username = v;
|
|
58
|
+
}
|
|
59
|
+
get password() {
|
|
60
|
+
return (this.#noHostname
|
|
61
|
+
? ''
|
|
62
|
+
: this.#url.password);
|
|
63
|
+
}
|
|
64
|
+
set password(v) {
|
|
65
|
+
this.#url.password = v;
|
|
66
|
+
}
|
|
67
|
+
get hostname() {
|
|
68
|
+
return (this.#noHostname
|
|
69
|
+
? ''
|
|
70
|
+
: this.#url.hostname);
|
|
71
|
+
}
|
|
72
|
+
set hostname(v) {
|
|
73
|
+
this.#noHostname = !v;
|
|
74
|
+
this.#url.hostname = v;
|
|
75
|
+
}
|
|
76
|
+
get port() {
|
|
77
|
+
return (this.#noHostname
|
|
78
|
+
? ''
|
|
79
|
+
: this.#url.port);
|
|
80
|
+
}
|
|
81
|
+
set port(v) {
|
|
82
|
+
this.#url.port = v;
|
|
83
|
+
}
|
|
84
|
+
get pathname() {
|
|
85
|
+
return (this.#noPathname
|
|
86
|
+
? ''
|
|
87
|
+
: this.#url.pathname);
|
|
88
|
+
}
|
|
89
|
+
set pathname(v) {
|
|
90
|
+
this.#noPathname = !v;
|
|
91
|
+
this.#url.pathname = v;
|
|
92
|
+
}
|
|
93
|
+
get search() {
|
|
94
|
+
return this.#url.search;
|
|
95
|
+
}
|
|
96
|
+
set search(v) {
|
|
97
|
+
this.#query = (0, query_string_1.qsParse)(v);
|
|
98
|
+
this.#url.search = v;
|
|
99
|
+
}
|
|
100
|
+
get hash() {
|
|
101
|
+
return this.#url.hash;
|
|
102
|
+
}
|
|
103
|
+
set hash(v) {
|
|
104
|
+
this.#url.hash = v;
|
|
105
|
+
}
|
|
106
|
+
get query() {
|
|
107
|
+
return this.#query;
|
|
108
|
+
}
|
|
109
|
+
set query(v) {
|
|
110
|
+
this.#query = v;
|
|
111
|
+
this.#url.search = (0, query_string_1.queryString)(v);
|
|
112
|
+
}
|
|
113
|
+
toString() {
|
|
114
|
+
return (this.#noHostname
|
|
115
|
+
? this.href
|
|
116
|
+
: this.#url.toString());
|
|
117
|
+
}
|
|
118
|
+
valueOf() {
|
|
119
|
+
return ({
|
|
120
|
+
href: this.href,
|
|
121
|
+
protocol: this.protocol,
|
|
122
|
+
username: this.username,
|
|
123
|
+
password: this.password,
|
|
124
|
+
hostname: this.hostname,
|
|
125
|
+
port: this.port,
|
|
126
|
+
pathname: this.pathname,
|
|
127
|
+
search: this.search,
|
|
128
|
+
query: this.query,
|
|
129
|
+
hash: this.hash
|
|
130
|
+
}).valueOf();
|
|
131
|
+
}
|
|
132
|
+
static parse(s, base) {
|
|
133
|
+
return new URI(s, base);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.URI = URI;
|
package/dist/uri.mjs
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { qsParse, queryString } from './query-string';
|
|
2
|
+
export class URI extends Object {
|
|
3
|
+
#url;
|
|
4
|
+
#noHostname = false;
|
|
5
|
+
#noPathname = false;
|
|
6
|
+
#query;
|
|
7
|
+
constructor(uri, base) {
|
|
8
|
+
super();
|
|
9
|
+
try {
|
|
10
|
+
this.#url = new URL(uri, base);
|
|
11
|
+
}
|
|
12
|
+
catch (_e) {
|
|
13
|
+
const dummyOrigin = 'http://a';
|
|
14
|
+
this.#noHostname = true;
|
|
15
|
+
try {
|
|
16
|
+
const newBase = (base
|
|
17
|
+
? (base[0] === '/'
|
|
18
|
+
? dummyOrigin + base
|
|
19
|
+
: dummyOrigin + '/' + base)
|
|
20
|
+
: dummyOrigin);
|
|
21
|
+
this.#url = new URL(uri, newBase);
|
|
22
|
+
this.#noPathname = this.#url.pathname === '/' && uri[0] !== '/';
|
|
23
|
+
}
|
|
24
|
+
catch (_e) {
|
|
25
|
+
this.#url = new URL('', dummyOrigin);
|
|
26
|
+
this.#noPathname = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this.#query = qsParse(this.#url.search);
|
|
30
|
+
}
|
|
31
|
+
get href() {
|
|
32
|
+
const targetHref = this.#url.href;
|
|
33
|
+
const hash = (targetHref[targetHref.length - 1] === '#'
|
|
34
|
+
? '#'
|
|
35
|
+
: this.#url.hash);
|
|
36
|
+
return (this.#noHostname
|
|
37
|
+
? this.pathname + this.#url.search + hash
|
|
38
|
+
: targetHref);
|
|
39
|
+
}
|
|
40
|
+
get protocol() {
|
|
41
|
+
return (this.#noHostname
|
|
42
|
+
? ''
|
|
43
|
+
: this.#url.protocol);
|
|
44
|
+
}
|
|
45
|
+
set protocol(v) {
|
|
46
|
+
this.#url.protocol = v;
|
|
47
|
+
}
|
|
48
|
+
get username() {
|
|
49
|
+
return (this.#noHostname
|
|
50
|
+
? ''
|
|
51
|
+
: this.#url.username);
|
|
52
|
+
}
|
|
53
|
+
set username(v) {
|
|
54
|
+
this.#url.username = v;
|
|
55
|
+
}
|
|
56
|
+
get password() {
|
|
57
|
+
return (this.#noHostname
|
|
58
|
+
? ''
|
|
59
|
+
: this.#url.password);
|
|
60
|
+
}
|
|
61
|
+
set password(v) {
|
|
62
|
+
this.#url.password = v;
|
|
63
|
+
}
|
|
64
|
+
get hostname() {
|
|
65
|
+
return (this.#noHostname
|
|
66
|
+
? ''
|
|
67
|
+
: this.#url.hostname);
|
|
68
|
+
}
|
|
69
|
+
set hostname(v) {
|
|
70
|
+
this.#noHostname = !v;
|
|
71
|
+
this.#url.hostname = v;
|
|
72
|
+
}
|
|
73
|
+
get port() {
|
|
74
|
+
return (this.#noHostname
|
|
75
|
+
? ''
|
|
76
|
+
: this.#url.port);
|
|
77
|
+
}
|
|
78
|
+
set port(v) {
|
|
79
|
+
this.#url.port = v;
|
|
80
|
+
}
|
|
81
|
+
get pathname() {
|
|
82
|
+
return (this.#noPathname
|
|
83
|
+
? ''
|
|
84
|
+
: this.#url.pathname);
|
|
85
|
+
}
|
|
86
|
+
set pathname(v) {
|
|
87
|
+
this.#noPathname = !v;
|
|
88
|
+
this.#url.pathname = v;
|
|
89
|
+
}
|
|
90
|
+
get search() {
|
|
91
|
+
return this.#url.search;
|
|
92
|
+
}
|
|
93
|
+
set search(v) {
|
|
94
|
+
this.#query = qsParse(v);
|
|
95
|
+
this.#url.search = v;
|
|
96
|
+
}
|
|
97
|
+
get hash() {
|
|
98
|
+
return this.#url.hash;
|
|
99
|
+
}
|
|
100
|
+
set hash(v) {
|
|
101
|
+
this.#url.hash = v;
|
|
102
|
+
}
|
|
103
|
+
get query() {
|
|
104
|
+
return this.#query;
|
|
105
|
+
}
|
|
106
|
+
set query(v) {
|
|
107
|
+
this.#query = v;
|
|
108
|
+
this.#url.search = queryString(v);
|
|
109
|
+
}
|
|
110
|
+
toString() {
|
|
111
|
+
return (this.#noHostname
|
|
112
|
+
? this.href
|
|
113
|
+
: this.#url.toString());
|
|
114
|
+
}
|
|
115
|
+
valueOf() {
|
|
116
|
+
return ({
|
|
117
|
+
href: this.href,
|
|
118
|
+
protocol: this.protocol,
|
|
119
|
+
username: this.username,
|
|
120
|
+
password: this.password,
|
|
121
|
+
hostname: this.hostname,
|
|
122
|
+
port: this.port,
|
|
123
|
+
pathname: this.pathname,
|
|
124
|
+
search: this.search,
|
|
125
|
+
query: this.query,
|
|
126
|
+
hash: this.hash
|
|
127
|
+
}).valueOf();
|
|
128
|
+
}
|
|
129
|
+
static parse(s, base) {
|
|
130
|
+
return new URI(s, base);
|
|
131
|
+
}
|
|
132
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-foundry/uri",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A more forgiving alternative to JavaScript's standard URL class.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"/dist"
|
|
16
|
+
],
|
|
17
|
+
"author": "Daniel A.C. Martin <npm@daniel-martin.co.uk> (http://daniel-martin.co.uk/)",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=12.0.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"qs": "^6.14.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/qs": "6.14.0",
|
|
27
|
+
"jest": "30.2.0",
|
|
28
|
+
"jest-environment-jsdom": "30.2.0",
|
|
29
|
+
"ts-jest": "29.4.6",
|
|
30
|
+
"typescript": "5.9.3"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
34
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
35
|
+
"build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
|
|
36
|
+
"build:cjs": "tsc",
|
|
37
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
38
|
+
},
|
|
39
|
+
"module": "dist/index.mjs",
|
|
40
|
+
"typings": "dist/index.d.ts"
|
|
41
|
+
}
|