@wordpress/url 3.3.0 → 3.3.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.
@@ -29,7 +29,10 @@ var _buildQueryString = require("./build-query-string");
29
29
  *
30
30
  * @return {string} URL with arguments applied.
31
31
  */
32
- function addQueryArgs(url = '', args) {
32
+ function addQueryArgs() {
33
+ let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
34
+ let args = arguments.length > 1 ? arguments[1] : undefined;
35
+
33
36
  // If no arguments are to be appended, return original URL.
34
37
  if (!args || !Object.keys(args).length) {
35
38
  return url;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,CAAuBC,GAAG,GAAG,EAA7B,EAAiCC,IAAjC,EAAwC;AAC9C;AACA,MAAK,CAAEA,IAAF,IAAU,CAAEC,MAAM,CAACC,IAAP,CAAaF,IAAb,EAAoBG,MAArC,EAA8C;AAC7C,WAAOJ,GAAP;AACA;;AAED,MAAIK,OAAO,GAAGL,GAAd,CAN8C,CAQ9C;;AACA,QAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B;AACAL,IAAAA,IAAI,GAAGC,MAAM,CAACM,MAAP,CAAe,gCAAcR,GAAd,CAAf,EAAoCC,IAApC,CAAP,CAF8B,CAI9B;;AACAI,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAR,CAAgB,CAAhB,EAAmBH,gBAAnB,CAAV;AACA;;AAED,SAAOD,OAAO,GAAG,GAAV,GAAgB,wCAAkBJ,IAAlB,CAAvB;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Appends arguments as querystring to the provided URL. If the URL already\n * includes query arguments, the arguments are merged with (and take precedent\n * over) the existing set.\n *\n * @param {string} [url=''] URL to which arguments should be appended. If omitted,\n * only the resulting querystring is returned.\n * @param {Object} [args] Query arguments to apply to URL.\n *\n * @example\n * ```js\n * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test\n * ```\n *\n * @return {string} URL with arguments applied.\n */\nexport function addQueryArgs( url = '', args ) {\n\t// If no arguments are to be appended, return original URL.\n\tif ( ! args || ! Object.keys( args ).length ) {\n\t\treturn url;\n\t}\n\n\tlet baseUrl = url;\n\n\t// Determine whether URL already had query arguments.\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex !== -1 ) {\n\t\t// Merge into existing query arguments.\n\t\targs = Object.assign( getQueryArgs( url ), args );\n\n\t\t// Change working base URL to omit previous query arguments.\n\t\tbaseUrl = baseUrl.substr( 0, queryStringIndex );\n\t}\n\n\treturn baseUrl + '?' + buildQueryString( args );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,YAAT,GAAwC;AAAA,MAAjBC,GAAiB,uEAAX,EAAW;AAAA,MAAPC,IAAO;;AAC9C;AACA,MAAK,CAAEA,IAAF,IAAU,CAAEC,MAAM,CAACC,IAAP,CAAaF,IAAb,EAAoBG,MAArC,EAA8C;AAC7C,WAAOJ,GAAP;AACA;;AAED,MAAIK,OAAO,GAAGL,GAAd,CAN8C,CAQ9C;;AACA,QAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B;AACAL,IAAAA,IAAI,GAAGC,MAAM,CAACM,MAAP,CAAe,gCAAcR,GAAd,CAAf,EAAoCC,IAApC,CAAP,CAF8B,CAI9B;;AACAI,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAR,CAAgB,CAAhB,EAAmBH,gBAAnB,CAAV;AACA;;AAED,SAAOD,OAAO,GAAG,GAAV,GAAgB,wCAAkBJ,IAAlB,CAAvB;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Appends arguments as querystring to the provided URL. If the URL already\n * includes query arguments, the arguments are merged with (and take precedent\n * over) the existing set.\n *\n * @param {string} [url=''] URL to which arguments should be appended. If omitted,\n * only the resulting querystring is returned.\n * @param {Object} [args] Query arguments to apply to URL.\n *\n * @example\n * ```js\n * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test\n * ```\n *\n * @return {string} URL with arguments applied.\n */\nexport function addQueryArgs( url = '', args ) {\n\t// If no arguments are to be appended, return original URL.\n\tif ( ! args || ! Object.keys( args ).length ) {\n\t\treturn url;\n\t}\n\n\tlet baseUrl = url;\n\n\t// Determine whether URL already had query arguments.\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex !== -1 ) {\n\t\t// Merge into existing query arguments.\n\t\targs = Object.assign( getQueryArgs( url ), args );\n\n\t\t// Change working base URL to omit previous query arguments.\n\t\tbaseUrl = baseUrl.substr( 0, queryStringIndex );\n\t}\n\n\treturn baseUrl + '?' + buildQueryString( args );\n}\n"]}
@@ -19,7 +19,8 @@ exports.filterURLForDisplay = filterURLForDisplay;
19
19
  *
20
20
  * @return {string} Displayed URL.
21
21
  */
22
- function filterURLForDisplay(url, maxLength = null) {
22
+ function filterURLForDisplay(url) {
23
+ let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
23
24
  // Remove protocol and www prefixes.
24
25
  let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
25
26
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,SAAS,GAAG,IAA/C,EAAsD;AAC5D;AACA,MAAIC,WAAW,GAAGF,GAAG,CAACG,OAAJ,CAAa,4BAAb,EAA2C,EAA3C,CAAlB,CAF4D,CAI5D;;AACA,MAAKD,WAAW,CAACE,KAAZ,CAAmB,YAAnB,CAAL,EAAyC;AACxCF,IAAAA,WAAW,GAAGA,WAAW,CAACC,OAAZ,CAAqB,GAArB,EAA0B,EAA1B,CAAd;AACA;;AAED,QAAME,WAAW,GAAG,qCAApB;;AAEA,MACC,CAAEJ,SAAF,IACAC,WAAW,CAACI,MAAZ,IAAsBL,SADtB,IAEA,CAAEC,WAAW,CAACE,KAAZ,CAAmBC,WAAnB,CAHH,EAIE;AACD,WAAOH,WAAP;AACA,GAjB2D,CAmB5D;;;AACAA,EAAAA,WAAW,GAAGA,WAAW,CAACK,KAAZ,CAAmB,GAAnB,EAA0B,CAA1B,CAAd;AACA,QAAMC,SAAS,GAAGN,WAAW,CAACK,KAAZ,CAAmB,GAAnB,CAAlB;AACA,QAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAV,GAAmB,CAArB,CAAtB;;AACA,MAAKG,IAAI,CAACH,MAAL,IAAeL,SAApB,EAAgC;AAC/B,WAAO,MAAMC,WAAW,CAACQ,KAAZ,CAAmB,CAACT,SAApB,CAAb;AACA,GAzB2D,CA2B5D;;;AACA,QAAMU,KAAK,GAAGF,IAAI,CAACG,WAAL,CAAkB,GAAlB,CAAd;AACA,QAAM,CAAEC,QAAF,EAAYC,SAAZ,IAA0B,CAC/BL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeC,KAAf,CAD+B,EAE/BF,IAAI,CAACC,KAAL,CAAYC,KAAK,GAAG,CAApB,CAF+B,CAAhC;AAIA,QAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAT,CAAgB,CAAC,CAAjB,IAAuB,GAAvB,GAA6BI,SAAnD;AACA,SACCL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeT,SAAS,GAAGc,aAAa,CAACT,MAA1B,GAAmC,CAAlD,IACA,GADA,GAEAS,aAHD;AAKA","sourcesContent":["/**\n * Returns a URL for display.\n *\n * @param {string} url Original URL.\n * @param {number|null} maxLength URL length.\n *\n * @example\n * ```js\n * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg\n * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png\n * ```\n *\n * @return {string} Displayed URL.\n */\nexport function filterURLForDisplay( url, maxLength = null ) {\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url.replace( /^(?:https?:)\\/\\/(?:www\\.)?/, '' );\n\n\t// Ends with / and only has that single slash, strip it.\n\tif ( filteredURL.match( /^[^\\/]+\\/$/ ) ) {\n\t\tfilteredURL = filteredURL.replace( '/', '' );\n\t}\n\n\tconst mediaRegexp = /([\\w|:])*\\.(?:jpg|jpeg|gif|png|svg)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( mediaRegexp )\n\t) {\n\t\treturn filteredURL;\n\t}\n\n\t// If the file is not greater than max length, return last portion of URL.\n\tfilteredURL = filteredURL.split( '?' )[ 0 ];\n\tconst urlPieces = filteredURL.split( '/' );\n\tconst file = urlPieces[ urlPieces.length - 1 ];\n\tif ( file.length <= maxLength ) {\n\t\treturn '…' + filteredURL.slice( -maxLength );\n\t}\n\n\t// If the file is greater than max length, truncate the file.\n\tconst index = file.lastIndexOf( '.' );\n\tconst [ fileName, extension ] = [\n\t\tfile.slice( 0, index ),\n\t\tfile.slice( index + 1 ),\n\t];\n\tconst truncatedFile = fileName.slice( -3 ) + '.' + extension;\n\treturn (\n\t\tfile.slice( 0, maxLength - truncatedFile.length - 1 ) +\n\t\t'…' +\n\t\ttruncatedFile\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAT,CAA8BC,GAA9B,EAAsD;AAAA,MAAnBC,SAAmB,uEAAP,IAAO;AAC5D;AACA,MAAIC,WAAW,GAAGF,GAAG,CAACG,OAAJ,CAAa,4BAAb,EAA2C,EAA3C,CAAlB,CAF4D,CAI5D;;AACA,MAAKD,WAAW,CAACE,KAAZ,CAAmB,YAAnB,CAAL,EAAyC;AACxCF,IAAAA,WAAW,GAAGA,WAAW,CAACC,OAAZ,CAAqB,GAArB,EAA0B,EAA1B,CAAd;AACA;;AAED,QAAME,WAAW,GAAG,qCAApB;;AAEA,MACC,CAAEJ,SAAF,IACAC,WAAW,CAACI,MAAZ,IAAsBL,SADtB,IAEA,CAAEC,WAAW,CAACE,KAAZ,CAAmBC,WAAnB,CAHH,EAIE;AACD,WAAOH,WAAP;AACA,GAjB2D,CAmB5D;;;AACAA,EAAAA,WAAW,GAAGA,WAAW,CAACK,KAAZ,CAAmB,GAAnB,EAA0B,CAA1B,CAAd;AACA,QAAMC,SAAS,GAAGN,WAAW,CAACK,KAAZ,CAAmB,GAAnB,CAAlB;AACA,QAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAV,GAAmB,CAArB,CAAtB;;AACA,MAAKG,IAAI,CAACH,MAAL,IAAeL,SAApB,EAAgC;AAC/B,WAAO,MAAMC,WAAW,CAACQ,KAAZ,CAAmB,CAACT,SAApB,CAAb;AACA,GAzB2D,CA2B5D;;;AACA,QAAMU,KAAK,GAAGF,IAAI,CAACG,WAAL,CAAkB,GAAlB,CAAd;AACA,QAAM,CAAEC,QAAF,EAAYC,SAAZ,IAA0B,CAC/BL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeC,KAAf,CAD+B,EAE/BF,IAAI,CAACC,KAAL,CAAYC,KAAK,GAAG,CAApB,CAF+B,CAAhC;AAIA,QAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAT,CAAgB,CAAC,CAAjB,IAAuB,GAAvB,GAA6BI,SAAnD;AACA,SACCL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeT,SAAS,GAAGc,aAAa,CAACT,MAA1B,GAAmC,CAAlD,IACA,GADA,GAEAS,aAHD;AAKA","sourcesContent":["/**\n * Returns a URL for display.\n *\n * @param {string} url Original URL.\n * @param {number|null} maxLength URL length.\n *\n * @example\n * ```js\n * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg\n * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png\n * ```\n *\n * @return {string} Displayed URL.\n */\nexport function filterURLForDisplay( url, maxLength = null ) {\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url.replace( /^(?:https?:)\\/\\/(?:www\\.)?/, '' );\n\n\t// Ends with / and only has that single slash, strip it.\n\tif ( filteredURL.match( /^[^\\/]+\\/$/ ) ) {\n\t\tfilteredURL = filteredURL.replace( '/', '' );\n\t}\n\n\tconst mediaRegexp = /([\\w|:])*\\.(?:jpg|jpeg|gif|png|svg)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( mediaRegexp )\n\t) {\n\t\treturn filteredURL;\n\t}\n\n\t// If the file is not greater than max length, return last portion of URL.\n\tfilteredURL = filteredURL.split( '?' )[ 0 ];\n\tconst urlPieces = filteredURL.split( '/' );\n\tconst file = urlPieces[ urlPieces.length - 1 ];\n\tif ( file.length <= maxLength ) {\n\t\treturn '…' + filteredURL.slice( -maxLength );\n\t}\n\n\t// If the file is greater than max length, truncate the file.\n\tconst index = file.lastIndexOf( '.' );\n\tconst [ fileName, extension ] = [\n\t\tfile.slice( 0, index ),\n\t\tfile.slice( index + 1 ),\n\t];\n\tconst truncatedFile = fileName.slice( -3 ) + '.' + extension;\n\treturn (\n\t\tfile.slice( 0, maxLength - truncatedFile.length - 1 ) +\n\t\t'…' +\n\t\ttruncatedFile\n\t);\n}\n"]}
@@ -74,11 +74,11 @@ function setPath(object, path, value) {
74
74
 
75
75
 
76
76
  function getQueryArgs(url) {
77
- return ((0, _getQueryString.getQueryString)(url) || ''). // Normalize space encoding, accounting for PHP URL encoding
77
+ return ((0, _getQueryString.getQueryString)(url) || '' // Normalize space encoding, accounting for PHP URL encoding
78
78
  // corresponding to `application/x-www-form-urlencoded`.
79
79
  //
80
80
  // See: https://tools.ietf.org/html/rfc1866#section-8.2.1
81
- replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
81
+ ).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
82
82
  const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
83
83
  // default is restored in destructuring assignment.
84
84
  .filter(Boolean).map(decodeURIComponent);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/get-query-args.js"],"names":["setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","decodeURIComponent","segments"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAT,CAAkBC,MAAlB,EAA0BC,IAA1B,EAAgCC,KAAhC,EAAwC;AACvC,QAAMC,MAAM,GAAGF,IAAI,CAACE,MAApB;AACA,QAAMC,SAAS,GAAGD,MAAM,GAAG,CAA3B;;AACA,OAAM,IAAIE,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGF,MAArB,EAA6BE,CAAC,EAA9B,EAAmC;AAClC,QAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAF,CAAd;;AAEA,QAAK,CAAEC,GAAF,IAASC,KAAK,CAACC,OAAN,CAAeR,MAAf,CAAd,EAAwC;AACvC;AACA;AACAM,MAAAA,GAAG,GAAGN,MAAM,CAACG,MAAP,CAAcM,QAAd,EAAN;AACA,KAPiC,CASlC;AACA;;;AACA,UAAMC,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEX,IAAI,CAAEI,CAAC,GAAG,CAAN,CAAN,CAAR,CAAnC;AAEAL,IAAAA,MAAM,CAAEM,GAAF,CAAN,GACCD,CAAC,KAAKD,SAAN,GACG;AACAF,IAAAA,KAFH,GAGG;AACA;AACAF,IAAAA,MAAM,CAAEM,GAAF,CAAN,KAAmBI,mBAAmB,GAAG,EAAH,GAAQ,EAA9C,CANJ;;AAQA,QAAKH,KAAK,CAACC,OAAN,CAAeR,MAAM,CAAEM,GAAF,CAArB,KAAkC,CAAEI,mBAAzC,EAA+D;AAC9D;AACA;AACAV,MAAAA,MAAM,CAAEM,GAAF,CAAN,GAAgB,EAAE,GAAGN,MAAM,CAAEM,GAAF;AAAX,OAAhB;AACA,KAzBiC,CA2BlC;;;AACAN,IAAAA,MAAM,GAAGA,MAAM,CAAEM,GAAF,CAAf;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SACC,CAAE,oCAAgBA,GAAhB,KAAyB,EAA3B,GACC;AACA;AACA;AACA;AACCC,EAAAA,OALF,CAKW,KALX,EAKkB,KALlB,EAMEC,KANF,CAMS,GANT,EAOEC,MAPF,CAOU,CAAEC,WAAF,EAAeC,QAAf,KAA6B;AACrC,UAAM,CAAEb,GAAF,EAAOJ,KAAK,GAAG,EAAf,IAAsBiB,QAAQ,CAClCH,KAD0B,CACnB,GADmB,EAE3B;AACA;AAH2B,KAI1BI,MAJ0B,CAIlBC,OAJkB,EAK1BC,GAL0B,CAKrBC,kBALqB,CAA5B;;AAOA,QAAKjB,GAAL,EAAW;AACV,YAAMkB,QAAQ,GAAGlB,GAAG,CAACS,OAAJ,CAAa,KAAb,EAAoB,EAApB,EAAyBC,KAAzB,CAAgC,GAAhC,CAAjB;AACAjB,MAAAA,OAAO,CAAEmB,WAAF,EAAeM,QAAf,EAAyBtB,KAAzB,CAAP;AACA;;AAED,WAAOgB,WAAP;AACA,GArBF,EAqBI,EArBJ,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryString } from './get-query-string';\n\n/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */\n\n/**\n * @typedef {Record<string,QueryArgParsed>} QueryArgs\n */\n\n/**\n * Sets a value in object deeply by a given array of path segments. Mutates the\n * object reference.\n *\n * @param {Record<string,*>} object Object in which to assign.\n * @param {string[]} path Path segment at which to set value.\n * @param {*} value Value to set.\n */\nfunction setPath( object, path, value ) {\n\tconst length = path.length;\n\tconst lastIndex = length - 1;\n\tfor ( let i = 0; i < length; i++ ) {\n\t\tlet key = path[ i ];\n\n\t\tif ( ! key && Array.isArray( object ) ) {\n\t\t\t// If key is empty string and next value is array, derive key from\n\t\t\t// the current length of the array.\n\t\t\tkey = object.length.toString();\n\t\t}\n\n\t\t// If the next key in the path is numeric (or empty string), it will be\n\t\t// created as an array. Otherwise, it will be created as an object.\n\t\tconst isNextKeyArrayIndex = ! isNaN( Number( path[ i + 1 ] ) );\n\n\t\tobject[ key ] =\n\t\t\ti === lastIndex\n\t\t\t\t? // If at end of path, assign the intended value.\n\t\t\t\t value\n\t\t\t\t: // Otherwise, advance to the next object in the path, creating\n\t\t\t\t // it if it does not yet exist.\n\t\t\t\t object[ key ] || ( isNextKeyArrayIndex ? [] : {} );\n\n\t\tif ( Array.isArray( object[ key ] ) && ! isNextKeyArrayIndex ) {\n\t\t\t// If we current key is non-numeric, but the next value is an\n\t\t\t// array, coerce the value to an object.\n\t\t\tobject[ key ] = { ...object[ key ] };\n\t\t}\n\n\t\t// Update working reference object to the next in the path.\n\t\tobject = object[ key ];\n\t}\n}\n\n/**\n * Returns an object of query arguments of the given URL. If the given URL is\n * invalid or has no querystring, an empty object is returned.\n *\n * @param {string} url URL.\n *\n * @example\n * ```js\n * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );\n * // { \"foo\": \"bar\", \"bar\": \"baz\" }\n * ```\n *\n * @return {QueryArgs} Query args object.\n */\nexport function getQueryArgs( url ) {\n\treturn (\n\t\t( getQueryString( url ) || '' )\n\t\t\t// Normalize space encoding, accounting for PHP URL encoding\n\t\t\t// corresponding to `application/x-www-form-urlencoded`.\n\t\t\t//\n\t\t\t// See: https://tools.ietf.org/html/rfc1866#section-8.2.1\n\t\t\t.replace( /\\+/g, '%20' )\n\t\t\t.split( '&' )\n\t\t\t.reduce( ( accumulator, keyValue ) => {\n\t\t\t\tconst [ key, value = '' ] = keyValue\n\t\t\t\t\t.split( '=' )\n\t\t\t\t\t// Filtering avoids decoding as `undefined` for value, where\n\t\t\t\t\t// default is restored in destructuring assignment.\n\t\t\t\t\t.filter( Boolean )\n\t\t\t\t\t.map( decodeURIComponent );\n\n\t\t\t\tif ( key ) {\n\t\t\t\t\tconst segments = key.replace( /\\]/g, '' ).split( '[' );\n\t\t\t\t\tsetPath( accumulator, segments, value );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t}, {} )\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/get-query-args.js"],"names":["setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","decodeURIComponent","segments"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAT,CAAkBC,MAAlB,EAA0BC,IAA1B,EAAgCC,KAAhC,EAAwC;AACvC,QAAMC,MAAM,GAAGF,IAAI,CAACE,MAApB;AACA,QAAMC,SAAS,GAAGD,MAAM,GAAG,CAA3B;;AACA,OAAM,IAAIE,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGF,MAArB,EAA6BE,CAAC,EAA9B,EAAmC;AAClC,QAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAF,CAAd;;AAEA,QAAK,CAAEC,GAAF,IAASC,KAAK,CAACC,OAAN,CAAeR,MAAf,CAAd,EAAwC;AACvC;AACA;AACAM,MAAAA,GAAG,GAAGN,MAAM,CAACG,MAAP,CAAcM,QAAd,EAAN;AACA,KAPiC,CASlC;AACA;;;AACA,UAAMC,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEX,IAAI,CAAEI,CAAC,GAAG,CAAN,CAAN,CAAR,CAAnC;AAEAL,IAAAA,MAAM,CAAEM,GAAF,CAAN,GACCD,CAAC,KAAKD,SAAN,GACG;AACAF,IAAAA,KAFH,GAGG;AACA;AACAF,IAAAA,MAAM,CAAEM,GAAF,CAAN,KAAmBI,mBAAmB,GAAG,EAAH,GAAQ,EAA9C,CANJ;;AAQA,QAAKH,KAAK,CAACC,OAAN,CAAeR,MAAM,CAAEM,GAAF,CAArB,KAAkC,CAAEI,mBAAzC,EAA+D;AAC9D;AACA;AACAV,MAAAA,MAAM,CAAEM,GAAF,CAAN,GAAgB,EAAE,GAAGN,MAAM,CAAEM,GAAF;AAAX,OAAhB;AACA,KAzBiC,CA2BlC;;;AACAN,IAAAA,MAAM,GAAGA,MAAM,CAAEM,GAAF,CAAf;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SACC,CAAE,oCAAgBA,GAAhB,KAAyB,EAA3B,CACC;AACA;AACA;AACA;AAJD,IAKEC,OALF,CAKW,KALX,EAKkB,KALlB,EAMEC,KANF,CAMS,GANT,EAOEC,MAPF,CAOU,CAAEC,WAAF,EAAeC,QAAf,KAA6B;AACrC,UAAM,CAAEb,GAAF,EAAOJ,KAAK,GAAG,EAAf,IAAsBiB,QAAQ,CAClCH,KAD0B,CACnB,GADmB,EAE3B;AACA;AAH2B,KAI1BI,MAJ0B,CAIlBC,OAJkB,EAK1BC,GAL0B,CAKrBC,kBALqB,CAA5B;;AAOA,QAAKjB,GAAL,EAAW;AACV,YAAMkB,QAAQ,GAAGlB,GAAG,CAACS,OAAJ,CAAa,KAAb,EAAoB,EAApB,EAAyBC,KAAzB,CAAgC,GAAhC,CAAjB;AACAjB,MAAAA,OAAO,CAAEmB,WAAF,EAAeM,QAAf,EAAyBtB,KAAzB,CAAP;AACA;;AAED,WAAOgB,WAAP;AACA,GArBF,EAqBI,EArBJ,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryString } from './get-query-string';\n\n/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */\n\n/**\n * @typedef {Record<string,QueryArgParsed>} QueryArgs\n */\n\n/**\n * Sets a value in object deeply by a given array of path segments. Mutates the\n * object reference.\n *\n * @param {Record<string,*>} object Object in which to assign.\n * @param {string[]} path Path segment at which to set value.\n * @param {*} value Value to set.\n */\nfunction setPath( object, path, value ) {\n\tconst length = path.length;\n\tconst lastIndex = length - 1;\n\tfor ( let i = 0; i < length; i++ ) {\n\t\tlet key = path[ i ];\n\n\t\tif ( ! key && Array.isArray( object ) ) {\n\t\t\t// If key is empty string and next value is array, derive key from\n\t\t\t// the current length of the array.\n\t\t\tkey = object.length.toString();\n\t\t}\n\n\t\t// If the next key in the path is numeric (or empty string), it will be\n\t\t// created as an array. Otherwise, it will be created as an object.\n\t\tconst isNextKeyArrayIndex = ! isNaN( Number( path[ i + 1 ] ) );\n\n\t\tobject[ key ] =\n\t\t\ti === lastIndex\n\t\t\t\t? // If at end of path, assign the intended value.\n\t\t\t\t value\n\t\t\t\t: // Otherwise, advance to the next object in the path, creating\n\t\t\t\t // it if it does not yet exist.\n\t\t\t\t object[ key ] || ( isNextKeyArrayIndex ? [] : {} );\n\n\t\tif ( Array.isArray( object[ key ] ) && ! isNextKeyArrayIndex ) {\n\t\t\t// If we current key is non-numeric, but the next value is an\n\t\t\t// array, coerce the value to an object.\n\t\t\tobject[ key ] = { ...object[ key ] };\n\t\t}\n\n\t\t// Update working reference object to the next in the path.\n\t\tobject = object[ key ];\n\t}\n}\n\n/**\n * Returns an object of query arguments of the given URL. If the given URL is\n * invalid or has no querystring, an empty object is returned.\n *\n * @param {string} url URL.\n *\n * @example\n * ```js\n * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );\n * // { \"foo\": \"bar\", \"bar\": \"baz\" }\n * ```\n *\n * @return {QueryArgs} Query args object.\n */\nexport function getQueryArgs( url ) {\n\treturn (\n\t\t( getQueryString( url ) || '' )\n\t\t\t// Normalize space encoding, accounting for PHP URL encoding\n\t\t\t// corresponding to `application/x-www-form-urlencoded`.\n\t\t\t//\n\t\t\t// See: https://tools.ietf.org/html/rfc1866#section-8.2.1\n\t\t\t.replace( /\\+/g, '%20' )\n\t\t\t.split( '&' )\n\t\t\t.reduce( ( accumulator, keyValue ) => {\n\t\t\t\tconst [ key, value = '' ] = keyValue\n\t\t\t\t\t.split( '=' )\n\t\t\t\t\t// Filtering avoids decoding as `undefined` for value, where\n\t\t\t\t\t// default is restored in destructuring assignment.\n\t\t\t\t\t.filter( Boolean )\n\t\t\t\t\t.map( decodeURIComponent );\n\n\t\t\t\tif ( key ) {\n\t\t\t\t\tconst segments = key.replace( /\\]/g, '' ).split( '[' );\n\t\t\t\t\tsetPath( accumulator, segments, value );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t}, {} )\n\t);\n}\n"]}
package/build/index.js CHANGED
@@ -3,28 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "isURL", {
6
+ Object.defineProperty(exports, "addQueryArgs", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _isUrl.isURL;
9
+ return _addQueryArgs.addQueryArgs;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "isEmail", {
12
+ Object.defineProperty(exports, "buildQueryString", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _isEmail.isEmail;
15
+ return _buildQueryString.buildQueryString;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "getProtocol", {
18
+ Object.defineProperty(exports, "cleanForSlug", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _getProtocol.getProtocol;
21
+ return _cleanForSlug.cleanForSlug;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "isValidProtocol", {
24
+ Object.defineProperty(exports, "filterURLForDisplay", {
25
25
  enumerable: true,
26
26
  get: function () {
27
- return _isValidProtocol.isValidProtocol;
27
+ return _filterUrlForDisplay.filterURLForDisplay;
28
28
  }
29
29
  });
30
30
  Object.defineProperty(exports, "getAuthority", {
@@ -33,130 +33,130 @@ Object.defineProperty(exports, "getAuthority", {
33
33
  return _getAuthority.getAuthority;
34
34
  }
35
35
  });
36
- Object.defineProperty(exports, "isValidAuthority", {
36
+ Object.defineProperty(exports, "getFilename", {
37
37
  enumerable: true,
38
38
  get: function () {
39
- return _isValidAuthority.isValidAuthority;
39
+ return _getFilename.getFilename;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "getPath", {
42
+ Object.defineProperty(exports, "getFragment", {
43
43
  enumerable: true,
44
44
  get: function () {
45
- return _getPath.getPath;
45
+ return _getFragment.getFragment;
46
46
  }
47
47
  });
48
- Object.defineProperty(exports, "isValidPath", {
48
+ Object.defineProperty(exports, "getPath", {
49
49
  enumerable: true,
50
50
  get: function () {
51
- return _isValidPath.isValidPath;
51
+ return _getPath.getPath;
52
52
  }
53
53
  });
54
- Object.defineProperty(exports, "getQueryString", {
54
+ Object.defineProperty(exports, "getPathAndQueryString", {
55
55
  enumerable: true,
56
56
  get: function () {
57
- return _getQueryString.getQueryString;
57
+ return _getPathAndQueryString.getPathAndQueryString;
58
58
  }
59
59
  });
60
- Object.defineProperty(exports, "buildQueryString", {
60
+ Object.defineProperty(exports, "getProtocol", {
61
61
  enumerable: true,
62
62
  get: function () {
63
- return _buildQueryString.buildQueryString;
63
+ return _getProtocol.getProtocol;
64
64
  }
65
65
  });
66
- Object.defineProperty(exports, "isValidQueryString", {
66
+ Object.defineProperty(exports, "getQueryArg", {
67
67
  enumerable: true,
68
68
  get: function () {
69
- return _isValidQueryString.isValidQueryString;
69
+ return _getQueryArg.getQueryArg;
70
70
  }
71
71
  });
72
- Object.defineProperty(exports, "getPathAndQueryString", {
72
+ Object.defineProperty(exports, "getQueryArgs", {
73
73
  enumerable: true,
74
74
  get: function () {
75
- return _getPathAndQueryString.getPathAndQueryString;
75
+ return _getQueryArgs.getQueryArgs;
76
76
  }
77
77
  });
78
- Object.defineProperty(exports, "getFragment", {
78
+ Object.defineProperty(exports, "getQueryString", {
79
79
  enumerable: true,
80
80
  get: function () {
81
- return _getFragment.getFragment;
81
+ return _getQueryString.getQueryString;
82
82
  }
83
83
  });
84
- Object.defineProperty(exports, "isValidFragment", {
84
+ Object.defineProperty(exports, "hasQueryArg", {
85
85
  enumerable: true,
86
86
  get: function () {
87
- return _isValidFragment.isValidFragment;
87
+ return _hasQueryArg.hasQueryArg;
88
88
  }
89
89
  });
90
- Object.defineProperty(exports, "addQueryArgs", {
90
+ Object.defineProperty(exports, "isEmail", {
91
91
  enumerable: true,
92
92
  get: function () {
93
- return _addQueryArgs.addQueryArgs;
93
+ return _isEmail.isEmail;
94
94
  }
95
95
  });
96
- Object.defineProperty(exports, "getQueryArg", {
96
+ Object.defineProperty(exports, "isURL", {
97
97
  enumerable: true,
98
98
  get: function () {
99
- return _getQueryArg.getQueryArg;
99
+ return _isUrl.isURL;
100
100
  }
101
101
  });
102
- Object.defineProperty(exports, "getQueryArgs", {
102
+ Object.defineProperty(exports, "isValidAuthority", {
103
103
  enumerable: true,
104
104
  get: function () {
105
- return _getQueryArgs.getQueryArgs;
105
+ return _isValidAuthority.isValidAuthority;
106
106
  }
107
107
  });
108
- Object.defineProperty(exports, "hasQueryArg", {
108
+ Object.defineProperty(exports, "isValidFragment", {
109
109
  enumerable: true,
110
110
  get: function () {
111
- return _hasQueryArg.hasQueryArg;
111
+ return _isValidFragment.isValidFragment;
112
112
  }
113
113
  });
114
- Object.defineProperty(exports, "removeQueryArgs", {
114
+ Object.defineProperty(exports, "isValidPath", {
115
115
  enumerable: true,
116
116
  get: function () {
117
- return _removeQueryArgs.removeQueryArgs;
117
+ return _isValidPath.isValidPath;
118
118
  }
119
119
  });
120
- Object.defineProperty(exports, "prependHTTP", {
120
+ Object.defineProperty(exports, "isValidProtocol", {
121
121
  enumerable: true,
122
122
  get: function () {
123
- return _prependHttp.prependHTTP;
123
+ return _isValidProtocol.isValidProtocol;
124
124
  }
125
125
  });
126
- Object.defineProperty(exports, "safeDecodeURI", {
126
+ Object.defineProperty(exports, "isValidQueryString", {
127
127
  enumerable: true,
128
128
  get: function () {
129
- return _safeDecodeUri.safeDecodeURI;
129
+ return _isValidQueryString.isValidQueryString;
130
130
  }
131
131
  });
132
- Object.defineProperty(exports, "safeDecodeURIComponent", {
132
+ Object.defineProperty(exports, "normalizePath", {
133
133
  enumerable: true,
134
134
  get: function () {
135
- return _safeDecodeUriComponent.safeDecodeURIComponent;
135
+ return _normalizePath.normalizePath;
136
136
  }
137
137
  });
138
- Object.defineProperty(exports, "filterURLForDisplay", {
138
+ Object.defineProperty(exports, "prependHTTP", {
139
139
  enumerable: true,
140
140
  get: function () {
141
- return _filterUrlForDisplay.filterURLForDisplay;
141
+ return _prependHttp.prependHTTP;
142
142
  }
143
143
  });
144
- Object.defineProperty(exports, "cleanForSlug", {
144
+ Object.defineProperty(exports, "removeQueryArgs", {
145
145
  enumerable: true,
146
146
  get: function () {
147
- return _cleanForSlug.cleanForSlug;
147
+ return _removeQueryArgs.removeQueryArgs;
148
148
  }
149
149
  });
150
- Object.defineProperty(exports, "getFilename", {
150
+ Object.defineProperty(exports, "safeDecodeURI", {
151
151
  enumerable: true,
152
152
  get: function () {
153
- return _getFilename.getFilename;
153
+ return _safeDecodeUri.safeDecodeURI;
154
154
  }
155
155
  });
156
- Object.defineProperty(exports, "normalizePath", {
156
+ Object.defineProperty(exports, "safeDecodeURIComponent", {
157
157
  enumerable: true,
158
158
  get: function () {
159
- return _normalizePath.normalizePath;
159
+ return _safeDecodeUriComponent.safeDecodeURIComponent;
160
160
  }
161
161
  });
162
162
 
@@ -26,7 +26,7 @@ var _buildQueryString = require("./build-query-string");
26
26
  *
27
27
  * @return {string} Updated URL.
28
28
  */
29
- function removeQueryArgs(url, ...args) {
29
+ function removeQueryArgs(url) {
30
30
  const queryStringIndex = url.indexOf('?');
31
31
 
32
32
  if (queryStringIndex === -1) {
@@ -35,6 +35,11 @@ function removeQueryArgs(url, ...args) {
35
35
 
36
36
  const query = (0, _getQueryArgs.getQueryArgs)(url);
37
37
  const baseURL = url.substr(0, queryStringIndex);
38
+
39
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
40
+ args[_key - 1] = arguments[_key];
41
+ }
42
+
38
43
  args.forEach(arg => delete query[arg]);
39
44
  const queryString = (0, _buildQueryString.buildQueryString)(query);
40
45
  return queryString ? baseURL + '?' + queryString : baseURL;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/remove-query-args.js"],"names":["removeQueryArgs","url","args","queryStringIndex","indexOf","query","baseURL","substr","forEach","arg","queryString"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,GAA1B,EAA+B,GAAGC,IAAlC,EAAyC;AAC/C,QAAMC,gBAAgB,GAAGF,GAAG,CAACG,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B,WAAOF,GAAP;AACA;;AAED,QAAMI,KAAK,GAAG,gCAAcJ,GAAd,CAAd;AACA,QAAMK,OAAO,GAAGL,GAAG,CAACM,MAAJ,CAAY,CAAZ,EAAeJ,gBAAf,CAAhB;AACAD,EAAAA,IAAI,CAACM,OAAL,CAAgBC,GAAF,IAAW,OAAOJ,KAAK,CAAEI,GAAF,CAArC;AACA,QAAMC,WAAW,GAAG,wCAAkBL,KAAlB,CAApB;AACA,SAAOK,WAAW,GAAGJ,OAAO,GAAG,GAAV,GAAgBI,WAAnB,GAAiCJ,OAAnD;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Removes arguments from the query string of the url\n *\n * @param {string} url URL.\n * @param {...string} args Query Args.\n *\n * @example\n * ```js\n * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar\n * ```\n *\n * @return {string} Updated URL.\n */\nexport function removeQueryArgs( url, ...args ) {\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex === -1 ) {\n\t\treturn url;\n\t}\n\n\tconst query = getQueryArgs( url );\n\tconst baseURL = url.substr( 0, queryStringIndex );\n\targs.forEach( ( arg ) => delete query[ arg ] );\n\tconst queryString = buildQueryString( query );\n\treturn queryString ? baseURL + '?' + queryString : baseURL;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/remove-query-args.js"],"names":["removeQueryArgs","url","queryStringIndex","indexOf","query","baseURL","substr","args","forEach","arg","queryString"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,GAA1B,EAAyC;AAC/C,QAAMC,gBAAgB,GAAGD,GAAG,CAACE,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B,WAAOD,GAAP;AACA;;AAED,QAAMG,KAAK,GAAG,gCAAcH,GAAd,CAAd;AACA,QAAMI,OAAO,GAAGJ,GAAG,CAACK,MAAJ,CAAY,CAAZ,EAAeJ,gBAAf,CAAhB;;AAP+C,oCAAPK,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAQ/CA,EAAAA,IAAI,CAACC,OAAL,CAAgBC,GAAF,IAAW,OAAOL,KAAK,CAAEK,GAAF,CAArC;AACA,QAAMC,WAAW,GAAG,wCAAkBN,KAAlB,CAApB;AACA,SAAOM,WAAW,GAAGL,OAAO,GAAG,GAAV,GAAgBK,WAAnB,GAAiCL,OAAnD;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Removes arguments from the query string of the url\n *\n * @param {string} url URL.\n * @param {...string} args Query Args.\n *\n * @example\n * ```js\n * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar\n * ```\n *\n * @return {string} Updated URL.\n */\nexport function removeQueryArgs( url, ...args ) {\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex === -1 ) {\n\t\treturn url;\n\t}\n\n\tconst query = getQueryArgs( url );\n\tconst baseURL = url.substr( 0, queryStringIndex );\n\targs.forEach( ( arg ) => delete query[ arg ] );\n\tconst queryString = buildQueryString( query );\n\treturn queryString ? baseURL + '?' + queryString : baseURL;\n}\n"]}
@@ -20,7 +20,10 @@ import { buildQueryString } from './build-query-string';
20
20
  * @return {string} URL with arguments applied.
21
21
  */
22
22
 
23
- export function addQueryArgs(url = '', args) {
23
+ export function addQueryArgs() {
24
+ let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
25
+ let args = arguments.length > 1 ? arguments[1] : undefined;
26
+
24
27
  // If no arguments are to be appended, return original URL.
25
28
  if (!args || !Object.keys(args).length) {
26
29
  return url;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["getQueryArgs","buildQueryString","addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,kBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CAAuBC,GAAG,GAAG,EAA7B,EAAiCC,IAAjC,EAAwC;AAC9C;AACA,MAAK,CAAEA,IAAF,IAAU,CAAEC,MAAM,CAACC,IAAP,CAAaF,IAAb,EAAoBG,MAArC,EAA8C;AAC7C,WAAOJ,GAAP;AACA;;AAED,MAAIK,OAAO,GAAGL,GAAd,CAN8C,CAQ9C;;AACA,QAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B;AACAL,IAAAA,IAAI,GAAGC,MAAM,CAACM,MAAP,CAAeX,YAAY,CAAEG,GAAF,CAA3B,EAAoCC,IAApC,CAAP,CAF8B,CAI9B;;AACAI,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAR,CAAgB,CAAhB,EAAmBH,gBAAnB,CAAV;AACA;;AAED,SAAOD,OAAO,GAAG,GAAV,GAAgBP,gBAAgB,CAAEG,IAAF,CAAvC;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Appends arguments as querystring to the provided URL. If the URL already\n * includes query arguments, the arguments are merged with (and take precedent\n * over) the existing set.\n *\n * @param {string} [url=''] URL to which arguments should be appended. If omitted,\n * only the resulting querystring is returned.\n * @param {Object} [args] Query arguments to apply to URL.\n *\n * @example\n * ```js\n * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test\n * ```\n *\n * @return {string} URL with arguments applied.\n */\nexport function addQueryArgs( url = '', args ) {\n\t// If no arguments are to be appended, return original URL.\n\tif ( ! args || ! Object.keys( args ).length ) {\n\t\treturn url;\n\t}\n\n\tlet baseUrl = url;\n\n\t// Determine whether URL already had query arguments.\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex !== -1 ) {\n\t\t// Merge into existing query arguments.\n\t\targs = Object.assign( getQueryArgs( url ), args );\n\n\t\t// Change working base URL to omit previous query arguments.\n\t\tbaseUrl = baseUrl.substr( 0, queryStringIndex );\n\t}\n\n\treturn baseUrl + '?' + buildQueryString( args );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/add-query-args.js"],"names":["getQueryArgs","buildQueryString","addQueryArgs","url","args","Object","keys","length","baseUrl","queryStringIndex","indexOf","assign","substr"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,kBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAAwC;AAAA,MAAjBC,GAAiB,uEAAX,EAAW;AAAA,MAAPC,IAAO;;AAC9C;AACA,MAAK,CAAEA,IAAF,IAAU,CAAEC,MAAM,CAACC,IAAP,CAAaF,IAAb,EAAoBG,MAArC,EAA8C;AAC7C,WAAOJ,GAAP;AACA;;AAED,MAAIK,OAAO,GAAGL,GAAd,CAN8C,CAQ9C;;AACA,QAAMM,gBAAgB,GAAGN,GAAG,CAACO,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B;AACAL,IAAAA,IAAI,GAAGC,MAAM,CAACM,MAAP,CAAeX,YAAY,CAAEG,GAAF,CAA3B,EAAoCC,IAApC,CAAP,CAF8B,CAI9B;;AACAI,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAR,CAAgB,CAAhB,EAAmBH,gBAAnB,CAAV;AACA;;AAED,SAAOD,OAAO,GAAG,GAAV,GAAgBP,gBAAgB,CAAEG,IAAF,CAAvC;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Appends arguments as querystring to the provided URL. If the URL already\n * includes query arguments, the arguments are merged with (and take precedent\n * over) the existing set.\n *\n * @param {string} [url=''] URL to which arguments should be appended. If omitted,\n * only the resulting querystring is returned.\n * @param {Object} [args] Query arguments to apply to URL.\n *\n * @example\n * ```js\n * const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test\n * ```\n *\n * @return {string} URL with arguments applied.\n */\nexport function addQueryArgs( url = '', args ) {\n\t// If no arguments are to be appended, return original URL.\n\tif ( ! args || ! Object.keys( args ).length ) {\n\t\treturn url;\n\t}\n\n\tlet baseUrl = url;\n\n\t// Determine whether URL already had query arguments.\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex !== -1 ) {\n\t\t// Merge into existing query arguments.\n\t\targs = Object.assign( getQueryArgs( url ), args );\n\n\t\t// Change working base URL to omit previous query arguments.\n\t\tbaseUrl = baseUrl.substr( 0, queryStringIndex );\n\t}\n\n\treturn baseUrl + '?' + buildQueryString( args );\n}\n"]}
@@ -12,7 +12,8 @@
12
12
  *
13
13
  * @return {string} Displayed URL.
14
14
  */
15
- export function filterURLForDisplay(url, maxLength = null) {
15
+ export function filterURLForDisplay(url) {
16
+ let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
16
17
  // Remove protocol and www prefixes.
17
18
  let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
18
19
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,SAAS,GAAG,IAA/C,EAAsD;AAC5D;AACA,MAAIC,WAAW,GAAGF,GAAG,CAACG,OAAJ,CAAa,4BAAb,EAA2C,EAA3C,CAAlB,CAF4D,CAI5D;;AACA,MAAKD,WAAW,CAACE,KAAZ,CAAmB,YAAnB,CAAL,EAAyC;AACxCF,IAAAA,WAAW,GAAGA,WAAW,CAACC,OAAZ,CAAqB,GAArB,EAA0B,EAA1B,CAAd;AACA;;AAED,QAAME,WAAW,GAAG,qCAApB;;AAEA,MACC,CAAEJ,SAAF,IACAC,WAAW,CAACI,MAAZ,IAAsBL,SADtB,IAEA,CAAEC,WAAW,CAACE,KAAZ,CAAmBC,WAAnB,CAHH,EAIE;AACD,WAAOH,WAAP;AACA,GAjB2D,CAmB5D;;;AACAA,EAAAA,WAAW,GAAGA,WAAW,CAACK,KAAZ,CAAmB,GAAnB,EAA0B,CAA1B,CAAd;AACA,QAAMC,SAAS,GAAGN,WAAW,CAACK,KAAZ,CAAmB,GAAnB,CAAlB;AACA,QAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAV,GAAmB,CAArB,CAAtB;;AACA,MAAKG,IAAI,CAACH,MAAL,IAAeL,SAApB,EAAgC;AAC/B,WAAO,MAAMC,WAAW,CAACQ,KAAZ,CAAmB,CAACT,SAApB,CAAb;AACA,GAzB2D,CA2B5D;;;AACA,QAAMU,KAAK,GAAGF,IAAI,CAACG,WAAL,CAAkB,GAAlB,CAAd;AACA,QAAM,CAAEC,QAAF,EAAYC,SAAZ,IAA0B,CAC/BL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeC,KAAf,CAD+B,EAE/BF,IAAI,CAACC,KAAL,CAAYC,KAAK,GAAG,CAApB,CAF+B,CAAhC;AAIA,QAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAT,CAAgB,CAAC,CAAjB,IAAuB,GAAvB,GAA6BI,SAAnD;AACA,SACCL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeT,SAAS,GAAGc,aAAa,CAACT,MAA1B,GAAmC,CAAlD,IACA,GADA,GAEAS,aAHD;AAKA","sourcesContent":["/**\n * Returns a URL for display.\n *\n * @param {string} url Original URL.\n * @param {number|null} maxLength URL length.\n *\n * @example\n * ```js\n * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg\n * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png\n * ```\n *\n * @return {string} Displayed URL.\n */\nexport function filterURLForDisplay( url, maxLength = null ) {\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url.replace( /^(?:https?:)\\/\\/(?:www\\.)?/, '' );\n\n\t// Ends with / and only has that single slash, strip it.\n\tif ( filteredURL.match( /^[^\\/]+\\/$/ ) ) {\n\t\tfilteredURL = filteredURL.replace( '/', '' );\n\t}\n\n\tconst mediaRegexp = /([\\w|:])*\\.(?:jpg|jpeg|gif|png|svg)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( mediaRegexp )\n\t) {\n\t\treturn filteredURL;\n\t}\n\n\t// If the file is not greater than max length, return last portion of URL.\n\tfilteredURL = filteredURL.split( '?' )[ 0 ];\n\tconst urlPieces = filteredURL.split( '/' );\n\tconst file = urlPieces[ urlPieces.length - 1 ];\n\tif ( file.length <= maxLength ) {\n\t\treturn '…' + filteredURL.slice( -maxLength );\n\t}\n\n\t// If the file is greater than max length, truncate the file.\n\tconst index = file.lastIndexOf( '.' );\n\tconst [ fileName, extension ] = [\n\t\tfile.slice( 0, index ),\n\t\tfile.slice( index + 1 ),\n\t];\n\tconst truncatedFile = fileName.slice( -3 ) + '.' + extension;\n\treturn (\n\t\tfile.slice( 0, maxLength - truncatedFile.length - 1 ) +\n\t\t'…' +\n\t\ttruncatedFile\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/filter-url-for-display.js"],"names":["filterURLForDisplay","url","maxLength","filteredURL","replace","match","mediaRegexp","length","split","urlPieces","file","slice","index","lastIndexOf","fileName","extension","truncatedFile"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,mBAAT,CAA8BC,GAA9B,EAAsD;AAAA,MAAnBC,SAAmB,uEAAP,IAAO;AAC5D;AACA,MAAIC,WAAW,GAAGF,GAAG,CAACG,OAAJ,CAAa,4BAAb,EAA2C,EAA3C,CAAlB,CAF4D,CAI5D;;AACA,MAAKD,WAAW,CAACE,KAAZ,CAAmB,YAAnB,CAAL,EAAyC;AACxCF,IAAAA,WAAW,GAAGA,WAAW,CAACC,OAAZ,CAAqB,GAArB,EAA0B,EAA1B,CAAd;AACA;;AAED,QAAME,WAAW,GAAG,qCAApB;;AAEA,MACC,CAAEJ,SAAF,IACAC,WAAW,CAACI,MAAZ,IAAsBL,SADtB,IAEA,CAAEC,WAAW,CAACE,KAAZ,CAAmBC,WAAnB,CAHH,EAIE;AACD,WAAOH,WAAP;AACA,GAjB2D,CAmB5D;;;AACAA,EAAAA,WAAW,GAAGA,WAAW,CAACK,KAAZ,CAAmB,GAAnB,EAA0B,CAA1B,CAAd;AACA,QAAMC,SAAS,GAAGN,WAAW,CAACK,KAAZ,CAAmB,GAAnB,CAAlB;AACA,QAAME,IAAI,GAAGD,SAAS,CAAEA,SAAS,CAACF,MAAV,GAAmB,CAArB,CAAtB;;AACA,MAAKG,IAAI,CAACH,MAAL,IAAeL,SAApB,EAAgC;AAC/B,WAAO,MAAMC,WAAW,CAACQ,KAAZ,CAAmB,CAACT,SAApB,CAAb;AACA,GAzB2D,CA2B5D;;;AACA,QAAMU,KAAK,GAAGF,IAAI,CAACG,WAAL,CAAkB,GAAlB,CAAd;AACA,QAAM,CAAEC,QAAF,EAAYC,SAAZ,IAA0B,CAC/BL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeC,KAAf,CAD+B,EAE/BF,IAAI,CAACC,KAAL,CAAYC,KAAK,GAAG,CAApB,CAF+B,CAAhC;AAIA,QAAMI,aAAa,GAAGF,QAAQ,CAACH,KAAT,CAAgB,CAAC,CAAjB,IAAuB,GAAvB,GAA6BI,SAAnD;AACA,SACCL,IAAI,CAACC,KAAL,CAAY,CAAZ,EAAeT,SAAS,GAAGc,aAAa,CAACT,MAA1B,GAAmC,CAAlD,IACA,GADA,GAEAS,aAHD;AAKA","sourcesContent":["/**\n * Returns a URL for display.\n *\n * @param {string} url Original URL.\n * @param {number|null} maxLength URL length.\n *\n * @example\n * ```js\n * const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg\n * const imageUrl = filterURLForDisplay( 'https://www.wordpress.org/wp-content/uploads/img.png', 20 ); // …ent/uploads/img.png\n * ```\n *\n * @return {string} Displayed URL.\n */\nexport function filterURLForDisplay( url, maxLength = null ) {\n\t// Remove protocol and www prefixes.\n\tlet filteredURL = url.replace( /^(?:https?:)\\/\\/(?:www\\.)?/, '' );\n\n\t// Ends with / and only has that single slash, strip it.\n\tif ( filteredURL.match( /^[^\\/]+\\/$/ ) ) {\n\t\tfilteredURL = filteredURL.replace( '/', '' );\n\t}\n\n\tconst mediaRegexp = /([\\w|:])*\\.(?:jpg|jpeg|gif|png|svg)/;\n\n\tif (\n\t\t! maxLength ||\n\t\tfilteredURL.length <= maxLength ||\n\t\t! filteredURL.match( mediaRegexp )\n\t) {\n\t\treturn filteredURL;\n\t}\n\n\t// If the file is not greater than max length, return last portion of URL.\n\tfilteredURL = filteredURL.split( '?' )[ 0 ];\n\tconst urlPieces = filteredURL.split( '/' );\n\tconst file = urlPieces[ urlPieces.length - 1 ];\n\tif ( file.length <= maxLength ) {\n\t\treturn '…' + filteredURL.slice( -maxLength );\n\t}\n\n\t// If the file is greater than max length, truncate the file.\n\tconst index = file.lastIndexOf( '.' );\n\tconst [ fileName, extension ] = [\n\t\tfile.slice( 0, index ),\n\t\tfile.slice( index + 1 ),\n\t];\n\tconst truncatedFile = fileName.slice( -3 ) + '.' + extension;\n\treturn (\n\t\tfile.slice( 0, maxLength - truncatedFile.length - 1 ) +\n\t\t'…' +\n\t\ttruncatedFile\n\t);\n}\n"]}
@@ -66,11 +66,11 @@ function setPath(object, path, value) {
66
66
 
67
67
 
68
68
  export function getQueryArgs(url) {
69
- return (getQueryString(url) || ''). // Normalize space encoding, accounting for PHP URL encoding
69
+ return (getQueryString(url) || '' // Normalize space encoding, accounting for PHP URL encoding
70
70
  // corresponding to `application/x-www-form-urlencoded`.
71
71
  //
72
72
  // See: https://tools.ietf.org/html/rfc1866#section-8.2.1
73
- replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
73
+ ).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
74
74
  const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
75
75
  // default is restored in destructuring assignment.
76
76
  .filter(Boolean).map(decodeURIComponent);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/get-query-args.js"],"names":["getQueryString","setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","decodeURIComponent","segments"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAT,QAA+B,oBAA/B;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,OAAT,CAAkBC,MAAlB,EAA0BC,IAA1B,EAAgCC,KAAhC,EAAwC;AACvC,QAAMC,MAAM,GAAGF,IAAI,CAACE,MAApB;AACA,QAAMC,SAAS,GAAGD,MAAM,GAAG,CAA3B;;AACA,OAAM,IAAIE,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGF,MAArB,EAA6BE,CAAC,EAA9B,EAAmC;AAClC,QAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAF,CAAd;;AAEA,QAAK,CAAEC,GAAF,IAASC,KAAK,CAACC,OAAN,CAAeR,MAAf,CAAd,EAAwC;AACvC;AACA;AACAM,MAAAA,GAAG,GAAGN,MAAM,CAACG,MAAP,CAAcM,QAAd,EAAN;AACA,KAPiC,CASlC;AACA;;;AACA,UAAMC,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEX,IAAI,CAAEI,CAAC,GAAG,CAAN,CAAN,CAAR,CAAnC;AAEAL,IAAAA,MAAM,CAAEM,GAAF,CAAN,GACCD,CAAC,KAAKD,SAAN,GACG;AACAF,IAAAA,KAFH,GAGG;AACA;AACAF,IAAAA,MAAM,CAAEM,GAAF,CAAN,KAAmBI,mBAAmB,GAAG,EAAH,GAAQ,EAA9C,CANJ;;AAQA,QAAKH,KAAK,CAACC,OAAN,CAAeR,MAAM,CAAEM,GAAF,CAArB,KAAkC,CAAEI,mBAAzC,EAA+D;AAC9D;AACA;AACAV,MAAAA,MAAM,CAAEM,GAAF,CAAN,GAAgB,EAAE,GAAGN,MAAM,CAAEM,GAAF;AAAX,OAAhB;AACA,KAzBiC,CA2BlC;;;AACAN,IAAAA,MAAM,GAAGA,MAAM,CAAEM,GAAF,CAAf;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASO,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SACC,CAAEhB,cAAc,CAAEgB,GAAF,CAAd,IAAyB,EAA3B,GACC;AACA;AACA;AACA;AACCC,EAAAA,OALF,CAKW,KALX,EAKkB,KALlB,EAMEC,KANF,CAMS,GANT,EAOEC,MAPF,CAOU,CAAEC,WAAF,EAAeC,QAAf,KAA6B;AACrC,UAAM,CAAEb,GAAF,EAAOJ,KAAK,GAAG,EAAf,IAAsBiB,QAAQ,CAClCH,KAD0B,CACnB,GADmB,EAE3B;AACA;AAH2B,KAI1BI,MAJ0B,CAIlBC,OAJkB,EAK1BC,GAL0B,CAKrBC,kBALqB,CAA5B;;AAOA,QAAKjB,GAAL,EAAW;AACV,YAAMkB,QAAQ,GAAGlB,GAAG,CAACS,OAAJ,CAAa,KAAb,EAAoB,EAApB,EAAyBC,KAAzB,CAAgC,GAAhC,CAAjB;AACAjB,MAAAA,OAAO,CAAEmB,WAAF,EAAeM,QAAf,EAAyBtB,KAAzB,CAAP;AACA;;AAED,WAAOgB,WAAP;AACA,GArBF,EAqBI,EArBJ,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryString } from './get-query-string';\n\n/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */\n\n/**\n * @typedef {Record<string,QueryArgParsed>} QueryArgs\n */\n\n/**\n * Sets a value in object deeply by a given array of path segments. Mutates the\n * object reference.\n *\n * @param {Record<string,*>} object Object in which to assign.\n * @param {string[]} path Path segment at which to set value.\n * @param {*} value Value to set.\n */\nfunction setPath( object, path, value ) {\n\tconst length = path.length;\n\tconst lastIndex = length - 1;\n\tfor ( let i = 0; i < length; i++ ) {\n\t\tlet key = path[ i ];\n\n\t\tif ( ! key && Array.isArray( object ) ) {\n\t\t\t// If key is empty string and next value is array, derive key from\n\t\t\t// the current length of the array.\n\t\t\tkey = object.length.toString();\n\t\t}\n\n\t\t// If the next key in the path is numeric (or empty string), it will be\n\t\t// created as an array. Otherwise, it will be created as an object.\n\t\tconst isNextKeyArrayIndex = ! isNaN( Number( path[ i + 1 ] ) );\n\n\t\tobject[ key ] =\n\t\t\ti === lastIndex\n\t\t\t\t? // If at end of path, assign the intended value.\n\t\t\t\t value\n\t\t\t\t: // Otherwise, advance to the next object in the path, creating\n\t\t\t\t // it if it does not yet exist.\n\t\t\t\t object[ key ] || ( isNextKeyArrayIndex ? [] : {} );\n\n\t\tif ( Array.isArray( object[ key ] ) && ! isNextKeyArrayIndex ) {\n\t\t\t// If we current key is non-numeric, but the next value is an\n\t\t\t// array, coerce the value to an object.\n\t\t\tobject[ key ] = { ...object[ key ] };\n\t\t}\n\n\t\t// Update working reference object to the next in the path.\n\t\tobject = object[ key ];\n\t}\n}\n\n/**\n * Returns an object of query arguments of the given URL. If the given URL is\n * invalid or has no querystring, an empty object is returned.\n *\n * @param {string} url URL.\n *\n * @example\n * ```js\n * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );\n * // { \"foo\": \"bar\", \"bar\": \"baz\" }\n * ```\n *\n * @return {QueryArgs} Query args object.\n */\nexport function getQueryArgs( url ) {\n\treturn (\n\t\t( getQueryString( url ) || '' )\n\t\t\t// Normalize space encoding, accounting for PHP URL encoding\n\t\t\t// corresponding to `application/x-www-form-urlencoded`.\n\t\t\t//\n\t\t\t// See: https://tools.ietf.org/html/rfc1866#section-8.2.1\n\t\t\t.replace( /\\+/g, '%20' )\n\t\t\t.split( '&' )\n\t\t\t.reduce( ( accumulator, keyValue ) => {\n\t\t\t\tconst [ key, value = '' ] = keyValue\n\t\t\t\t\t.split( '=' )\n\t\t\t\t\t// Filtering avoids decoding as `undefined` for value, where\n\t\t\t\t\t// default is restored in destructuring assignment.\n\t\t\t\t\t.filter( Boolean )\n\t\t\t\t\t.map( decodeURIComponent );\n\n\t\t\t\tif ( key ) {\n\t\t\t\t\tconst segments = key.replace( /\\]/g, '' ).split( '[' );\n\t\t\t\t\tsetPath( accumulator, segments, value );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t}, {} )\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/get-query-args.js"],"names":["getQueryString","setPath","object","path","value","length","lastIndex","i","key","Array","isArray","toString","isNextKeyArrayIndex","isNaN","Number","getQueryArgs","url","replace","split","reduce","accumulator","keyValue","filter","Boolean","map","decodeURIComponent","segments"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAT,QAA+B,oBAA/B;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,OAAT,CAAkBC,MAAlB,EAA0BC,IAA1B,EAAgCC,KAAhC,EAAwC;AACvC,QAAMC,MAAM,GAAGF,IAAI,CAACE,MAApB;AACA,QAAMC,SAAS,GAAGD,MAAM,GAAG,CAA3B;;AACA,OAAM,IAAIE,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGF,MAArB,EAA6BE,CAAC,EAA9B,EAAmC;AAClC,QAAIC,GAAG,GAAGL,IAAI,CAAEI,CAAF,CAAd;;AAEA,QAAK,CAAEC,GAAF,IAASC,KAAK,CAACC,OAAN,CAAeR,MAAf,CAAd,EAAwC;AACvC;AACA;AACAM,MAAAA,GAAG,GAAGN,MAAM,CAACG,MAAP,CAAcM,QAAd,EAAN;AACA,KAPiC,CASlC;AACA;;;AACA,UAAMC,mBAAmB,GAAG,CAAEC,KAAK,CAAEC,MAAM,CAAEX,IAAI,CAAEI,CAAC,GAAG,CAAN,CAAN,CAAR,CAAnC;AAEAL,IAAAA,MAAM,CAAEM,GAAF,CAAN,GACCD,CAAC,KAAKD,SAAN,GACG;AACAF,IAAAA,KAFH,GAGG;AACA;AACAF,IAAAA,MAAM,CAAEM,GAAF,CAAN,KAAmBI,mBAAmB,GAAG,EAAH,GAAQ,EAA9C,CANJ;;AAQA,QAAKH,KAAK,CAACC,OAAN,CAAeR,MAAM,CAAEM,GAAF,CAArB,KAAkC,CAAEI,mBAAzC,EAA+D;AAC9D;AACA;AACAV,MAAAA,MAAM,CAAEM,GAAF,CAAN,GAAgB,EAAE,GAAGN,MAAM,CAAEM,GAAF;AAAX,OAAhB;AACA,KAzBiC,CA2BlC;;;AACAN,IAAAA,MAAM,GAAGA,MAAM,CAAEM,GAAF,CAAf;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASO,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SACC,CAAEhB,cAAc,CAAEgB,GAAF,CAAd,IAAyB,EAA3B,CACC;AACA;AACA;AACA;AAJD,IAKEC,OALF,CAKW,KALX,EAKkB,KALlB,EAMEC,KANF,CAMS,GANT,EAOEC,MAPF,CAOU,CAAEC,WAAF,EAAeC,QAAf,KAA6B;AACrC,UAAM,CAAEb,GAAF,EAAOJ,KAAK,GAAG,EAAf,IAAsBiB,QAAQ,CAClCH,KAD0B,CACnB,GADmB,EAE3B;AACA;AAH2B,KAI1BI,MAJ0B,CAIlBC,OAJkB,EAK1BC,GAL0B,CAKrBC,kBALqB,CAA5B;;AAOA,QAAKjB,GAAL,EAAW;AACV,YAAMkB,QAAQ,GAAGlB,GAAG,CAACS,OAAJ,CAAa,KAAb,EAAoB,EAApB,EAAyBC,KAAzB,CAAgC,GAAhC,CAAjB;AACAjB,MAAAA,OAAO,CAAEmB,WAAF,EAAeM,QAAf,EAAyBtB,KAAzB,CAAP;AACA;;AAED,WAAOgB,WAAP;AACA,GArBF,EAqBI,EArBJ,CADD;AAwBA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryString } from './get-query-string';\n\n/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */\n\n/**\n * @typedef {Record<string,QueryArgParsed>} QueryArgs\n */\n\n/**\n * Sets a value in object deeply by a given array of path segments. Mutates the\n * object reference.\n *\n * @param {Record<string,*>} object Object in which to assign.\n * @param {string[]} path Path segment at which to set value.\n * @param {*} value Value to set.\n */\nfunction setPath( object, path, value ) {\n\tconst length = path.length;\n\tconst lastIndex = length - 1;\n\tfor ( let i = 0; i < length; i++ ) {\n\t\tlet key = path[ i ];\n\n\t\tif ( ! key && Array.isArray( object ) ) {\n\t\t\t// If key is empty string and next value is array, derive key from\n\t\t\t// the current length of the array.\n\t\t\tkey = object.length.toString();\n\t\t}\n\n\t\t// If the next key in the path is numeric (or empty string), it will be\n\t\t// created as an array. Otherwise, it will be created as an object.\n\t\tconst isNextKeyArrayIndex = ! isNaN( Number( path[ i + 1 ] ) );\n\n\t\tobject[ key ] =\n\t\t\ti === lastIndex\n\t\t\t\t? // If at end of path, assign the intended value.\n\t\t\t\t value\n\t\t\t\t: // Otherwise, advance to the next object in the path, creating\n\t\t\t\t // it if it does not yet exist.\n\t\t\t\t object[ key ] || ( isNextKeyArrayIndex ? [] : {} );\n\n\t\tif ( Array.isArray( object[ key ] ) && ! isNextKeyArrayIndex ) {\n\t\t\t// If we current key is non-numeric, but the next value is an\n\t\t\t// array, coerce the value to an object.\n\t\t\tobject[ key ] = { ...object[ key ] };\n\t\t}\n\n\t\t// Update working reference object to the next in the path.\n\t\tobject = object[ key ];\n\t}\n}\n\n/**\n * Returns an object of query arguments of the given URL. If the given URL is\n * invalid or has no querystring, an empty object is returned.\n *\n * @param {string} url URL.\n *\n * @example\n * ```js\n * const foo = getQueryArgs( 'https://wordpress.org?foo=bar&bar=baz' );\n * // { \"foo\": \"bar\", \"bar\": \"baz\" }\n * ```\n *\n * @return {QueryArgs} Query args object.\n */\nexport function getQueryArgs( url ) {\n\treturn (\n\t\t( getQueryString( url ) || '' )\n\t\t\t// Normalize space encoding, accounting for PHP URL encoding\n\t\t\t// corresponding to `application/x-www-form-urlencoded`.\n\t\t\t//\n\t\t\t// See: https://tools.ietf.org/html/rfc1866#section-8.2.1\n\t\t\t.replace( /\\+/g, '%20' )\n\t\t\t.split( '&' )\n\t\t\t.reduce( ( accumulator, keyValue ) => {\n\t\t\t\tconst [ key, value = '' ] = keyValue\n\t\t\t\t\t.split( '=' )\n\t\t\t\t\t// Filtering avoids decoding as `undefined` for value, where\n\t\t\t\t\t// default is restored in destructuring assignment.\n\t\t\t\t\t.filter( Boolean )\n\t\t\t\t\t.map( decodeURIComponent );\n\n\t\t\t\tif ( key ) {\n\t\t\t\t\tconst segments = key.replace( /\\]/g, '' ).split( '[' );\n\t\t\t\t\tsetPath( accumulator, segments, value );\n\t\t\t\t}\n\n\t\t\t\treturn accumulator;\n\t\t\t}, {} )\n\t);\n}\n"]}
@@ -17,7 +17,7 @@ import { buildQueryString } from './build-query-string';
17
17
  * @return {string} Updated URL.
18
18
  */
19
19
 
20
- export function removeQueryArgs(url, ...args) {
20
+ export function removeQueryArgs(url) {
21
21
  const queryStringIndex = url.indexOf('?');
22
22
 
23
23
  if (queryStringIndex === -1) {
@@ -26,6 +26,11 @@ export function removeQueryArgs(url, ...args) {
26
26
 
27
27
  const query = getQueryArgs(url);
28
28
  const baseURL = url.substr(0, queryStringIndex);
29
+
30
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
31
+ args[_key - 1] = arguments[_key];
32
+ }
33
+
29
34
  args.forEach(arg => delete query[arg]);
30
35
  const queryString = buildQueryString(query);
31
36
  return queryString ? baseURL + '?' + queryString : baseURL;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/url/src/remove-query-args.js"],"names":["getQueryArgs","buildQueryString","removeQueryArgs","url","args","queryStringIndex","indexOf","query","baseURL","substr","forEach","arg","queryString"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,kBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,GAA1B,EAA+B,GAAGC,IAAlC,EAAyC;AAC/C,QAAMC,gBAAgB,GAAGF,GAAG,CAACG,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B,WAAOF,GAAP;AACA;;AAED,QAAMI,KAAK,GAAGP,YAAY,CAAEG,GAAF,CAA1B;AACA,QAAMK,OAAO,GAAGL,GAAG,CAACM,MAAJ,CAAY,CAAZ,EAAeJ,gBAAf,CAAhB;AACAD,EAAAA,IAAI,CAACM,OAAL,CAAgBC,GAAF,IAAW,OAAOJ,KAAK,CAAEI,GAAF,CAArC;AACA,QAAMC,WAAW,GAAGX,gBAAgB,CAAEM,KAAF,CAApC;AACA,SAAOK,WAAW,GAAGJ,OAAO,GAAG,GAAV,GAAgBI,WAAnB,GAAiCJ,OAAnD;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Removes arguments from the query string of the url\n *\n * @param {string} url URL.\n * @param {...string} args Query Args.\n *\n * @example\n * ```js\n * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar\n * ```\n *\n * @return {string} Updated URL.\n */\nexport function removeQueryArgs( url, ...args ) {\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex === -1 ) {\n\t\treturn url;\n\t}\n\n\tconst query = getQueryArgs( url );\n\tconst baseURL = url.substr( 0, queryStringIndex );\n\targs.forEach( ( arg ) => delete query[ arg ] );\n\tconst queryString = buildQueryString( query );\n\treturn queryString ? baseURL + '?' + queryString : baseURL;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/url/src/remove-query-args.js"],"names":["getQueryArgs","buildQueryString","removeQueryArgs","url","queryStringIndex","indexOf","query","baseURL","substr","args","forEach","arg","queryString"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,kBAA7B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,GAA1B,EAAyC;AAC/C,QAAMC,gBAAgB,GAAGD,GAAG,CAACE,OAAJ,CAAa,GAAb,CAAzB;;AACA,MAAKD,gBAAgB,KAAK,CAAC,CAA3B,EAA+B;AAC9B,WAAOD,GAAP;AACA;;AAED,QAAMG,KAAK,GAAGN,YAAY,CAAEG,GAAF,CAA1B;AACA,QAAMI,OAAO,GAAGJ,GAAG,CAACK,MAAJ,CAAY,CAAZ,EAAeJ,gBAAf,CAAhB;;AAP+C,oCAAPK,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAQ/CA,EAAAA,IAAI,CAACC,OAAL,CAAgBC,GAAF,IAAW,OAAOL,KAAK,CAAEK,GAAF,CAArC;AACA,QAAMC,WAAW,GAAGX,gBAAgB,CAAEK,KAAF,CAApC;AACA,SAAOM,WAAW,GAAGL,OAAO,GAAG,GAAV,GAAgBK,WAAnB,GAAiCL,OAAnD;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getQueryArgs } from './get-query-args';\nimport { buildQueryString } from './build-query-string';\n\n/**\n * Removes arguments from the query string of the url\n *\n * @param {string} url URL.\n * @param {...string} args Query Args.\n *\n * @example\n * ```js\n * const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar\n * ```\n *\n * @return {string} Updated URL.\n */\nexport function removeQueryArgs( url, ...args ) {\n\tconst queryStringIndex = url.indexOf( '?' );\n\tif ( queryStringIndex === -1 ) {\n\t\treturn url;\n\t}\n\n\tconst query = getQueryArgs( url );\n\tconst baseURL = url.substr( 0, queryStringIndex );\n\targs.forEach( ( arg ) => delete query[ arg ] );\n\tconst queryString = buildQueryString( query );\n\treturn queryString ? baseURL + '?' + queryString : baseURL;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/url",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "WordPress URL utilities.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,11 +27,11 @@
27
27
  "types": "build-types",
28
28
  "sideEffects": false,
29
29
  "dependencies": {
30
- "@babel/runtime": "^7.13.10",
30
+ "@babel/runtime": "^7.16.0",
31
31
  "lodash": "^4.17.21"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "393c2b5533837fd637e998d23f0124c081a10df0"
36
+ "gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50"
37
37
  }