import { TidyURL } from './src'; import { decodeBase64, guessEncoding } from './src/utils'; TidyURL.config.setMany({ silent: false, allowAMP: false, allowCustomHandlers: true, allowRedirects: true }); const tests = [ // Delete test URLs before commit 'https://tracking.inflection.io/02522a2b2726fb0a03bb19f2d8d9524d/gAAAAABny2PCHzD6sfomYgxrbWWC2GPJ_AFA8-9lZZIJB5ZXGkbG6DdX0p7slVJDBjibWPBhL_7moW6WeUZcrn05hYzvc4INssw5CxMcMKG29-DsEF1Z6L64wLdpmNv4RtMwp9R640zBdEw0rUEFI6HyUBDEGeDvoDX54TzR6xzN8KUD3WNZ1AIyf9DQ58P5MYWmUaIubi8fH4JHUHg9HvJlD5IPFcIdORhGq4pi34rD779AxnqsP392c_pOdDRYtCdhXWEhu-gphU22hz2C2P0rGqO0iFnEIA4LG_GYdDh-hT-7wTv4z5RLBoRU5txNiH-e8BEzUDOhaDL-jnn2uIfAsXTkK6KysWD2YinNG-dJVBC9lMlgVFknM4eu1mm5XfdgXW9YxHKAkO8jrnI7GtyIpGKTMLtj67fFhnvZBObc8UqSs' ]; for (const test of tests) { if (test.length === 0) continue; const link = TidyURL.clean(test); // All tests should pass before publishing if (link.info.reduction < 0) { console.log(link.url); throw Error('Reduction less than 0'); } // If last link, log additional information that can be used for debugging if (test === tests[tests.length - 1]) { const params = new URL(link.url).searchParams; console.log(link); console.log('--- start:params ---'); params.forEach((val, key) => { // This is just to save time when testing URLs const possible = guessEncoding(val); if (possible.base64) console.log(`'${key}' might be base64: ${decodeBase64(val)}`); if (possible.isJSON) console.log(`'${key}' might be JSON: ${JSON.stringify(val)}`); if (/script/i.test(val)) console.warn(`'${key}' Possible XSS`); console.log({ [key]: val }); }); console.log('--- end:params ---'); } console.log(TidyURL.loglines); console.log('Input: ' + link.info.original); console.log('Clean: ' + link.url); console.log('New Host: ' + link.info.isNewHost); console.log(`${link.info.reduction}% smaller (${link.info.difference} characters)\n\n`); }