From e06b944e87b23dec285dc3093e3fabd6f7ff2b0d Mon Sep 17 00:00:00 2001 From: Nigel Heron Date: Thu, 28 Jul 2016 17:56:14 -0400 Subject: [PATCH] Add optional options.window param in getCompressedUserTiming (#3) --- README.md | 4 +++- bower.json | 2 +- dist/usertiming-compression.min.js | 2 +- dist/usertiming-decompression.min.js | 2 +- package.json | 2 +- src/usertiming-compression.js | 4 +++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 446319d..3a3e4eb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # usertiming-compression.js -v0.1.0 +v0.1.3 [http://nicj.net](http://nicj.net) @@ -117,6 +117,7 @@ Gathers all UserTiming marks and measures from the root HTML page and all access * `options.map`: A map of names to indexes to use for compression. * `options.from`: The minimum `startTime` * `options.to`: The maximum `startTime` +* `options.window`: window object that will be queried for UserTiming data **Returns**: A map of names to compressed values. @@ -203,6 +204,7 @@ Or via ``gulp``: * v0.1.0 - 2015-12-10: Initial version * v0.1.1 - 2016-04-04: `getCompressedUserTiming()` gathers Measures that end after the specified `from` * v0.1.2 - 2016-04-04: Protect against X-O frame access that crashes some browsers +* v0.1.3 - 2016-07-25: `getCompressedUserTiming()` accepts an alternate window param passed into options ## Thanks diff --git a/bower.json b/bower.json index d236f89..defb804 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "usertiming-compression", - "version": "0.1.2", + "version": "0.1.3", "homepage": "https://github.com/nicjansma/usertiming-compression.js", "authors": [ "Nic Jansma " diff --git a/dist/usertiming-compression.min.js b/dist/usertiming-compression.min.js index 8df4e9b..6b9e462 100644 --- a/dist/usertiming-compression.min.js +++ b/dist/usertiming-compression.min.js @@ -1 +1 @@ -!function(e){"use strict";var r,n;"undefined"!=typeof e?(r=e,n=r.UserTimingCompression):r={};var t,i=t={};i.noConflict=function(){return r.UserTimingCompression=n,i},i.trimTiming=function(e,r){"number"!=typeof e&&(e=0),"number"!=typeof r&&(r=0);var n=Math.round(e),t=Math.round(r);return 0===n?0:n-t},i.toBase36=function(e){return"number"==typeof e?e.toString(36):""},i.findUserTimingForFrame=function(e){var r;if(!e)return[];try{if(!("performance"in e&&e.performance&&e.performance.getEntriesByType))return r;r=e.performance.getEntriesByType("mark"),r=r.concat(e.performance.getEntriesByType("measure"))}catch(n){return r}return r},i.compressUserTiming=function(e,r){var n,i,o,a=0,f={};if(r=r||{},!e||!e.length)return[];for(n=0;n0?(n+=(""!==n?".":"")+i+"*",r>=2&&(n+=r+1),r=0):n+=(""!==n?".":"")+i}return/^\d+$/.test(n)?parseInt(n,10):n},i.getCompressedUserTiming=function(r){var n=this.findUserTimingForFrame(e);return r=r||{},r.from&&(n=n.filter(function(e){return e.startTime>=r.from})),r.to&&(n=n.filter(function(e){return e.startTime<=r.to})),t.compressUserTiming(n,r)},i.compressForUri=function(e){if("object"!=typeof e)return"";var r=!1;for(var n in e)if(e.hasOwnProperty(n)){if(isNaN(n)){r=!1;break}r=!0}if(r)return"1"+t.flattenMap(e);var i=t.convertToTrie(e),o=t.optimizeTrie(i,!0),a=t.jsUrl(o),f=t.flattenArray(e);if("string"!=typeof f||0===f.length)return"";var u=encodeURIComponent(a),s=encodeURIComponent(f);return u.length1331)continue;o.length>1&&(o=t.toBase36(i-36),o="-"+(1===o.length?"0":"")+o),r.push(o+e[n])}return r.sort(),r=r.join("~")},i.jsUrl=function(e){function r(e){return/[^\w-.]/.test(e)?e=e.replace(/[^\w-.]/g,function(e){return"$"===e?"!":(e=e.charCodeAt(0),256>e?"*"+("00"+e.toString(16)).slice(-2):"**"+("0000"+e.toString(16)).slice(-4))}):e}switch(typeof e){case"number":return isFinite(e)?"~"+e:"~null";case"string":return"~'"+r(e);case"boolean":return"~"+e;case"object":return e?Array.isArray(e)?"~("+(e.map(function(e){return t.jsUrl(e)||"~null"}).join("")||"~")+")":"~("+Object.keys(e).map(function(n){var i=t.jsUrl(e[n]);return i&&r(n)+i}).filter(function(e){return e}).sort().join("~")+")":"~null";default:return}},"function"==typeof define&&define.amd?define([],function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:"undefined"!=typeof r&&(r.UserTimingCompression=i)}("undefined"!=typeof window?window:void 0); \ No newline at end of file +!function(e){"use strict";var r,n;"undefined"!=typeof e?(r=e,n=r.UserTimingCompression):r={};var t,i=t={};i.noConflict=function(){return r.UserTimingCompression=n,i},i.trimTiming=function(e,r){"number"!=typeof e&&(e=0),"number"!=typeof r&&(r=0);var n=Math.round(e),t=Math.round(r);return 0===n?0:n-t},i.toBase36=function(e){return"number"==typeof e?e.toString(36):""},i.findUserTimingForFrame=function(e){var r;if(!e)return[];try{e.location&&e.location.href;if(!("performance"in e&&e.performance&&e.performance.getEntriesByType))return r;r=e.performance.getEntriesByType("mark"),r=r.concat(e.performance.getEntriesByType("measure"))}catch(n){return r}return r},i.compressUserTiming=function(e,r){var n,i,o,a=0,f={};if(r=r||{},!e||!e.length)return[];for(n=0;n0?(n+=(""!==n?".":"")+i+"*",r>=2&&(n+=r+1),r=0):n+=(""!==n?".":"")+i}return/^\d+$/.test(n)?parseInt(n,10):n},i.getCompressedUserTiming=function(r){var n,i;return r=r||{},n=r.window||e,i=this.findUserTimingForFrame(n),r.from&&(i=i.filter(function(e){return e.startTime+e.duration>=r.from})),r.to&&(i=i.filter(function(e){return e.startTime<=r.to})),t.compressUserTiming(i,r)},i.compressForUri=function(e){if("object"!=typeof e)return"";var r=!1;for(var n in e)if(e.hasOwnProperty(n)){if(isNaN(n)){r=!1;break}r=!0}if(r)return"1"+t.flattenMap(e);var i=t.convertToTrie(e),o=t.optimizeTrie(i,!0),a=t.jsUrl(o),f=t.flattenArray(e);if("string"!=typeof f||0===f.length)return"";var u=encodeURIComponent(a),s=encodeURIComponent(f);return u.length1331)continue;o.length>1&&(o=t.toBase36(i-36),o="-"+(1===o.length?"0":"")+o),r.push(o+e[n])}return r.sort(),r=r.join("~")},i.jsUrl=function(e){function r(e){return/[^\w-.]/.test(e)?e=e.replace(/[^\w-.]/g,function(e){return"$"===e?"!":(e=e.charCodeAt(0),e<256?"*"+("00"+e.toString(16)).slice(-2):"**"+("0000"+e.toString(16)).slice(-4))}):e}switch(typeof e){case"number":return isFinite(e)?"~"+e:"~null";case"string":return"~'"+r(e);case"boolean":return"~"+e;case"object":return e?Array.isArray(e)?"~("+(e.map(function(e){return t.jsUrl(e)||"~null"}).join("")||"~")+")":"~("+Object.keys(e).map(function(n){var i=t.jsUrl(e[n]);return i&&r(n)+i}).filter(function(e){return e}).sort().join("~")+")":"~null";default:return}},"function"==typeof define&&define.amd?define([],function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:"undefined"!=typeof r&&(r.UserTimingCompression=i)}("undefined"!=typeof window?window:void 0); \ No newline at end of file diff --git a/dist/usertiming-decompression.min.js b/dist/usertiming-decompression.min.js index 1d25322..a3fe0ef 100644 --- a/dist/usertiming-decompression.min.js +++ b/dist/usertiming-decompression.min.js @@ -1 +1 @@ -!function(r){"use strict";var e,t;"undefined"!=typeof r&&(e=r,t=e.UserTimingDecompression);var n,s=n={};s.noConflict=function(){return e.UserTimingDecompression=t,s},s.decompressFromString=function(r,e){var t=[];if(e=e||{},"string"!=typeof r)return t;var s=r[0];return"~"===s||"{"===s||"("===s?t=n.decompressUriTrie(r):"0"===s?t=n.decompressUriArray(r.substring(1)):"1"===s&&(t=n.decompressUriMap(r.substring(1),e.map)),t},s.decompressUriTrie=function(r,e){var t=[];if("string"==typeof r)if("~"===r[0])r=n.jsUrl(r);else{if("{"!==r[0]&&"("!==r[0])return[];"("===r[0]&&(r=r.replace(/\(/g,"{").replace(/\)/g,"}").replace(/~/g,":").replace(/\-/g,",").replace(/'/g,'"'));try{r=JSON.parse(r)}catch(s){return[]}}e=e||"";for(var i in r)if(r.hasOwnProperty(i)){var o=r[i],a=e+i;if(-1!==a.indexOf("!",a.length-1)&&(a=a.substring(0,a.length-1)),"string"==typeof o)for(var f=o.split("|"),u=0;ua;a++)e.push(""!==s?s:"0")}}return e},s.decompressUserTiming=function(r,e){if("string"!=typeof r)return[];var t=n.decompressFromString(r,e);return t.sort(function(r,e){return r.startTime!==e.startTime?r.startTime-e.startTime:r.duration-e.duration}),t};var i={"true":!0,"false":!1,"null":null};s.jsUrl=function(r){function e(e){if(r[n]!==e)throw new Error("bad JSURL syntax: expected "+e+", got "+(r&&r[n]));n++}function t(){for(var e,t=n,i="";s>n&&"~"!==(e=r[n])&&")"!==e;)switch(e){case"*":n>t&&(i+=r.substring(t,n)),"*"===r[n+1]?(i+=String.fromCharCode(parseInt(r.substring(n+2,n+6),16)),t=n+=6):(i+=String.fromCharCode(parseInt(r.substring(n+1,n+3),16)),t=n+=3);break;case"!":n>t&&(i+=r.substring(t,n)),i+="$",t=++n;break;default:n++}return i+r.substring(t,n)}if("string"!=typeof r)return r;var n=0,s=r.length;return function o(){var a,f,u;switch(e("~"),f=r[n]){case"(":if(n++,"~"===r[n])if(a=[],")"===r[n+1])n++;else do a.push(o());while("~"===r[n]);else if(a={},")"!==r[n])do{var p=t();a[p]=o()}while("~"===r[n]&&++n);e(")");break;case"'":n++,a=t();break;default:for(u=n++;s>n&&/[^)~]/.test(r[n]);)n++;var c=r.substring(u,n);if(/[\d\-]/.test(f))a=parseFloat(c);else if(a=i[c],"undefined"==typeof a)throw new Error("bad value keyword: "+c)}return a}()},"function"==typeof define&&define.amd?define([],function(){return s}):"undefined"!=typeof module&&module.exports?module.exports=s:"undefined"!=typeof e&&(e.UserTimingDecompression=s)}("undefined"!=typeof window?window:void 0); \ No newline at end of file +!function(r){"use strict";var e,t;"undefined"!=typeof r&&(e=r,t=e.UserTimingDecompression);var n,s=n={};s.noConflict=function(){return e.UserTimingDecompression=t,s},s.decompressFromString=function(r,e){var t=[];if(e=e||{},"string"!=typeof r)return t;var s=r[0];return"~"===s||"{"===s||"("===s?t=n.decompressUriTrie(r):"0"===s?t=n.decompressUriArray(r.substring(1)):"1"===s&&(t=n.decompressUriMap(r.substring(1),e.map)),t},s.decompressUriTrie=function(r,e){var t=[];if("string"==typeof r)if("~"===r[0])r=n.jsUrl(r);else{if("{"!==r[0]&&"("!==r[0])return[];"("===r[0]&&(r=r.replace(/\(/g,"{").replace(/\)/g,"}").replace(/~/g,":").replace(/\-/g,",").replace(/'/g,'"'));try{r=JSON.parse(r)}catch(s){return[]}}e=e||"";for(var i in r)if(r.hasOwnProperty(i)){var o=r[i],a=e+i;if(a.indexOf("!",a.length-1)!==-1&&(a=a.substring(0,a.length-1)),"string"==typeof o)for(var f=o.split("|"),u=0;u