<commit_before># Pre dependencies
Preferences = require("./preferences")
sprintf = require("./sprintf")

###*
@class App
  Application top class (Not instanciatable)
###
class App
  null

  # Version emulation for browser view
  VER_EMULATION = "0.9.0"

  # Conversion from version string to integer
  v2i = (v) ->
    [p1, p2, p3, p4] = v.split(".", 4).map((p) -> parseInt(p) & 0xffff)
    return (p1 << 48) | (p2 << 32) | (p3 << 16) | (p4 << 0)

  ###*
  @static
  @property {Sketch}
    Current sketch
  ###
  @classProperty("sketch",
    get: -> @_sketch
    set: (v) ->
      @_sketch = v
      t = "#{v.friendlyName} - " if v?
      window.document.title = "#{t or ""}Rubic"
      return
  )

  ###*
  @static
  @property {string}
    Version string for Rubic
  @readonly
  ###
  @classProperty("version", value: chrome.runtime.getManifest?()["version"] or VER_EMULATION)

  LOG = (type, verbosity, args) ->
    return if Preferences.logVerbosity < verbosity
    fn = window.console[type].bind(window.console)
    return fn(sprintf(args...)) if typeof(args[0]) == "string"
    return fn(args...)

  @log          = -> return LOG("log", 1, arguments)
  @log.detail   = -> return LOG("log", 2, arguments)
  @info         = -> return LOG("info", 1, arguments)
  @info.detail  = -> return LOG("info", 2, arguments)
  @warn         = -> return LOG("warn", 1, arguments)
  @warn.detail  = -> return LOG("warn", 2, arguments)
  @error        = -> return LOG("error", 1, arguments)
  @error.detail = -> return LOG("error", 2, arguments)

  @info("Rubic/%s %s", @version, window.navigator.userAgent)

  ###*
  @static
  @method
    Check if current version matches an version-check expression
  @param {string} versionExpr
    Expression for version check
  @return {boolean}
    Result of version check
  ###
  @versionCheck: (expr) ->
    return true unless expr?
    current = v2i(@version)
    for expr2 in expr.split(",")
      result = true
      for expr3 in expr.split("&")
        [operator, value] = expr3.trim().split(" ")
        target = v2i(value)
        switch operator
          when ">"  then result and= (current >  target)
          when "<"  then result and= (current <  target)
          when ">=" then result and= (current >= target)
          when "<=" then result and= (current >= target)
          when "==" then result and= (current == target)
          else result = false
        break unless result
      return true if result<commit_msg>Support node.js environment<commit_after># Pre dependencies
Preferences = require("./preferences")
sprintf = require("./sprintf")

###*
@class App
  Application top class (Not instanciatable)
###
class App
  null

  # Version emulation for browser view
  VER_EMULATION = "0.9.0"

  # Conversion from version string to integer
  v2i = (v) ->
    [p1, p2, p3, p4] = v.split(".", 4).map((p) -> parseInt(p) & 0xffff)
    return (p1 << 48) | (p2 << 32) | (p3 << 16) | (p4 << 0)

  ###*
  @static
  @property {Sketch}
    Current sketch
  ###
  @classProperty("sketch",
    get: -> @_sketch
    set: (v) ->
      @_sketch = v
      t = "#{v.friendlyName} - " if v?
      window.document.title = "#{t or ""}Rubic"
      return
  )

  ###*
  @static
  @property {string}
    Version string for Rubic
  @readonly
  ###
  @classProperty("version", value: chrome?.runtime?.getManifest?()["version"] or VER_EMULATION)

  LOG = (type, verbosity, args) ->
    return if Preferences.logVerbosity < verbosity
    fn = global.console[type].bind(global.console)
    return fn(sprintf(args...)) if typeof(args[0]) == "string"
    return fn(args...)

  @log          = -> return LOG("log", 1, arguments)
  @log.detail   = -> return LOG("log", 2, arguments)
  @info         = -> return LOG("info", 1, arguments)
  @info.detail  = -> return LOG("info", 2, arguments)
  @warn         = -> return LOG("warn", 1, arguments)
  @warn.detail  = -> return LOG("warn", 2, arguments)
  @error        = -> return LOG("error", 1, arguments)
  @error.detail = -> return LOG("error", 2, arguments)

  @info("Rubic/%s %s", @version, window?.navigator.userAgent)

  ###*
  @static
  @method
    Check if current version matches an version-check expression
  @param {string} versionExpr
    Expression for version check
  @return {boolean}
    Result of version check
  ###
  @versionCheck: (expr) ->
    return true unless expr?
    current = v2i(@version)
    for expr2 in expr.split(",")
      result = true
      for expr3 in expr.split("&")
        [operator, value] = expr3.trim().split(" ")
        target = v2i(value)
        switch operator
          when ">"  then result and= (current >  target)
          when "<"  then result and= (current <  target)
          when ">=" then result and= (current >= target)
          when "<=" then result and= (current >= target)
          when "==" then result and= (current == target)
          else result = false
        break unless result
      return true if result
{'fraction_non_alphanumeric': 0.15767131594906003, 'fraction_numerical': 0.014149989892864362, 'mean_word_length': 2.681547619047619, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 41, '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': '7411108', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1576, 'n_words': 465}