@stryke/http 0.7.0 → 0.7.1

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.
@@ -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 CHANGED
@@ -25,6 +25,17 @@ Object.keys(_formatDataUri).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
+ var _helpers = require("./helpers.cjs");
29
+ Object.keys(_helpers).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _helpers[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _helpers[key];
36
+ }
37
+ });
38
+ });
28
39
  var _types = require("./types.cjs");
29
40
  Object.keys(_types).forEach(function (key) {
30
41
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./cookie";
2
2
  export * from "./format-data-uri";
3
+ export * from "./helpers";
3
4
  export * from "./types";
4
5
  export * from "./url";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./cookie";export*from"./format-data-uri";export*from"./types";export*from"./url";
1
+ export*from"./cookie";export*from"./format-data-uri";export*from"./helpers";export*from"./types";export*from"./url";
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface StormURLBuilderOptions {
1
+ export interface StormURLOptions {
2
2
  /**
3
3
  * Should the URL be decoded
4
4
  *
package/dist/url.cjs CHANGED
@@ -7,27 +7,29 @@ exports.StormURL = void 0;
7
7
  var _stormJson = require("@stryke/json/storm-json");
8
8
  var _joinPaths = require("@stryke/path/join-paths");
9
9
  var _isInteger = require("@stryke/type-checks/is-integer");
10
+ var _isSetString = require("@stryke/type-checks/is-set-string");
10
11
  var _isUndefined = require("@stryke/type-checks/is-undefined");
11
12
  var _ufo = require("ufo");
13
+ var _helpers = require("./helpers.cjs");
12
14
  class StormURL {
13
- #h;
15
+ #a;
14
16
  #i;
15
17
  #r;
16
18
  #t;
17
19
  #s;
18
- #a;
19
- #o = [];
20
- #e;
20
+ #o;
21
+ #e = [];
22
+ #h;
21
23
  #n;
22
24
  constructor(t, s = {
23
25
  decode: !0
24
26
  }) {
25
- this.#h = s;
26
- const i = (0, _ufo.parseURL)(this.#h.decode ? (0, _ufo.decode)(t) : t),
27
+ this.#a = s;
28
+ const i = (0, _ufo.parseURL)(this.#a.decode ? (0, _ufo.decode)(t) : t),
27
29
  h = (0, _ufo.parseAuth)(i.auth);
28
30
  this.#i = h.username, this.#r = h.password;
29
31
  const a = (0, _ufo.parseHost)(i.host);
30
- this.#t = a.hostname, this.#s = a.port, this.#a = i.protocol, this.#e = i.hash || "", this.#n = (0, _ufo.parseQuery)(i.search), this.#o = i.pathname ? i.pathname.split("/").filter(Boolean) : [];
32
+ this.#t = a.hostname, this.#s = a.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"));
31
33
  }
32
34
  set params(t) {
33
35
  this.#n = t;
@@ -51,10 +53,10 @@ class StormURL {
51
53
  return t ? t.startsWith("?") ? t : `?${t}` : "";
52
54
  }
53
55
  set hash(t) {
54
- this.#e = t.startsWith("#") ? t : `#${t}`;
56
+ this.#h = t.startsWith("#") ? t : `#${t}`;
55
57
  }
56
58
  get hash() {
57
- return this.#e;
59
+ return this.#h;
58
60
  }
59
61
  set port(t) {
60
62
  this.#s = !(0, _isUndefined.isUndefined)(t) && (0, _isInteger.isInteger)(t) ? `${t}` : void 0;
@@ -70,10 +72,10 @@ class StormURL {
70
72
  return this.#i && this.#r ? `${this.#i}:${this.#r}` : this.#i ? this.#i : this.#r ? this.#r : "";
71
73
  }
72
74
  set protocol(t) {
73
- this.#a = t.endsWith(":") ? t : t.endsWith("://") ? t.slice(0, -2) : `${t}:`;
75
+ this.#o = t.endsWith(":") ? t : t.endsWith("://") ? t.slice(0, -2) : `${t}:`;
74
76
  }
75
77
  get protocol() {
76
- return this.#a || this.#h.defaultProtocol || "https:";
78
+ return this.#o || this.#a.defaultProtocol || "https:";
77
79
  }
78
80
  set hostname(t) {
79
81
  this.#t = t;
@@ -89,10 +91,10 @@ class StormURL {
89
91
  return this.#t && this.#s ? `${this.#t}:${this.#s}` : this.#t ? this.#t : this.#s ? this.#s : "";
90
92
  }
91
93
  set paths(t) {
92
- this.#o = t.filter(Boolean);
94
+ this.#e = t.filter(Boolean);
93
95
  }
94
96
  get paths() {
95
- return this.#o;
97
+ return this.#e;
96
98
  }
97
99
  set pathname(t) {
98
100
  this.paths = (0, _ufo.cleanDoubleSlashes)(t).split("/");
@@ -102,7 +104,7 @@ class StormURL {
102
104
  }
103
105
  set path(t) {
104
106
  const s = (0, _ufo.parsePath)(t);
105
- this.pathname = s.pathname, this.search = s.search, this.#e = s.hash;
107
+ this.pathname = s.pathname, this.search = s.search, this.#h = s.hash;
106
108
  }
107
109
  get path() {
108
110
  return (0, _ufo.stringifyParsedURL)({
package/dist/url.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ParsedURL } from "ufo";
2
- import type { IStormURL, StormURLBuilderOptions } from "./types";
2
+ import type { IStormURL, StormURLOptions } from "./types";
3
3
  /**
4
4
  * A class used to build URLs
5
5
  *
@@ -10,7 +10,7 @@ import type { IStormURL, StormURLBuilderOptions } from "./types";
10
10
  */
11
11
  export declare class StormURL implements IStormURL, Partial<URL> {
12
12
  #private;
13
- constructor(initialURL: string, options?: StormURLBuilderOptions);
13
+ constructor(initialURL: string, options?: StormURLOptions);
14
14
  set params(value: Record<string, any>);
15
15
  get params(): Record<string, any>;
16
16
  get searchParams(): URLSearchParams;
package/dist/url.mjs CHANGED
@@ -1 +1 @@
1
- import{StormJSON as o}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{isUndefined as l}from"@stryke/type-checks/is-undefined";import{cleanDoubleSlashes as d,decode as b,isEqual as R,isNonEmptyURL as S,isRelative as f,isSamePath as U,isScriptProtocol as L,normalizeURL as P,parseAuth as n,parseHost as p,parsePath as y,parseQuery as c,parseURL as u,stringifyParsedURL as e,stringifyQuery as $}from"ufo";export class StormURL{#h;#i;#r;#t;#s;#a;#o=[];#e;#n;constructor(t,s={decode:!0}){this.#h=s;const i=u(this.#h.decode?b(t):t),h=n(i.auth);this.#i=h.username,this.#r=h.password;const a=p(i.host);this.#t=a.hostname,this.#s=a.port,this.#a=i.protocol,this.#e=i.hash||"",this.#n=c(i.search),this.#o=i.pathname?i.pathname.split("/").filter(Boolean):[]}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=$(this.params);return t?t.startsWith("?")?t:`?${t}`:""}set hash(t){this.#e=t.startsWith("#")?t:`#${t}`}get hash(){return this.#e}set port(t){this.#s=!l(t)&&g(t)?`${t}`:void 0}get port(){return this.#s}set auth(t){const s=n(t);this.#i=s.username,this.#r=s.password}get auth(){return this.#i&&this.#r?`${this.#i}:${this.#r}`:this.#i?this.#i:this.#r?this.#r:""}set protocol(t){this.#a=t.endsWith(":")?t:t.endsWith("://")?t.slice(0,-2):`${t}:`}get protocol(){return this.#a||this.#h.defaultProtocol||"https:"}set hostname(t){this.#t=t}get hostname(){return this.#t}set host(t){const s=p(t);this.#t=s.hostname,this.#s=s.port}get host(){return this.#t&&this.#s?`${this.#t}:${this.#s}`:this.#t?this.#t:this.#s?this.#s:""}set paths(t){this.#o=t.filter(Boolean)}get paths(){return this.#o}set pathname(t){this.paths=d(t).split("/")}get pathname(){return`/${this.paths?m(...this.paths.map(t=>o.stringify(t))):""}`}set path(t){const s=y(t);this.pathname=s.pathname,this.search=s.search,this.#e=s.hash}get path(){return e({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 L(this.protocol)}get isRelative(){return f(this.toString())}get isNonEmptyURL(){return S(this.toString())}get __typename(){return"StormURL"}isSamePath(t){return U(this.path,t)}isEqual(t){return R(this.toString(),typeof t=="string"?t:t instanceof StormURL?t.toString():e(t))}toParsed(){return{protocol:this.protocol,auth:this.auth,host:this.host,pathname:this.pathname,search:this.search,hash:this.hash}}toString(){return e(this.toParsed())}toEncoded(){return P(this.toString())}}o.instance.registerCustom({isApplicable:r=>r.__typename==="StormURL",serialize:r=>r.toEncoded(),deserialize:r=>new StormURL(r,{decode:!0})},"StormURL");
1
+ import{StormJSON as o}from"@stryke/json/storm-json";import{joinPaths as m}from"@stryke/path/join-paths";import{isInteger as l}from"@stryke/type-checks/is-integer";import{isSetString as g}from"@stryke/type-checks/is-set-string";import{isUndefined as d}from"@stryke/type-checks/is-undefined";import{cleanDoubleSlashes as b,decode as f,isEqual as R,isNonEmptyURL as S,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 e,stringifyQuery as E}from"ufo";import{formatLocalePath as O}from"./helpers";export class StormURL{#a;#i;#r;#t;#s;#o;#e=[];#h;#n;constructor(t,s={decode:!0}){this.#a=s;const i=u(this.#a.decode?f(t):t),h=n(i.auth);this.#i=h.username,this.#r=h.password;const a=p(i.host);this.#t=a.hostname,this.#s=a.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((g(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.#s=!d(t)&&l(t)?`${t}`:void 0}get port(){return this.#s}set auth(t){const s=n(t);this.#i=s.username,this.#r=s.password}get auth(){return this.#i&&this.#r?`${this.#i}:${this.#r}`:this.#i?this.#i:this.#r?this.#r:""}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.#t=t}get hostname(){return this.#t}set host(t){const s=p(t);this.#t=s.hostname,this.#s=s.port}get host(){return this.#t&&this.#s?`${this.#t}:${this.#s}`:this.#t?this.#t:this.#s?this.#s:""}set paths(t){this.#e=t.filter(Boolean)}get paths(){return this.#e}set pathname(t){this.paths=b(t).split("/")}get pathname(){return`/${this.paths?m(...this.paths.map(t=>o.stringify(t))):""}`}set path(t){const s=$(t);this.pathname=s.pathname,this.search=s.search,this.#h=s.hash}get path(){return e({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 S(this.toString())}get __typename(){return"StormURL"}isSamePath(t){return U(this.path,t)}isEqual(t){return R(this.toString(),typeof t=="string"?t:t instanceof StormURL?t.toString():e(t))}toParsed(){return{protocol:this.protocol,auth:this.auth,host:this.host,pathname:this.pathname,search:this.search,hash:this.hash}}toString(){return e(this.toParsed())}toEncoded(){return y(this.toString())}}o.instance.registerCustom({isApplicable:r=>r.__typename==="StormURL",serialize:r=>r.toEncoded(),deserialize:r=>new StormURL(r,{decode:!0})},"StormURL");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/http",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "A package containing HTTP communication utilities used by Storm Software.",
6
6
  "repository": {
@@ -81,6 +81,20 @@
81
81
  },
82
82
  "default": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" }
83
83
  },
84
+ "./helpers": {
85
+ "import": {
86
+ "types": "./dist/helpers.d.ts",
87
+ "default": "./dist/helpers.mjs"
88
+ },
89
+ "require": {
90
+ "types": "./dist/helpers.d.ts",
91
+ "default": "./dist/helpers.cjs"
92
+ },
93
+ "default": {
94
+ "types": "./dist/helpers.d.ts",
95
+ "default": "./dist/helpers.mjs"
96
+ }
97
+ },
84
98
  "./format-data-uri": {
85
99
  "import": {
86
100
  "types": "./dist/format-data-uri.d.ts",