<commit_before>do (window = @, document) ->
  "use strict"

  ###
    String helper functions
  ###

  # Use ECMAScript 6 String.prototype.contains if available
  contains = (bigString, smallString) ->
    if String::contains then bigString.contains(smallString) else !!~bigString.indexOf(smallString)

  ###
    Default configuration for detectr
  ###
  defaultTests =
    tests:
      desktop:
        run: -> not runTest('mobile')
        result: 'desktop'
      mobile:
        run: -> 
          # Most mobile browsers have a mobile in their user agent
          return true if contains detectr.Browser.get(), 'mobile'

          runTest('android') or runTest('ios') or runTest('bada') or runTest('webos') or runTest('wp7') or runTest('blackberry')
        result: 'mobile'
      macosx:
        run: -> (contains detectr.Browser.platform.name(), 'macosx') and not (contains detectr.Browser.platform.name(), 'likemacosx')
        result: 'macosx'
      linux:
        run: -> contains detectr.Browser.platform.name(), 'linux'
        result: 'linux'
      windows:
        run: -> contains detectr.Browser.platform.name(), 'windows'
        result: 'windows'
      android:
        run: -> contains detectr.Browser.get(), 'android'
        result: 'android'
      ios:
        run: -> contains detectr.Browser.platform.name(), 'likemacosx'
        result: 'ios'
      ipod:
        run: -> contains detectr.Browser.get(), 'ipod'
        result: 'ipod'
      iphone:
        run: -> (contains detectr.Browser.get(), 'iphone') and not runTest('ipod')
        result: 'iphone'
      ipad:
        run: -> contains detectr.Browser.get(), 'ipad'
        result: 'ipad'
      bada:
        run: -> contains detectr.Browser.get(), 'bada'
        result: 'bada'
      webos:
        run: -> contains detectr.Browser.get(), 'webos'
        result: 'webos'
      wp7:
        run: -> contains detectr.Browser.get(), 'windows phone os'
        result: 'wp7'
      blackberry:
        run: -> (contains detectr.Browser.get(), 'rim') or (contains detectr.Browser.get(), 'blackberry')
        result: 'blackberry'
      landscape:
        run: -> detectr.Display.pageWidth() >= detectr.Display.pageHeight()
        result: 'landscape'
      portrait:
        run: -> !runTest('landscape')
        result: 'portrait'
      'browser-chrome':
        run: -> contains detectr.Browser.get(), 'chrome'
        result: 'browser-chrome'
      'browser-firefox':
        run: -> contains detectr.Browser.get(), 'firefox'
        result: 'browser-firefox'
      'browser-ie':
        run: -> contains detectr.Browser.get(), 'msie'
        result: 'browser-ie'
      'browser-safari':
        run: -> (contains detectr.Browser.get(), 'safari') and not (contains detectr.Browser.get(), 'chrome')
        result: 'browser-safari'
      'browser-opera':
        run: -> contains detectr.Browser.get(), 'opera'
        result: 'browser-opera'
    
  
  detectCache = {}
  detectResultCache = {}
  globalOptions = {}
  testQueue = {}

  ###
    Runs a defined test
  ###
  runTest = (testName, testObject) ->
    return false unless testName

    if testQueue[testName].status is 'tested'
      return !!detectCache[testName]
    else
      if testObject
        if testObject.run
          testResultBool = !!testObject.run()
          testResultString = testObject.result

        console.log "Testing #{testName}: Result: #{testResultBool}" if globalOptions?.debug?

        testQueue[testName].status = 'tested' if testQueue[testName]

        detectCache[testName] = testResultBool

        if testResultBool
          htmlClassName = document.documentElement.className

          htmlClassName += " #{testResultString}"
          # Trim className just in case
          htmlClassName = htmlClassName.trim()
          document.documentElement.className = htmlClassName

          detectResultCache[testName] = testResultString

          !!detectCache[testName]
      else
        runTest testName, testQueue[testName]


  ###
    detectr constructor
  ###
  detectr = (config, options) ->
    # Make sure the config object exists and it has some tests in it
    return undefined unless (config and config.tests)

    globalOptions = options

    uaString = navigator.userAgent.toLowerCase()
    {appName: uaAppName, appVersion: uaAppVersion, platform: uaPlatform} = navigator

    parsedPlatform = uaString.match(/(.*?)\s(.*?)\((.*?);\s(.*?)\)/)

    detectr.Browser or= 
      width: -> window.outerWidth
      height: -> window.outerHeight
      get: -> uaString
      name: -> uaAppName
      version: -> uaAppVersion
      platform: 
        name: -> parsedPlatform[4].replace(/\s/gi, '').toLowerCase()
        original: -> uaPlatform
      language: ->
        language = navigator.language or navigator.systemLanguage
        language.split('-')[0] if language?

    # Sets language attribute to browser language by default
    document.documentElement.setAttribute('lang', detectr.Browser.language())<commit_msg>Added some example doc tags<commit_after>do (window = @, document) ->
  "use strict"

  ###
    String helper functions
  ###

  # Use ECMAScript 6 String.prototype.contains if available
  contains = (bigString, smallString) ->
    if String::contains then bigString.contains(smallString) else !!~bigString.indexOf(smallString)

  ###
    Default configuration for detectr
    
    @mixin Default tests
  ###
  defaultTests =
    tests:
      desktop:
        run: -> not runTest('mobile')
        result: 'desktop'
      mobile:
        run: -> 
          # Most mobile browsers have a mobile in their user agent
          return true if contains detectr.Browser.get(), 'mobile'

          runTest('android') or runTest('ios') or runTest('bada') or runTest('webos') or runTest('wp7') or runTest('blackberry')
        result: 'mobile'
      macosx:
        run: -> (contains detectr.Browser.platform.name(), 'macosx') and not (contains detectr.Browser.platform.name(), 'likemacosx')
        result: 'macosx'
      linux:
        run: -> contains detectr.Browser.platform.name(), 'linux'
        result: 'linux'
      windows:
        run: -> contains detectr.Browser.platform.name(), 'windows'
        result: 'windows'
      android:
        run: -> contains detectr.Browser.get(), 'android'
        result: 'android'
      ios:
        run: -> contains detectr.Browser.platform.name(), 'likemacosx'
        result: 'ios'
      ipod:
        run: -> contains detectr.Browser.get(), 'ipod'
        result: 'ipod'
      iphone:
        run: -> (contains detectr.Browser.get(), 'iphone') and not runTest('ipod')
        result: 'iphone'
      ipad:
        run: -> contains detectr.Browser.get(), 'ipad'
        result: 'ipad'
      bada:
        run: -> contains detectr.Browser.get(), 'bada'
        result: 'bada'
      webos:
        run: -> contains detectr.Browser.get(), 'webos'
        result: 'webos'
      wp7:
        run: -> contains detectr.Browser.get(), 'windows phone os'
        result: 'wp7'
      blackberry:
        run: -> (contains detectr.Browser.get(), 'rim') or (contains detectr.Browser.get(), 'blackberry')
        result: 'blackberry'
      landscape:
        run: -> detectr.Display.pageWidth() >= detectr.Display.pageHeight()
        result: 'landscape'
      portrait:
        run: -> !runTest('landscape')
        result: 'portrait'
      'browser-chrome':
        run: -> contains detectr.Browser.get(), 'chrome'
        result: 'browser-chrome'
      'browser-firefox':
        run: -> contains detectr.Browser.get(), 'firefox'
        result: 'browser-firefox'
      'browser-ie':
        run: -> contains detectr.Browser.get(), 'msie'
        result: 'browser-ie'
      'browser-safari':
        run: -> (contains detectr.Browser.get(), 'safari') and not (contains detectr.Browser.get(), 'chrome')
        result: 'browser-safari'
      'browser-opera':
        run: -> contains detectr.Browser.get(), 'opera'
        result: 'browser-opera'
    
  
  detectCache = {}
  detectResultCache = {}
  globalOptions = {}
  testQueue = {}

  ###
    Runs a defined test
  ###
  runTest = (testName, testObject) ->
    return false unless testName

    if testQueue[testName].status is 'tested'
      return !!detectCache[testName]
    else
      if testObject
        if testObject.run
          testResultBool = !!testObject.run()
          testResultString = testObject.result

        console.log "Testing #{testName}: Result: #{testResultBool}" if globalOptions?.debug?

        testQueue[testName].status = 'tested' if testQueue[testName]

        detectCache[testName] = testResultBool

        if testResultBool
          htmlClassName = document.documentElement.className

          htmlClassName += " #{testResultString}"
          # Trim className just in case
          htmlClassName = htmlClassName.trim()
          document.documentElement.className = htmlClassName

          detectResultCache[testName] = testResultString

          !!detectCache[testName]
      else
        runTest testName, testQueue[testName]


  ###
    detectr constructor
    
    @method detectr
  ###
  detectr = (config, options) ->
    # Make sure the config object exists and it has some tests in it
    return undefined unless (config and config.tests)

    globalOptions = options

    uaString = navigator.userAgent.toLowerCase()
    {appName: uaAppName, appVersion: uaAppVersion, platform: uaPlatform} = navigator

    parsedPlatform = uaString.match(/(.*?)\s(.*?)\((.*?);\s(.*?)\)/)

    detectr.Browser or= 
      width: -> window.outerWidth
      height: -> window.outerHeight
      get: -> uaString
      name: -> uaAppName
      version: -> uaAppVersion
      platform: 
        name: -> parsedPlatform[4].replace(/\s/gi, '').toLowerCase()
        original: -> uaPlatform
      language: ->
        language = navigator.language or navigator.systemLanguage
        language.split('-')[0] if language?

    # Sets language attribute to browser language by default
    document.documentElement.setAttribute('lang', detectr.Browser.language())
{'fraction_non_alphanumeric': 0.12967927713236024, 'fraction_numerical': 0.0011915400655347036, 'mean_word_length': 2.48995148995149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 71, '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': '873574', 'n_tokens_mistral': 2930, 'n_tokens_neox': 2879, 'n_words': 714}