<commit_before>import * as cookies from 'js-cookie'

function removeNaked (): string {
  const domain = `${location.hostname}`
  return domain.indexOf('www.') === 0 ? domain.substring(4) : domain
}

function setCookie (
  domainParts: Array<string>,
  name: string,
  options: cookies.CookieAttributes,
  data: string | object
): string | undefined {
  let domain = domainParts[domainParts.length - 1]
  let attr: cookies.CookieAttributes = options
  for (let i = 2; i <= domainParts.length; i++) {
    domain = `${domainParts[domainParts.length - i]}.${domain}`
    attr = Object.assign({}, options, { domain })
    cookies.set(name, data, options)
    const storedId = cookies.get(name)
    if (storedId) {
      return storedId
    }
  }
  cookies.set(name, data, attr)
  return cookies.get(name)
}

function findOrCreate (
  name: string,
  options: cookies.CookieAttributes,
  data?: string | object
): string | undefined {
  const value = cookies.get(name)
  if (value) {
    return value
  }
  const domainParts: Array<string> = removeNaked().split('.')
  const subDomain: any = domainParts[domainParts.length - 1]
  /* tslint:disable:triple-equals */
  if (domainParts.length === 4 && parseInt(subDomain, 10) == subDomain) {
    return cookies.get(name)
  }

  let created
  if (data) {
    created = setCookie(domainParts, name, options, data)
  }
  return cookies.get(name)
}
<commit_msg>fix(src) fix cookie domain setting<commit_after>import * as cookies from 'js-cookie'

function removeNaked (): string {
  const domain = `${location.hostname}`
  return domain.indexOf('www.') === 0 ? domain.substring(4) : domain
}

export function _set (
  domainParts: Array<string>,
  name: string,
  options: cookies.CookieAttributes,
  data: string | object
): string | undefined {
  let domain = domainParts[domainParts.length - 1]
  let attr: cookies.CookieAttributes = options
  for (let i = 2; i <= domainParts.length; i++) {
    domain = `${domainParts[domainParts.length - i]}.${domain}`
    attr.domain = domain
    cookies.set(name, data, attr)
    const storedId = cookies.get(name)
    if (storedId) {
      return domain
    }
  }
  cookies.set(name, data, options)
  return cookies.get(name)
}

function findOrCreate (
  name: string,
  options: cookies.CookieAttributes,
  data?: string | object
): string | undefined {
  const value = cookies.get(name)
  if (value) {
    return value
  }
  const domainParts: Array<string> = removeNaked().split('.')
  const subDomain: any = domainParts[domainParts.length - 1]
  /* tslint:disable:triple-equals */
  if (domainParts.length === 4 && parseInt(subDomain, 10) == subDomain) {
    return cookies.get(name)
  }

  if (data) {
    _set(domainParts, name, options, data)
  }
  return cookies.get(name)
}

{'fraction_non_alphanumeric': 0.13716974303293522, 'fraction_numerical': 0.00579080709373869, 'mean_word_length': 3.732876712328767, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3771697', 'n_tokens_mistral': 883, 'n_tokens_neox': 884, 'n_words': 226}