@wordpress/url
Advanced tools
@@ -23,3 +23,6 @@ /** | ||
| export function addQueryArgs(url = '', args) { | ||
| export function addQueryArgs() { | ||
| let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
| let args = arguments.length > 1 ? arguments[1] : undefined; | ||
| // If no arguments are to be appended, return original URL. | ||
@@ -26,0 +29,0 @@ if (!args || !Object.keys(args).length) { |
@@ -1,1 +0,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"]} | ||
| {"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"]} |
@@ -15,3 +15,4 @@ /** | ||
| */ | ||
| export function filterURLForDisplay(url, maxLength = null) { | ||
| export function filterURLForDisplay(url) { | ||
| let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
| // Remove protocol and www prefixes. | ||
@@ -18,0 +19,0 @@ let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it. |
@@ -1,1 +0,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"]} | ||
| {"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"]} |
@@ -69,7 +69,7 @@ /** | ||
| export function getQueryArgs(url) { | ||
| return (getQueryString(url) || ''). // Normalize space encoding, accounting for PHP URL encoding | ||
| return (getQueryString(url) || '' // Normalize space encoding, accounting for PHP URL encoding | ||
| // corresponding to `application/x-www-form-urlencoded`. | ||
| // | ||
| // See: https://tools.ietf.org/html/rfc1866#section-8.2.1 | ||
| replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => { | ||
| ).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => { | ||
| const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where | ||
@@ -76,0 +76,0 @@ // default is restored in destructuring assignment. |
@@ -1,1 +0,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;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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"]} | ||
| {"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"]} |
@@ -20,3 +20,3 @@ /** | ||
| export function removeQueryArgs(url, ...args) { | ||
| export function removeQueryArgs(url) { | ||
| const queryStringIndex = url.indexOf('?'); | ||
@@ -30,2 +30,7 @@ | ||
| const baseURL = url.substr(0, queryStringIndex); | ||
| for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
| args[_key - 1] = arguments[_key]; | ||
| } | ||
| args.forEach(arg => delete query[arg]); | ||
@@ -32,0 +37,0 @@ const queryString = buildQueryString(query); |
@@ -1,1 +0,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"]} | ||
| {"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"]} |
@@ -32,3 +32,6 @@ "use strict"; | ||
| */ | ||
| function addQueryArgs(url = '', args) { | ||
| function addQueryArgs() { | ||
| let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
| let args = arguments.length > 1 ? arguments[1] : undefined; | ||
| // If no arguments are to be appended, return original URL. | ||
@@ -35,0 +38,0 @@ if (!args || !Object.keys(args).length) { |
@@ -1,1 +0,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"]} | ||
| {"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"]} |
@@ -22,3 +22,4 @@ "use strict"; | ||
| */ | ||
| function filterURLForDisplay(url, maxLength = null) { | ||
| function filterURLForDisplay(url) { | ||
| let maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
| // Remove protocol and www prefixes. | ||
@@ -25,0 +26,0 @@ let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it. |
@@ -1,1 +0,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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,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"]} | ||
| {"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"]} |
@@ -77,7 +77,7 @@ "use strict"; | ||
| function getQueryArgs(url) { | ||
| return ((0, _getQueryString.getQueryString)(url) || ''). // Normalize space encoding, accounting for PHP URL encoding | ||
| return ((0, _getQueryString.getQueryString)(url) || '' // Normalize space encoding, accounting for PHP URL encoding | ||
| // corresponding to `application/x-www-form-urlencoded`. | ||
| // | ||
| // See: https://tools.ietf.org/html/rfc1866#section-8.2.1 | ||
| replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => { | ||
| ).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => { | ||
| const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where | ||
@@ -84,0 +84,0 @@ // default is restored in destructuring assignment. |
@@ -1,1 +0,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;A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AJ,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"]} | ||
| {"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,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,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"]} |
+50
-50
@@ -6,24 +6,24 @@ "use strict"; | ||
| }); | ||
| Object.defineProperty(exports, "isURL", { | ||
| Object.defineProperty(exports, "addQueryArgs", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isUrl.isURL; | ||
| return _addQueryArgs.addQueryArgs; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isEmail", { | ||
| Object.defineProperty(exports, "buildQueryString", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isEmail.isEmail; | ||
| return _buildQueryString.buildQueryString; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getProtocol", { | ||
| Object.defineProperty(exports, "cleanForSlug", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getProtocol.getProtocol; | ||
| return _cleanForSlug.cleanForSlug; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isValidProtocol", { | ||
| Object.defineProperty(exports, "filterURLForDisplay", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isValidProtocol.isValidProtocol; | ||
| return _filterUrlForDisplay.filterURLForDisplay; | ||
| } | ||
@@ -37,126 +37,126 @@ }); | ||
| }); | ||
| Object.defineProperty(exports, "isValidAuthority", { | ||
| Object.defineProperty(exports, "getFilename", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isValidAuthority.isValidAuthority; | ||
| return _getFilename.getFilename; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getPath", { | ||
| Object.defineProperty(exports, "getFragment", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getPath.getPath; | ||
| return _getFragment.getFragment; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isValidPath", { | ||
| Object.defineProperty(exports, "getPath", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isValidPath.isValidPath; | ||
| return _getPath.getPath; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getQueryString", { | ||
| Object.defineProperty(exports, "getPathAndQueryString", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getQueryString.getQueryString; | ||
| return _getPathAndQueryString.getPathAndQueryString; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "buildQueryString", { | ||
| Object.defineProperty(exports, "getProtocol", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _buildQueryString.buildQueryString; | ||
| return _getProtocol.getProtocol; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isValidQueryString", { | ||
| Object.defineProperty(exports, "getQueryArg", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isValidQueryString.isValidQueryString; | ||
| return _getQueryArg.getQueryArg; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getPathAndQueryString", { | ||
| Object.defineProperty(exports, "getQueryArgs", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getPathAndQueryString.getPathAndQueryString; | ||
| return _getQueryArgs.getQueryArgs; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getFragment", { | ||
| Object.defineProperty(exports, "getQueryString", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getFragment.getFragment; | ||
| return _getQueryString.getQueryString; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isValidFragment", { | ||
| Object.defineProperty(exports, "hasQueryArg", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _isValidFragment.isValidFragment; | ||
| return _hasQueryArg.hasQueryArg; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "addQueryArgs", { | ||
| Object.defineProperty(exports, "isEmail", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _addQueryArgs.addQueryArgs; | ||
| return _isEmail.isEmail; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getQueryArg", { | ||
| Object.defineProperty(exports, "isURL", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getQueryArg.getQueryArg; | ||
| return _isUrl.isURL; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getQueryArgs", { | ||
| Object.defineProperty(exports, "isValidAuthority", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getQueryArgs.getQueryArgs; | ||
| return _isValidAuthority.isValidAuthority; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "hasQueryArg", { | ||
| Object.defineProperty(exports, "isValidFragment", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _hasQueryArg.hasQueryArg; | ||
| return _isValidFragment.isValidFragment; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "removeQueryArgs", { | ||
| Object.defineProperty(exports, "isValidPath", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _removeQueryArgs.removeQueryArgs; | ||
| return _isValidPath.isValidPath; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "prependHTTP", { | ||
| Object.defineProperty(exports, "isValidProtocol", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _prependHttp.prependHTTP; | ||
| return _isValidProtocol.isValidProtocol; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "safeDecodeURI", { | ||
| Object.defineProperty(exports, "isValidQueryString", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _safeDecodeUri.safeDecodeURI; | ||
| return _isValidQueryString.isValidQueryString; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "safeDecodeURIComponent", { | ||
| Object.defineProperty(exports, "normalizePath", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _safeDecodeUriComponent.safeDecodeURIComponent; | ||
| return _normalizePath.normalizePath; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "filterURLForDisplay", { | ||
| Object.defineProperty(exports, "prependHTTP", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _filterUrlForDisplay.filterURLForDisplay; | ||
| return _prependHttp.prependHTTP; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "cleanForSlug", { | ||
| Object.defineProperty(exports, "removeQueryArgs", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _cleanForSlug.cleanForSlug; | ||
| return _removeQueryArgs.removeQueryArgs; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "getFilename", { | ||
| Object.defineProperty(exports, "safeDecodeURI", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _getFilename.getFilename; | ||
| return _safeDecodeUri.safeDecodeURI; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "normalizePath", { | ||
| Object.defineProperty(exports, "safeDecodeURIComponent", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _normalizePath.normalizePath; | ||
| return _safeDecodeUriComponent.safeDecodeURIComponent; | ||
| } | ||
@@ -163,0 +163,0 @@ }); |
@@ -29,3 +29,3 @@ "use strict"; | ||
| */ | ||
| function removeQueryArgs(url, ...args) { | ||
| function removeQueryArgs(url) { | ||
| const queryStringIndex = url.indexOf('?'); | ||
@@ -39,2 +39,7 @@ | ||
| const baseURL = url.substr(0, queryStringIndex); | ||
| for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
| args[_key - 1] = arguments[_key]; | ||
| } | ||
| args.forEach(arg => delete query[arg]); | ||
@@ -41,0 +46,0 @@ const queryString = (0, _buildQueryString.buildQueryString)(query); |
@@ -1,1 +0,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"]} | ||
| {"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"]} |
+3
-3
| { | ||
| "name": "@wordpress/url", | ||
| "version": "3.3.0", | ||
| "version": "3.3.1", | ||
| "description": "WordPress URL utilities.", | ||
@@ -30,3 +30,3 @@ "author": "The WordPress Contributors", | ||
| "dependencies": { | ||
| "@babel/runtime": "^7.13.10", | ||
| "@babel/runtime": "^7.16.0", | ||
| "lodash": "^4.17.21" | ||
@@ -37,3 +37,3 @@ }, | ||
| }, | ||
| "gitHead": "393c2b5533837fd637e998d23f0124c081a10df0" | ||
| "gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50" | ||
| } |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
287507
0.27%4163
0.29%Updated