@stryke/url 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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <!-- START header -->
2
+ <!-- END header -->
3
+
4
+ # Stryke - URL Helpers
5
+
6
+ A package containing the `StormURL` wrapper class and various URL helper
7
+ utilities.
8
+
9
+ <!-- START doctoc -->
10
+ <!-- END doctoc -->
11
+
12
+ ## Installing
13
+
14
+ Using [pnpm](http://pnpm.io):
15
+
16
+ ```bash
17
+ pnpm add -D @stryke/url
18
+ ```
19
+
20
+ <details>
21
+ <summary>Using npm</summary>
22
+
23
+ ```bash
24
+ npm install -D @stryke/url
25
+ ```
26
+
27
+ </details>
28
+
29
+ <details>
30
+ <summary>Using yarn</summary>
31
+
32
+ ```bash
33
+ yarn add -D @stryke/url
34
+ ```
35
+
36
+ </details>
37
+
38
+ ## Reduced Package Size
39
+
40
+ This project uses [tsup](https://tsup.egoist.dev/) to package the source code
41
+ due to its ability to remove unused code and ship smaller javascript files
42
+ thanks to code splitting. This helps to greatly reduce the size of the package
43
+ and to make it easier to use in other projects.
44
+
45
+ ## Development
46
+
47
+ This project is built using [Nx](https://nx.dev). As a result, many of the usual
48
+ commands are available to assist in development.
49
+
50
+ ### Building
51
+
52
+ Run `nx build url` to build the library.
53
+
54
+ ### Running unit tests
55
+
56
+ Run `nx test url` to execute the unit tests via [Jest](https://jestjs.io).
57
+
58
+ ### Linting
59
+
60
+ Run `nx lint url` to run [ESLint](https://eslint.org/) on the package.
61
+
62
+ <!-- START footer -->
63
+ <!-- END footer -->
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatLocalePath = formatLocalePath;
7
+ function formatLocalePath(o) {
8
+ let t = o;
9
+ if (t.includes("_") && (t = t.replace(/_/g, "-")), t.includes("-")) {
10
+ const e = t.split("-");
11
+ if (e.length > 1) {
12
+ const n = e[0],
13
+ i = e[1];
14
+ n && i && (t = `${n}-${i}`);
15
+ }
16
+ }
17
+ return t.toLowerCase();
18
+ }
@@ -0,0 +1 @@
1
+ export declare function formatLocalePath(locale: string): string;
@@ -0,0 +1 @@
1
+ export function formatLocalePath(o){let t=o;if(t.includes("_")&&(t=t.replace(/_/g,"-")),t.includes("-")){const e=t.split("-");if(e.length>1){const n=e[0],i=e[1];n&&i&&(t=`${n}-${i}`)}}return t.toLowerCase()}
package/dist/index.cjs ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _stormUrl = require("./storm-url.cjs");
7
+ Object.keys(_stormUrl).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _stormUrl[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _stormUrl[key];
14
+ }
15
+ });
16
+ });
17
+ var _types = require("./types.cjs");
18
+ Object.keys(_types).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _types[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _types[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./storm-url";
2
+ export * from "./types";
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export*from"./storm-url";export*from"./types";
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StormURL = void 0;
7
+ var _stormJson = require("@stryke/json/storm-json");
8
+ var _joinPaths = require("@stryke/path/join-paths");
9
+ var _isInteger = require("@stryke/type-checks/is-integer");
10
+ var _isSetString = require("@stryke/type-checks/is-set-string");
11
+ var _isUndefined = require("@stryke/type-checks/is-undefined");
12
+ var _ufo = require("ufo");
13
+ var _helpers = require("./helpers.cjs");
14
+ class StormURL {
15
+ #a;
16
+ #t;
17
+ #s;
18
+ #i;
19
+ #r;
20
+ #o;
21
+ #e = [];
22
+ #h;
23
+ #n;
24
+ constructor(t, s = {
25
+ decode: !0
26
+ }) {
27
+ this.#a = s;
28
+ const i = (0, _ufo.parseURL)(this.#a.decode ? (0, _ufo.decode)(t) : t),
29
+ a = (0, _ufo.parseAuth)(i.auth);
30
+ this.#t = a.username, this.#s = a.password;
31
+ const o = (0, _ufo.parseHost)(i.host);
32
+ this.#i = o.hostname, this.#r = o.port, this.#o = i.protocol, this.#h = i.hash || "", this.#n = (0, _ufo.parseQuery)(i.search), this.#e = i.pathname ? i.pathname.split("/").filter(Boolean) : [], s.locale && this.#e.unshift((0, _helpers.formatLocalePath)(((0, _isSetString.isSetString)(s.locale) ? s.locale : process.env.DEFAULT_LOCALE) || "en-us"));
33
+ }
34
+ set params(t) {
35
+ this.#n = t;
36
+ }
37
+ get params() {
38
+ return this.#n;
39
+ }
40
+ get searchParams() {
41
+ const t = new URLSearchParams();
42
+ for (const [s, i] of Object.entries(this.params)) t.append(s, i);
43
+ return t;
44
+ }
45
+ set searchParams(t) {
46
+ this.params = Object.fromEntries(t.entries());
47
+ }
48
+ set search(t) {
49
+ this.params = (0, _ufo.parseQuery)(t);
50
+ }
51
+ get search() {
52
+ const t = (0, _ufo.stringifyQuery)(this.params);
53
+ return t ? t.startsWith("?") ? t : `?${t}` : "";
54
+ }
55
+ set hash(t) {
56
+ this.#h = t.startsWith("#") ? t : `#${t}`;
57
+ }
58
+ get hash() {
59
+ return this.#h;
60
+ }
61
+ set port(t) {
62
+ this.#r = !(0, _isUndefined.isUndefined)(t) && (0, _isInteger.isInteger)(t) ? `${t}` : "";
63
+ }
64
+ get port() {
65
+ return this.#r || "";
66
+ }
67
+ set username(t) {
68
+ this.auth = `${t}:${this.#s}`;
69
+ }
70
+ get username() {
71
+ return this.#t || "";
72
+ }
73
+ set password(t) {
74
+ this.auth = `${this.#t}:${t}`;
75
+ }
76
+ get password() {
77
+ return this.#s || "";
78
+ }
79
+ set auth(t) {
80
+ const s = (0, _ufo.parseAuth)(t);
81
+ this.#t = s.username, this.#s = s.password;
82
+ }
83
+ get auth() {
84
+ return this.#t && this.#s ? `${this.#t}:${this.#s}` : this.#t ? this.#t : this.#s ? this.#s : "";
85
+ }
86
+ set protocol(t) {
87
+ this.#o = t.endsWith(":") ? t : t.endsWith("://") ? t.slice(0, -2) : `${t}:`;
88
+ }
89
+ get protocol() {
90
+ return this.#o || this.#a.defaultProtocol || "https:";
91
+ }
92
+ set hostname(t) {
93
+ this.#i = t;
94
+ }
95
+ get hostname() {
96
+ return this.#i;
97
+ }
98
+ set host(t) {
99
+ const s = (0, _ufo.parseHost)(t);
100
+ this.#i = s.hostname, this.#r = s.port;
101
+ }
102
+ get host() {
103
+ return this.#i && this.#r ? `${this.#i}:${this.#r}` : this.#i ? this.#i : this.#r ? this.#r : "";
104
+ }
105
+ set paths(t) {
106
+ this.#e = t.filter(Boolean);
107
+ }
108
+ get paths() {
109
+ return this.#e;
110
+ }
111
+ set pathname(t) {
112
+ this.paths = (0, _ufo.cleanDoubleSlashes)(t).split("/");
113
+ }
114
+ get pathname() {
115
+ return `/${this.paths ? (0, _joinPaths.joinPaths)(...this.paths.map(t => _stormJson.StormJSON.stringify(t))) : ""}`;
116
+ }
117
+ set path(t) {
118
+ const s = (0, _ufo.parsePath)(t);
119
+ this.pathname = s.pathname, this.search = s.search, this.#h = s.hash;
120
+ }
121
+ get path() {
122
+ return (0, _ufo.stringifyParsedURL)({
123
+ pathname: this.pathname,
124
+ search: this.search,
125
+ hash: this.hash
126
+ });
127
+ }
128
+ get href() {
129
+ return this.toString();
130
+ }
131
+ set href(t) {
132
+ const s = (0, _ufo.parseURL)(t);
133
+ this.protocol = s.protocol || this.protocol, this.auth = s.auth || this.auth, this.host = s.host || this.host, this.pathname = s.pathname || this.pathname, this.search = s.search || this.search, this.hash = s.hash || this.hash;
134
+ }
135
+ get origin() {
136
+ return `${this.protocol}//${this.host}`;
137
+ }
138
+ get isScriptProtocol() {
139
+ return (0, _ufo.isScriptProtocol)(this.protocol);
140
+ }
141
+ get isRelative() {
142
+ return (0, _ufo.isRelative)(this.toString());
143
+ }
144
+ get isNonEmptyURL() {
145
+ return (0, _ufo.isNonEmptyURL)(this.toString());
146
+ }
147
+ get __typename() {
148
+ return "StormURL";
149
+ }
150
+ isSamePath(t) {
151
+ return (0, _ufo.isSamePath)(this.path, t);
152
+ }
153
+ isEqual(t) {
154
+ return (0, _ufo.isEqual)(this.toString(), typeof t == "string" ? t : t instanceof StormURL ? t.toString() : (0, _ufo.stringifyParsedURL)(t));
155
+ }
156
+ toParsed() {
157
+ return {
158
+ protocol: this.protocol,
159
+ auth: this.auth,
160
+ host: this.host,
161
+ pathname: this.pathname,
162
+ search: this.search,
163
+ hash: this.hash
164
+ };
165
+ }
166
+ toString() {
167
+ return (0, _ufo.stringifyParsedURL)(this.toParsed());
168
+ }
169
+ toEncoded() {
170
+ return (0, _ufo.normalizeURL)(this.toString());
171
+ }
172
+ toJSON() {
173
+ return _stormJson.StormJSON.stringify(this.toParsed());
174
+ }
175
+ }
176
+ exports.StormURL = StormURL;
177
+ _stormJson.StormJSON.instance.registerCustom({
178
+ isApplicable: r => r.__typename === "StormURL",
179
+ serialize: r => r.toEncoded(),
180
+ deserialize: r => new StormURL(r, {
181
+ decode: !0
182
+ })
183
+ }, "StormURL");
@@ -0,0 +1,55 @@
1
+ import type { ParsedURL } from "ufo";
2
+ import type { IStormURL, StormURLOptions } from "./types";
3
+ /**
4
+ * A class used to build URLs
5
+ *
6
+ * @remarks
7
+ * This class is used to build URLs with a fluent API.
8
+ *
9
+ * The [UFO](https://github.com/unjs/ufo) library is used under the hood to parse and stringify URLs.
10
+ */
11
+ export declare class StormURL implements IStormURL, URL {
12
+ #private;
13
+ constructor(initialURL: string, options?: StormURLOptions);
14
+ set params(value: Record<string, any>);
15
+ get params(): Record<string, any>;
16
+ get searchParams(): URLSearchParams;
17
+ set searchParams(value: URLSearchParams);
18
+ set search(value: string);
19
+ get search(): string;
20
+ set hash(value: string);
21
+ get hash(): string;
22
+ set port(value: string | number);
23
+ get port(): string;
24
+ set username(value: string);
25
+ get username(): string;
26
+ set password(value: string);
27
+ get password(): string;
28
+ set auth(value: string | undefined);
29
+ get auth(): string;
30
+ set protocol(value: string);
31
+ get protocol(): string;
32
+ set hostname(value: string);
33
+ get hostname(): string;
34
+ set host(value: string | undefined);
35
+ get host(): string;
36
+ set paths(value: any[]);
37
+ get paths(): any[];
38
+ set pathname(value: string);
39
+ get pathname(): string;
40
+ set path(value: string);
41
+ get path(): string;
42
+ get href(): string;
43
+ set href(value: string);
44
+ get origin(): string;
45
+ get isScriptProtocol(): boolean;
46
+ get isRelative(): boolean;
47
+ get isNonEmptyURL(): boolean;
48
+ get __typename(): string;
49
+ isSamePath(path: string): boolean;
50
+ isEqual(url: string | ParsedURL | StormURL): boolean;
51
+ toParsed(): ParsedURL;
52
+ toString(): string;
53
+ toEncoded(): string;
54
+ toJSON(): string;
55
+ }
@@ -0,0 +1 @@
1
+ import{StormJSON as e}from"@stryke/json/storm-json";import{joinPaths as m}from"@stryke/path/join-paths";import{isInteger as g}from"@stryke/type-checks/is-integer";import{isSetString as l}from"@stryke/type-checks/is-set-string";import{isUndefined as b}from"@stryke/type-checks/is-undefined";import{cleanDoubleSlashes as d,decode as S,isEqual as f,isNonEmptyURL as R,isRelative as L,isSamePath as U,isScriptProtocol as P,normalizeURL as y,parseAuth as n,parseHost as p,parsePath as $,parseQuery as c,parseURL as u,stringifyParsedURL as h,stringifyQuery as E}from"ufo";import{formatLocalePath as O}from"./helpers";export class StormURL{#a;#t;#s;#i;#r;#o;#e=[];#h;#n;constructor(t,s={decode:!0}){this.#a=s;const i=u(this.#a.decode?S(t):t),a=n(i.auth);this.#t=a.username,this.#s=a.password;const o=p(i.host);this.#i=o.hostname,this.#r=o.port,this.#o=i.protocol,this.#h=i.hash||"",this.#n=c(i.search),this.#e=i.pathname?i.pathname.split("/").filter(Boolean):[],s.locale&&this.#e.unshift(O((l(s.locale)?s.locale:process.env.DEFAULT_LOCALE)||"en-us"))}set params(t){this.#n=t}get params(){return this.#n}get searchParams(){const t=new URLSearchParams;for(const[s,i]of Object.entries(this.params))t.append(s,i);return t}set searchParams(t){this.params=Object.fromEntries(t.entries())}set search(t){this.params=c(t)}get search(){const t=E(this.params);return t?t.startsWith("?")?t:`?${t}`:""}set hash(t){this.#h=t.startsWith("#")?t:`#${t}`}get hash(){return this.#h}set port(t){this.#r=!b(t)&&g(t)?`${t}`:""}get port(){return this.#r||""}set username(t){this.auth=`${t}:${this.#s}`}get username(){return this.#t||""}set password(t){this.auth=`${this.#t}:${t}`}get password(){return this.#s||""}set auth(t){const s=n(t);this.#t=s.username,this.#s=s.password}get auth(){return this.#t&&this.#s?`${this.#t}:${this.#s}`:this.#t?this.#t:this.#s?this.#s:""}set protocol(t){this.#o=t.endsWith(":")?t:t.endsWith("://")?t.slice(0,-2):`${t}:`}get protocol(){return this.#o||this.#a.defaultProtocol||"https:"}set hostname(t){this.#i=t}get hostname(){return this.#i}set host(t){const s=p(t);this.#i=s.hostname,this.#r=s.port}get host(){return this.#i&&this.#r?`${this.#i}:${this.#r}`:this.#i?this.#i:this.#r?this.#r:""}set paths(t){this.#e=t.filter(Boolean)}get paths(){return this.#e}set pathname(t){this.paths=d(t).split("/")}get pathname(){return`/${this.paths?m(...this.paths.map(t=>e.stringify(t))):""}`}set path(t){const s=$(t);this.pathname=s.pathname,this.search=s.search,this.#h=s.hash}get path(){return h({pathname:this.pathname,search:this.search,hash:this.hash})}get href(){return this.toString()}set href(t){const s=u(t);this.protocol=s.protocol||this.protocol,this.auth=s.auth||this.auth,this.host=s.host||this.host,this.pathname=s.pathname||this.pathname,this.search=s.search||this.search,this.hash=s.hash||this.hash}get origin(){return`${this.protocol}//${this.host}`}get isScriptProtocol(){return P(this.protocol)}get isRelative(){return L(this.toString())}get isNonEmptyURL(){return R(this.toString())}get __typename(){return"StormURL"}isSamePath(t){return U(this.path,t)}isEqual(t){return f(this.toString(),typeof t=="string"?t:t instanceof StormURL?t.toString():h(t))}toParsed(){return{protocol:this.protocol,auth:this.auth,host:this.host,pathname:this.pathname,search:this.search,hash:this.hash}}toString(){return h(this.toParsed())}toEncoded(){return y(this.toString())}toJSON(){return e.stringify(this.toParsed())}}e.instance.registerCustom({isApplicable:r=>r.__typename==="StormURL",serialize:r=>r.toEncoded(),deserialize:r=>new StormURL(r,{decode:!0})},"StormURL");
package/dist/types.cjs ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PROTOCOL_RELATIVE_SYMBOL = void 0;
7
+ const PROTOCOL_RELATIVE_SYMBOL = exports.PROTOCOL_RELATIVE_SYMBOL = Symbol("protocol-relative");
@@ -0,0 +1,90 @@
1
+ export interface StormURLOptions {
2
+ /**
3
+ * Should the URL be decoded
4
+ *
5
+ * @defaultValue `true`
6
+ */
7
+ decode?: boolean;
8
+ /**
9
+ * Should the URL include a locale path segment
10
+ */
11
+ locale?: string | true;
12
+ /**
13
+ * The default protocol to use
14
+ *
15
+ * @defaultValue "https"
16
+ */
17
+ defaultProtocol?: string;
18
+ }
19
+ export declare const PROTOCOL_RELATIVE_SYMBOL: unique symbol;
20
+ export interface IStormURL extends URL {
21
+ /**
22
+ * A string containing the username and password specified before the domain name.
23
+ */
24
+ auth: string;
25
+ /**
26
+ * A string containing the username specified before the domain name.
27
+ */
28
+ username: string;
29
+ /**
30
+ * A string containing the password specified before the domain name.
31
+ */
32
+ password: string;
33
+ /**
34
+ * A string containing the domain (that is the hostname) followed by (if a port was specified) a `:` and the port of the URL.
35
+ */
36
+ host: string;
37
+ /**
38
+ * A string containing the domain of the URL.
39
+ */
40
+ hostname: string;
41
+ /**
42
+ * A string containing the port number of the URL.
43
+ */
44
+ port: string;
45
+ /**
46
+ * A string containing the protocol scheme of the URL, including the final `:`.
47
+ */
48
+ protocol: string;
49
+ /**
50
+ * A stringified value that returns the whole URL.
51
+ */
52
+ href: string;
53
+ /**
54
+ * A string containing an initial `/` followed by the path of the URL, not including the query string or fragment.
55
+ */
56
+ pathname: string;
57
+ /**
58
+ * The paths of the URL
59
+ */
60
+ paths: any[];
61
+ /**
62
+ * A string containing a `#` followed by the fragment identifier of the URL.
63
+ */
64
+ hash: string;
65
+ /**
66
+ * A string indicating the URL's parameter string; if any parameters are provided, this string includes all of them, beginning with the leading `?` character.
67
+ */
68
+ search: string;
69
+ /**
70
+ * The search parameters of the URL
71
+ *
72
+ * @remarks
73
+ * This is a `URLSearchParams` object that contains the search parameters of the URL.
74
+ */
75
+ searchParams: URLSearchParams;
76
+ /**
77
+ * The search parameters of the URL
78
+ *
79
+ * @remarks
80
+ * This is a Record\<string, any\> object that contains the search parameters of the URL.
81
+ */
82
+ params: Record<string, any>;
83
+ /**
84
+ * An optional symbol to indicate that the URL is protocol-relative
85
+ *
86
+ * @remarks
87
+ * This is used when the URL is protocol-relative (e.g. //example.com)
88
+ */
89
+ [PROTOCOL_RELATIVE_SYMBOL]?: boolean;
90
+ }
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export const PROTOCOL_RELATIVE_SYMBOL=Symbol("protocol-relative");
package/package.json ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ "name": "@stryke/url",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "A package containing the `StormURL` class, which is used to parse and manipulate URLs.",
6
+ "repository": {
7
+ "type": "github",
8
+ "url": "https://github.com/storm-software/stryke.git",
9
+ "directory": "packages/url"
10
+ },
11
+ "private": false,
12
+ "dependencies": {
13
+ "ufo": "1.5.4",
14
+ "@stryke/json": "^0.7.3",
15
+ "@stryke/path": "^0.4.11",
16
+ "@stryke/type-checks": "^0.3.2"
17
+ },
18
+ "devDependencies": { "@types/node": "^22.13.1" },
19
+ "publishConfig": { "access": "public" },
20
+ "sideEffects": false,
21
+ "files": ["dist/**/*"],
22
+ "homepage": "https://stormsoftware.com",
23
+ "bugs": {
24
+ "url": "https://stormsoftware.com/support",
25
+ "email": "support@stormsoftware.com"
26
+ },
27
+ "license": "Apache-2.0",
28
+ "keywords": [
29
+ "stryke",
30
+ "typescript",
31
+ "utilities",
32
+ "storm-software",
33
+ "storm",
34
+ "storm-ops",
35
+ "cyclone-ui",
36
+ "sullivanpj",
37
+ "monorepo"
38
+ ],
39
+ "funding": {
40
+ "type": "github",
41
+ "url": "https://github.com/sponsors/storm-software"
42
+ },
43
+ "author": {
44
+ "name": "Storm Software",
45
+ "email": "contact@stormsoftware.com",
46
+ "url": "https://stormsoftware.com"
47
+ },
48
+ "maintainers": [
49
+ {
50
+ "name": "Storm Software",
51
+ "email": "contact@stormsoftware.com",
52
+ "url": "https://stormsoftware.com"
53
+ }
54
+ ],
55
+ "contributors": [
56
+ {
57
+ "name": "Storm Software",
58
+ "email": "contact@stormsoftware.com",
59
+ "url": "https://stormsoftware.com"
60
+ }
61
+ ],
62
+ "exports": {
63
+ "./types": {
64
+ "import": { "types": "./dist/types.d.ts", "default": "./dist/types.mjs" },
65
+ "require": {
66
+ "types": "./dist/types.d.ts",
67
+ "default": "./dist/types.cjs"
68
+ },
69
+ "default": { "types": "./dist/types.d.ts", "default": "./dist/types.mjs" }
70
+ },
71
+ "./storm-url": {
72
+ "import": {
73
+ "types": "./dist/storm-url.d.ts",
74
+ "default": "./dist/storm-url.mjs"
75
+ },
76
+ "require": {
77
+ "types": "./dist/storm-url.d.ts",
78
+ "default": "./dist/storm-url.cjs"
79
+ },
80
+ "default": {
81
+ "types": "./dist/storm-url.d.ts",
82
+ "default": "./dist/storm-url.mjs"
83
+ }
84
+ },
85
+ "./index": {
86
+ "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
87
+ "require": {
88
+ "types": "./dist/index.d.ts",
89
+ "default": "./dist/index.cjs"
90
+ },
91
+ "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
92
+ },
93
+ "./helpers": {
94
+ "import": {
95
+ "types": "./dist/helpers.d.ts",
96
+ "default": "./dist/helpers.mjs"
97
+ },
98
+ "require": {
99
+ "types": "./dist/helpers.d.ts",
100
+ "default": "./dist/helpers.cjs"
101
+ },
102
+ "default": {
103
+ "types": "./dist/helpers.d.ts",
104
+ "default": "./dist/helpers.mjs"
105
+ }
106
+ },
107
+ ".": {
108
+ "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
109
+ "require": {
110
+ "types": "./dist/index.d.ts",
111
+ "default": "./dist/index.cjs"
112
+ },
113
+ "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
114
+ },
115
+ "./package.json": "./package.json"
116
+ },
117
+ "main": "./dist/index.cjs",
118
+ "module": "./dist/index.mjs",
119
+ "types": "./dist/index.d.ts"
120
+ }