<commit_before>###
Auxiliaries are utlity functions that are specific to Sagefy.
###

cookie = require('./cookie')
{extend, copy, isString, isArray} = require('./utilities')

# Determine if the user is logged in
isLoggedIn = ->
    return cookie.get('logged_in') is '1'

# Capitalizes the first letter of a string
ucfirst = (str) ->
    return str.charAt(0).toUpperCase() + str.slice(1)

# Replaces dashes and spaces with underscores, ready to be used in an URL
underscored = (str) ->
    return str.replace(/[-\s]+/g, '_').toLowerCase()

# From Handlebars
escape = (str) ->
    chars = {
        '&': '&amp;'
        '<': '&lt;'
        '>': '&gt;'
        '"': '&quot;'
        '\'': '&#x27;'
        '`': '&#x60;'
    }

    return ('' + str).replace(/[&<>"'`]/g, (char) ->
        return chars[char]
    )

# From http://ejohn.org/files/pretty.js
# TODO-3 move copy to content directory
timeAgo = (str) ->
    diff = (new Date()).getTime() - (new Date(str)).getTime()
    days = Math.floor(diff / (24 * 60 * 60 * 1000))
    hours = Math.floor(diff / (60 * 60 * 1000))
    minutes = Math.floor(diff / (60 * 1000))
    return "#{days} days ago" if days > 1
    return 'Yesterday' if days is 1
    return "#{hours} hours ago" if hours > 1
    return '1 hour ago' if hours is 1
    return "#{minutes} minutes ago" if minutes > 1
    return '1 minute ago' if minutes is 1
    return 'Just now'

# Return a variable friendly name of the title.
slugify = (s) ->
    return s.toLowerCase().replace(/[-\s]+/g, '_')

# Set the page title.
setTitle = (title = 'FIX ME') ->
    title = "#{title} – Sagefy"
    if document.title isnt title
        document.title = title

# Wait for function to stop being called for `delay`
# milliseconds, and then finally call the real function.
debounce = (fn, delay) ->
    timer = null
    return (args...) ->
        clearTimeout(timer)
        timer = setTimeout(=>
            fn.apply(this, args)
        , delay)

# Determine if a given path matches this router.
# Returns either false or array, where array is matches parameters.
matchesRoute = (docPath, viewPath) ->
    docPath = docPath.split('?')[0]  # Only match the pre-query params
    if isString(viewPath)
        viewPath = new RegExp(
            '^' +
            viewPath.replace(/\{([\d\w\_\$]+)\}/g, '([^/]+)') +
            '$'
        )
    match = docPath.match(viewPath)
    return if match then match.slice(1) else false

valuefy = (value) ->
    return true if value is 'true'
    return false if value is 'false'
    return null if value is 'null'
    return parseFloat(value) if value.match(/^\d+\.\d+$/)
    return parseInt(value) if value.match(/^\d+$/)
    return decodeURIComponent(value)

truncate = (str, len) ->
    return str if str.length <= len
    return str.slice(0, len) + '...'

compact = (A) ->
    return (a for a in A when a)

mergeArraysByKey = (A, B, key = 'id') ->
    a = 0
    b = 0
    C = []

    A = compact(A)
    B = compact(B)

    console.log(A, B)
    console.log(A.length, B.length)

    while a < A.length
        b2 = b
        found = false

        while b2 < B.length
            if A[a][key] is B[b2][key]
                while b <= b2
                    C.push(B[b])
                    b++
                found = true
                break
            b2++

        if not found
            C.push(A[a])

        a++

    while b < B.length
        C.push(B[b])<commit_msg>Remove logs<commit_after>###
Auxiliaries are utlity functions that are specific to Sagefy.
###

cookie = require('./cookie')
{extend, copy, isString, isArray} = require('./utilities')

# Determine if the user is logged in
isLoggedIn = ->
    return cookie.get('logged_in') is '1'

# Capitalizes the first letter of a string
ucfirst = (str) ->
    return str.charAt(0).toUpperCase() + str.slice(1)

# Replaces dashes and spaces with underscores, ready to be used in an URL
underscored = (str) ->
    return str.replace(/[-\s]+/g, '_').toLowerCase()

# From Handlebars
escape = (str) ->
    chars = {
        '&': '&amp;'
        '<': '&lt;'
        '>': '&gt;'
        '"': '&quot;'
        '\'': '&#x27;'
        '`': '&#x60;'
    }

    return ('' + str).replace(/[&<>"'`]/g, (char) ->
        return chars[char]
    )

# From http://ejohn.org/files/pretty.js
# TODO-3 move copy to content directory
timeAgo = (str) ->
    diff = (new Date()).getTime() - (new Date(str)).getTime()
    days = Math.floor(diff / (24 * 60 * 60 * 1000))
    hours = Math.floor(diff / (60 * 60 * 1000))
    minutes = Math.floor(diff / (60 * 1000))
    return "#{days} days ago" if days > 1
    return 'Yesterday' if days is 1
    return "#{hours} hours ago" if hours > 1
    return '1 hour ago' if hours is 1
    return "#{minutes} minutes ago" if minutes > 1
    return '1 minute ago' if minutes is 1
    return 'Just now'

# Return a variable friendly name of the title.
slugify = (s) ->
    return s.toLowerCase().replace(/[-\s]+/g, '_')

# Set the page title.
setTitle = (title = 'FIX ME') ->
    title = "#{title} – Sagefy"
    if document.title isnt title
        document.title = title

# Wait for function to stop being called for `delay`
# milliseconds, and then finally call the real function.
debounce = (fn, delay) ->
    timer = null
    return (args...) ->
        clearTimeout(timer)
        timer = setTimeout(=>
            fn.apply(this, args)
        , delay)

# Determine if a given path matches this router.
# Returns either false or array, where array is matches parameters.
matchesRoute = (docPath, viewPath) ->
    docPath = docPath.split('?')[0]  # Only match the pre-query params
    if isString(viewPath)
        viewPath = new RegExp(
            '^' +
            viewPath.replace(/\{([\d\w\_\$]+)\}/g, '([^/]+)') +
            '$'
        )
    match = docPath.match(viewPath)
    return if match then match.slice(1) else false

valuefy = (value) ->
    return true if value is 'true'
    return false if value is 'false'
    return null if value is 'null'
    return parseFloat(value) if value.match(/^\d+\.\d+$/)
    return parseInt(value) if value.match(/^\d+$/)
    return decodeURIComponent(value)

truncate = (str, len) ->
    return str if str.length <= len
    return str.slice(0, len) + '...'

compact = (A) ->
    return (a for a in A when a)

mergeArraysByKey = (A, B, key = 'id') ->
    a = 0
    b = 0
    C = []

    A = compact(A)
    B = compact(B)

    while a < A.length
        b2 = b
        found = false

        while b2 < B.length
            if A[a][key] is B[b2][key]
                while b <= b2
                    C.push(B[b])
                    b++
                found = true
                break
            b2++

        if not found
            C.push(A[a])

        a++

    while b < B.length
        C.push(B[b])
{'fraction_non_alphanumeric': 0.15475313190862197, 'fraction_numerical': 0.014738393515106854, 'mean_word_length': 2.12, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, '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': '7643333', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2233, 'n_words': 706}