@stryke/url 0.2.2 → 0.2.4

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.
@@ -1,5 +1,5 @@
1
1
  import type { ParsedURL } from "ufo";
2
- import type { IStormURL, StormURLOptions } from "./types";
2
+ import type { StormURLInterface, StormURLOptions } from "./types";
3
3
  /**
4
4
  * A class used to build URLs
5
5
  *
@@ -8,7 +8,7 @@ import type { IStormURL, StormURLOptions } from "./types";
8
8
  *
9
9
  * The [UFO](https://github.com/unjs/ufo) library is used under the hood to parse and stringify URLs.
10
10
  */
11
- export declare class StormURL implements IStormURL, URL {
11
+ export declare class StormURL implements StormURLInterface, URL {
12
12
  #private;
13
13
  constructor(initialURL: string, options?: StormURLOptions);
14
14
  set params(value: Record<string, any>);
@@ -1 +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");
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 f,isEqual as S,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?f(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 S(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.d.ts CHANGED
@@ -17,7 +17,7 @@ export interface StormURLOptions {
17
17
  defaultProtocol?: string;
18
18
  }
19
19
  export declare const PROTOCOL_RELATIVE_SYMBOL: unique symbol;
20
- export interface IStormURL extends URL {
20
+ export interface StormURLInterface extends URL {
21
21
  /**
22
22
  * A string containing the username and password specified before the domain name.
23
23
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/url",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "A package containing the `StormURL` class, which is used to parse and manipulate URLs.",
6
6
  "repository": {
@@ -11,9 +11,9 @@
11
11
  "private": false,
12
12
  "dependencies": {
13
13
  "ufo": "1.5.4",
14
- "@stryke/json": "^0.9.1",
15
- "@stryke/path": "^0.8.0",
16
- "@stryke/type-checks": "^0.3.4"
14
+ "@stryke/json": "^0.9.2",
15
+ "@stryke/path": "^0.12.1",
16
+ "@stryke/type-checks": "^0.3.6"
17
17
  },
18
18
  "devDependencies": { "@types/node": "^22.14.0" },
19
19
  "publishConfig": { "access": "public" },
@@ -116,5 +116,6 @@
116
116
  },
117
117
  "main": "./dist/index.cjs",
118
118
  "module": "./dist/index.mjs",
119
- "types": "./dist/index.d.ts"
119
+ "types": "./dist/index.d.ts",
120
+ "gitHead": "57da58e3434302b35f798674d9f18f92ca7f7ac9"
120
121
  }