<commit_before>var SNKit = (() => {
  return {
    version: "2.0.0",
    getWidgetDetails: (callback) => {
      var details = [];
      var spWidgets = document.querySelectorAll("[widget='widget']");

      spWidgets.forEach((w, i) => {
        var detailObj = {};
        var thisScope = angular.element(spWidgets[i]).scope();
        detailObj.name = thisScope.widget.name;
        detailObj.technicalName = thisScope.widget.id;
        detailObj.id = spWidgets[i].id
        detailObj.className = spWidgets[i].classList.item(0);
        detailObj.identifier = "class"
        detailObj.portalId = thisScope.portal.sys_id;
        detailObj.themeId = thisScope.theme.sys_id;
        detailObj.pageId = thisScope.page.sys_id;
        detailObj.serverTime = thisScope.widget._server_time;
        if(thisScope.theme.header && thisScope.theme.header.sys_id) detailObj.headerId = thisScope.theme.header.sys_id;
        if(thisScope.theme.footer && thisScope.theme.footer.sys_id) detailObj.footerId = thisScope.theme.footer.sys_id;
        details.push(detailObj);
      })
      callback(details);
    },
    getWidgetScopes: (p1, p2) => {
      var _widgetName;
      var _callback;
      /**
       * Allow the user to either enter a string name of the widget, a string name of
       * the widget with a callback, or just a callback.
       */
      if(p1) {
        if(typeof(p1) === "string") {
          _widgetName = p1;
        } else if(typeof(p1) === "function") {
          _callback = p1;
        }
      }
      if(p2) {
        if(typeof(p2) === "function")
          _callback = p2;
      }

      var widgetScopes = [];
      var spWidgets = document.querySelectorAll("[widget='widget']");

      spWidgets.forEach((widget, i) => {
        var thisScope = angular.element(spWidgets[i]).scope();
        widgetScopes.push(thisScope);
      });

      if(_widgetName) {
        if (_callback) {
          var results = widgetScopes.filter((scope) => {
            return scope.widget.name.toUpperCase() == _widgetName.toUpperCase()
          });
          _callback(results);
          return;
        } else {
          return widgetScopes.filter((scope) => {
            return scope.widget.name.toUpperCase() == _widgetName.toUpperCase()
          });
        }
      }
      if(_callback) _callback(widgetScopes);
      else return widgetScopes;
    },
    timeServer: (scope) => {

      return new Promise((resolve, reject) => {
        var timing;
        var start = Date.now();
        //console.log(scope.widget.name + " started @" + Date.now());
        scope.server.refresh().then(() => {
          var end = Date.now();
          //console.log(scope.widget.name + " finished @" + Date.now());
          timing = end - start;

          //record timing in widget scope
          scope.load_time = timing;

          resolve({timing: timing, name: scope.widget.name});
        });
      });
    },
    // Promises need to run in a synchronous chain, this is not happening yet.
    getServerTimings: (callback) => {
      var scopes = SNKit.getWidgetScopes();<commit_msg>adjust scope key to ensure it's clear<commit_after>var SNKit = (() => {
  return {
    version: "2.0.0",
    getWidgetDetails: (callback) => {
      var details = [];
      var spWidgets = document.querySelectorAll("[widget='widget']");

      spWidgets.forEach((w, i) => {
        var detailObj = {};
        var thisScope = angular.element(spWidgets[i]).scope();
        detailObj.name = thisScope.widget.name;
        detailObj.technicalName = thisScope.widget.id;
        detailObj.id = spWidgets[i].id
        detailObj.className = spWidgets[i].classList.item(0);
        detailObj.identifier = "class"
        detailObj.portalId = thisScope.portal.sys_id;
        detailObj.themeId = thisScope.theme.sys_id;
        detailObj.pageId = thisScope.page.sys_id;
        detailObj.serverTime = thisScope.widget._server_time;
        if(thisScope.theme.header && thisScope.theme.header.sys_id) detailObj.headerId = thisScope.theme.header.sys_id;
        if(thisScope.theme.footer && thisScope.theme.footer.sys_id) detailObj.footerId = thisScope.theme.footer.sys_id;
        details.push(detailObj);
      })
      callback(details);
    },
    getWidgetScopes: (p1, p2) => {
      var _widgetName;
      var _callback;
      /**
       * Allow the user to either enter a string name of the widget, a string name of
       * the widget with a callback, or just a callback.
       */
      if(p1) {
        if(typeof(p1) === "string") {
          _widgetName = p1;
        } else if(typeof(p1) === "function") {
          _callback = p1;
        }
      }
      if(p2) {
        if(typeof(p2) === "function")
          _callback = p2;
      }

      var widgetScopes = [];
      var spWidgets = document.querySelectorAll("[widget='widget']");

      spWidgets.forEach((widget, i) => {
        var thisScope = angular.element(spWidgets[i]).scope();
        widgetScopes.push(thisScope);
      });

      if(_widgetName) {
        if (_callback) {
          var results = widgetScopes.filter((scope) => {
            return scope.widget.name.toUpperCase() == _widgetName.toUpperCase()
          });
          _callback(results);
          return;
        } else {
          return widgetScopes.filter((scope) => {
            return scope.widget.name.toUpperCase() == _widgetName.toUpperCase()
          });
        }
      }
      if(_callback) _callback(widgetScopes);
      else return widgetScopes;
    },
    timeServer: (scope) => {

      return new Promise((resolve, reject) => {
        var timing;
        var start = Date.now();
        //console.log(scope.widget.name + " started @" + Date.now());
        scope.server.refresh().then(() => {
          var end = Date.now();
          //console.log(scope.widget.name + " finished @" + Date.now());
          timing = end - start;

          //record timing in widget scope
          scope.snkit_load_time_ms = timing;

          resolve({timing: timing, name: scope.widget.name});
        });
      });
    },
    // Promises need to run in a synchronous chain, this is not happening yet.
    getServerTimings: (callback) => {
      var scopes = SNKit.getWidgetScopes();
{'fraction_non_alphanumeric': 0.13711621925735412, 'fraction_numerical': 0.004500884102234368, 'mean_word_length': 2.1826086956521737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2153778', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1850, 'n_words': 365}