File tree Expand file tree Collapse file tree 3 files changed +15
-9
lines changed
Expand file tree Collapse file tree 3 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,10 @@ declare type AjaxRequestInit = RequestInit & {
1111 */
1212export declare const defaultInit : Partial < AjaxRequestInit > & {
1313 headers : Record < string , string > ;
14+ url ?: Partial < AjaxURLObject > ;
1415} ;
1516declare type URLComponent = string | number | boolean | null | undefined ;
16- /**
17- * A valid URL for an ajax request. Can either directly be a string representing a raw URL or a object to safely build it (recommended).
18- */
19- export declare type AjaxURL = string | {
17+ declare type AjaxURLObject = {
2018 /**
2119 * The base URL of the request.
2220 * Example: `https://www.sahnee.games/request?param1=true¶ms2=hello%20world¶m2=second#test`
@@ -70,6 +68,10 @@ export declare type AjaxURL = string | {
7068 [ key : string ] : URLComponent | URLComponent [ ] ;
7169 } ;
7270} ;
71+ /**
72+ * A valid URL for an ajax request. Can either directly be a string representing a raw URL or a object to safely build it (recommended).
73+ */
74+ export declare type AjaxURL = string | AjaxURLObject ;
7375/**
7476 * Helper for inline building a URL.
7577 * @param url The URL.
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ exports.url = function (p) {
9595 if ( typeof p === 'string' ) {
9696 return p ;
9797 }
98+ p = Object . assign ( { } , exports . defaultInit . url , p ) ;
9899 var url = '' ;
99100 if ( Array . isArray ( p . url ) ) {
100101 url = p . url
Original file line number Diff line number Diff line change @@ -20,16 +20,13 @@ const JSON_CONTENT_TYPE_UTF8 = JSON_CONTENT_TYPE_BASIC + '; charset=utf-8';
2020/**
2121 * Default options for every request.
2222 */
23- export const defaultInit : Partial < AjaxRequestInit > & { headers : Record < string , string > } = {
23+ export const defaultInit : Partial < AjaxRequestInit > & { headers : Record < string , string > , url ?: Partial < AjaxURLObject > } = {
2424 headers : { }
2525} ;
2626
2727type URLComponent = string | number | boolean | null | undefined ;
2828
29- /**
30- * A valid URL for an ajax request. Can either directly be a string representing a raw URL or a object to safely build it (recommended).
31- */
32- export type AjaxURL = string | {
29+ type AjaxURLObject = {
3330 /**
3431 * The base URL of the request.
3532 * Example: `https://www.sahnee.games/request?param1=true¶ms2=hello%20world¶m2=second#test`
@@ -91,6 +88,11 @@ export type AjaxURL = string | {
9188 }
9289} ;
9390
91+ /**
92+ * A valid URL for an ajax request. Can either directly be a string representing a raw URL or a object to safely build it (recommended).
93+ */
94+ export type AjaxURL = string | AjaxURLObject
95+
9496/**
9597 * Helper for inline building a URL.
9698 * @param url The URL.
@@ -100,6 +102,7 @@ export const url = (p: AjaxURL) => {
100102 if ( typeof p === 'string' ) {
101103 return p ;
102104 }
105+ p = Object . assign ( { } , defaultInit . url , p ) ;
103106 let url = '' ;
104107 if ( Array . isArray ( p . url ) ) {
105108 url = p . url
You can’t perform that action at this time.
0 commit comments