<commit_before>goog.provide 'acorn.util'

goog.require 'acorn.config'


acorn.util =

  assert: (condition, description) ->
    throw new Error description if not condition

  urlRegEx: (url) ->
    ///^(https?:\/\/)?#{url ? '.*'}$///

  isUrl: (url) ->
    url = String(url)
    @urlRegEx().test url

  isPath: (path) ->
    /^[A-Za-z\/.-_]+$/.test path

  # helpers to construct acorn urls TODO: delete these?
  url: ->
    path = _.toArray(arguments).join '/'
    "http://#{acorn.config.domain}/#{path}"

  apiUrl: ->
    apiPath = "api/v#{acorn.config.api.version}".split '/'
    @url.apply(@, apiPath.concat _.toArray arguments)

  imgUrl: ->
    @url.apply(@, ['img'].concat _.toArray arguments)

  # construct an <iframe> element, with `src` and `id`
  iframeOptions:
    frameborder: 0
    border: 0
    width: '100%'
    height: '100%'
    allowFullScreen: 'true'
    webkitAllowFullScreen: 'true'
    mozallowfullscreen: 'true'

  # construct an <iframe> element, with `src` and `id`
  iframe: (src, id) ->
    f = $ '<iframe>'
    _.map @iframeOptions, (val, key) ->
      f.attr key, val
    f.attr 'src', src
    f.attr 'id', id if id?
    f

  # get the acorn variable in given <iframe> element
  acornInIframe: (iframe) ->
    iframe = iframe.get 0 if iframe.jquery?
    win = iframe.contentWindow ? iframe.contentDocument.defaultView
    win.acorn

  # creates and returns a get/setter with a closured variable
  property: (defaultValue, validate) ->
    storedValue = defaultValue
    validate ?= (x) -> x

    (value) ->
      storedValue = validate value if value?
      storedValue

  # requests full screen with given elem
  fullscreen: (elem) ->
    elem = elem[0] if elem.jquery?
    if elem.requestFullscreen
      elem.requestFullscreen()
    else if elem.webkitRequestFullScreen
      elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)
    else if elem.mozRequestFullScreen
      elem.mozRequestFullScreen()

  # add acorn css
  appendCss: (srcs) ->
    srcs ?= acorn.config.css
    srcs = [srcs] unless _.isArray(srcs)
    _.each srcs, (src) ->
      unless $("link[rel='stylesheet'][href='#{src}']").length
        css = $('<link>')
        css.attr 'rel', 'stylesheet'
        css.attr 'href', src
        $('body').append css

  # converts human-readable timeString to seconds and back
  # human-readable format is: [[hh:]mm:]ss[.SSS]
  Time: class Time
    constructor: (time) ->
      @time = @constructor.timestringToSeconds time

    seconds: => @time
    timestring: => @constructor.secondsToTimestring @time

    @timestringToSeconds: (timestring) =>
      timestring = String(timestring ? 0)

      # handle subsec [.SSS]
      [rest, subsec] = timestring.split '.'<commit_msg>util: stylefix: update comment text<commit_after>goog.provide 'acorn.util'

goog.require 'acorn.config'


acorn.util =

  assert: (condition, description) ->
    throw new Error description if not condition

  urlRegEx: (url) ->
    ///^(https?:\/\/)?#{url ? '.*'}$///

  isUrl: (url) ->
    url = String(url)
    @urlRegEx().test url

  isPath: (path) ->
    /^[A-Za-z\/.-_]+$/.test path

  # helpers to construct acorn urls TODO: delete these?
  url: ->
    path = _.toArray(arguments).join '/'
    "http://#{acorn.config.domain}/#{path}"

  apiUrl: ->
    apiPath = "api/v#{acorn.config.api.version}".split '/'
    @url.apply(@, apiPath.concat _.toArray arguments)

  imgUrl: ->
    @url.apply(@, ['img'].concat _.toArray arguments)

  # construct an <iframe> element, with `src` and `id`
  iframeOptions:
    frameborder: 0
    border: 0
    width: '100%'
    height: '100%'
    allowFullScreen: 'true'
    webkitAllowFullScreen: 'true'
    mozallowfullscreen: 'true'

  # construct an <iframe> element, with `src` and `id`
  iframe: (src, id) ->
    f = $ '<iframe>'
    _.map @iframeOptions, (val, key) ->
      f.attr key, val
    f.attr 'src', src
    f.attr 'id', id if id?
    f

  # get the acorn variable in given <iframe> element
  acornInIframe: (iframe) ->
    iframe = iframe.get 0 if iframe.jquery?
    win = iframe.contentWindow ? iframe.contentDocument.defaultView
    win.acorn

  # creates and returns a get/setter with a closured variable
  property: (defaultValue, validate) ->
    storedValue = defaultValue
    validate ?= (x) -> x

    (value) ->
      storedValue = validate value if value?
      storedValue

  # requests full screen with given elem
  fullscreen: (elem) ->
    elem = elem[0] if elem.jquery?
    if elem.requestFullscreen
      elem.requestFullscreen()
    else if elem.webkitRequestFullScreen
      elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)
    else if elem.mozRequestFullScreen
      elem.mozRequestFullScreen()

  # add acorn css
  appendCss: (srcs) ->
    srcs ?= acorn.config.css
    srcs = [srcs] unless _.isArray(srcs)
    _.each srcs, (src) ->
      unless $("link[rel='stylesheet'][href='#{src}']").length
        css = $('<link>')
        css.attr 'rel', 'stylesheet'
        css.attr 'href', src
        $('body').append css

  # converts human-readable timestring to seconds and back
  # human-readable format is: [[hh:]mm:]ss[.SSS]
  Time: class Time
    constructor: (time) ->
      @time = @constructor.timestringToSeconds time

    seconds: => @time
    timestring: => @constructor.secondsToTimestring @time

    @timestringToSeconds: (timestring) =>
      timestring = String(timestring ? 0)

      # handle subsec [.SSS]
      [rest, subsec] = timestring.split '.'
{'fraction_non_alphanumeric': 0.14635931211123307, 'fraction_numerical': 0.00402488108305891, 'mean_word_length': 2.8690728945506017, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, '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': '939332', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1812, 'n_words': 466}