{"version":3,"file":"normalize-path.cjs","names":["safeDecodeURIComponent"],"sources":["../src/normalize-path.ts"],"sourcesContent":["import { safeDecodeURIComponent } from './safe-decode-uri-component';\n\n/**\n * Given a path, returns a normalized path where equal query parameter values\n * will be treated as identical, regardless of order they appear in the original\n * text.\n *\n * @param path Original path.\n *\n * @return Normalized path.\n */\nexport function normalizePath( path: string ): string {\n\tconst separatorIndex = path.indexOf( '?' );\n\n\tif ( separatorIndex === -1 ) {\n\t\treturn path;\n\t}\n\n\tconst base = path.slice( 0, separatorIndex );\n\tconst query = path.slice( separatorIndex + 1 );\n\n\tif ( ! query ) {\n\t\treturn base;\n\t}\n\n\t// 'b=1%2C2&c=2&a=5'\n\treturn (\n\t\tbase +\n\t\t'?' +\n\t\tquery\n\t\t\t// [ 'b=1%2C2', 'c=2', 'a=5' ]\n\t\t\t.split( '&' )\n\t\t\t// [ [ 'b, '1%2C2' ], [ 'c', '2' ], [ 'a', '5' ] ]\n\t\t\t.map( ( entry ) => entry.split( '=' ) )\n\t\t\t// [ [ 'b', '1,2' ], [ 'c', '2' ], [ 'a', '5' ] ]\n\t\t\t.map( ( pair ) => pair.map( safeDecodeURIComponent ) )\n\t\t\t// [ [ 'a', '5' ], [ 'b, '1,2' ], [ 'c', '2' ] ]\n\t\t\t.sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) )\n\t\t\t// [ [ 'a', '5' ], [ 'b, '1%2C2' ], [ 'c', '2' ] ]\n\t\t\t.map( ( pair ) => pair.map( encodeURIComponent ) )\n\t\t\t// [ 'a=5', 'b=1%2C2', 'c=2' ]\n\t\t\t.map( ( pair ) => pair.join( '=' ) )\n\t\t\t// 'a=5&b=1%2C2&c=2'\n\t\t\t.join( '&' )\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,SAAgB,cAAe,MAAuB;CACrD,MAAM,iBAAiB,KAAK,QAAS,GAAI;CAEzC,IAAK,mBAAmB,IACvB,OAAO;CAGR,MAAM,OAAO,KAAK,MAAO,GAAG,cAAe;CAC3C,MAAM,QAAQ,KAAK,MAAO,iBAAiB,CAAE;CAE7C,IAAK,CAAE,OACN,OAAO;CAIR,OACC,OACA,MACA,MAEE,MAAO,GAAI,CAAC,CAEZ,KAAO,UAAW,MAAM,MAAO,GAAI,CAAE,CAAC,CAEtC,KAAO,SAAU,KAAK,IAAKA,+BAAAA,sBAAuB,CAAE,CAAC,CAErD,MAAQ,GAAG,MAAO,EAAG,EAAG,CAAC,cAAe,EAAG,EAAI,CAAE,CAAC,CAElD,KAAO,SAAU,KAAK,IAAK,kBAAmB,CAAE,CAAC,CAEjD,KAAO,SAAU,KAAK,KAAM,GAAI,CAAE,CAAC,CAEnC,KAAM,GAAI;AAEd"}