<commit_before>import filter from 'lodash.filter'
import map from 'lodash.map'
import trim from 'lodash.trim'

const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/')

export const parse = (remote) => {
  const [type, rest] = remote.url.split('://')
  if (type === 'file') {
    remote.type = 'local'
    remote.path = `/${rest}` // FIXME the heading slash has been forgotten on client side first implementation
  } else if (type === 'nfs') {
    remote.type = 'nfs'
    const [host, share] = rest.split(':')
    remote.path = `/tmp/xo-server/mounts/${remote.id}`
    remote.host = host
    remote.share = share
  } else if (type === 'smb') {
    remote.type = 'smb'
    const [auth, smb] = rest.split('@')
    const [username, password] = auth.split(':')
    const [domain, sh] = smb.split('\\\\')
    const [host, path] = sh.split('\0')
    remote.host = host
    remote.path = path
    remote.domain = domain
    remote.username = username
    remote.password = password
  }
  return remote
}

export const compose = ({type, host, path, username, password, domain}) => {
  let url = `${type}://`
  if (type === 'nfs') {
    url += `${host}:`
  }
  if (type === 'smb') {
    url += `${username}:${password}@${domain}\\\\${host}`
  }
  path = sanitizePath(path)
  if (type === 'smb') {
    path = path.split('/')<commit_msg>method rename<commit_after>import filter from 'lodash.filter'
import map from 'lodash.map'
import trim from 'lodash.trim'

const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/')

export const parse = (remote) => {
  const [type, rest] = remote.url.split('://')
  if (type === 'file') {
    remote.type = 'local'
    remote.path = `/${rest}` // FIXME the heading slash has been forgotten on client side first implementation
  } else if (type === 'nfs') {
    remote.type = 'nfs'
    const [host, share] = rest.split(':')
    remote.path = `/tmp/xo-server/mounts/${remote.id}`
    remote.host = host
    remote.share = share
  } else if (type === 'smb') {
    remote.type = 'smb'
    const [auth, smb] = rest.split('@')
    const [username, password] = auth.split(':')
    const [domain, sh] = smb.split('\\\\')
    const [host, path] = sh.split('\0')
    remote.host = host
    remote.path = path
    remote.domain = domain
    remote.username = username
    remote.password = password
  }
  return remote
}

export const format = ({type, host, path, username, password, domain}) => {
  let url = `${type}://`
  if (type === 'nfs') {
    url += `${host}:`
  }
  if (type === 'smb') {
    url += `${username}:${password}@${domain}\\\\${host}`
  }
  path = sanitizePath(path)
  if (type === 'smb') {
    path = path.split('/')
{'fraction_non_alphanumeric': 0.2085889570552147, 'fraction_numerical': 0.0007217610970768675, 'mean_word_length': 3.0526315789473686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1067619', 'n_tokens_mistral': 946, 'n_tokens_neox': 951, 'n_words': 252}