src/index.js
function _getContextsFromPath(path) {
  const allContexts = {
    add: [],
    remove: [],
  }
  _each(_pathContexts, pathContext => {
    let contextAdded = false
    const contexts = pathContext.contexts
    const regexes = pathContext.regexes
    const paths = pathContext.paths

    _each(regexes, regex => {
      regex.lastIndex = 0
      const matches = regex.exec(path)
      if (matches && matches.length > 0) {
        const contextsToAdd = []
        _each(contexts, context => {
          const replacedContext = context.replace(
            _contextRegex,
            (match, group) => {
              return matches[group]
            },
          )
          contextsToAdd.push(replacedContext)
        })
        allContexts.add = allContexts.add.concat(contextsToAdd)
        contextAdded = true
      }
      return !contextAdded
    })

    if (!contextAdded) {
      _each(paths, pathToTry => {
        if (path === pathToTry) {
          allContexts.add = allContexts.add.concat(contexts)
          contextAdded = true
        }
        return !contextAdded
      })
      if (!contextAdded) {
        allContexts.remove = allContexts.remove.concat(contexts)
      }
    }
  })
  return allContexts
}
function _getContextsFromPath(path) {
  const allContexts = {
    add: [],
    remove: [],
  }
  _each(_pathContexts, pathContext => {
    let contextAdded = false
    const contexts = pathContext.contexts
    const regexes = pathContext.regexes
    const paths = pathContext.paths

    _each(regexes, regex => {
      regex.lastIndex = 0
      const matches = regex.exec(path)
      if (matches && matches.length > 0) {
        const contextsToAdd = []
        _each(contexts, context => {
          const replacedContext = context.replace(
            _contextRegex,
            (match, group) => {
              return matches[group]
            },
          )
          contextsToAdd.push(replacedContext)
        })
        allContexts.add = allContexts.add.concat(contextsToAdd)
        contextAdded = true
      }
      return !contextAdded
    })

    if (!contextAdded) {
      _each(paths, pathToTry => {
        if (path === pathToTry) {
          allContexts.add = allContexts.add.concat(contexts)
          contextAdded = true
        }
        return !contextAdded
      })
      if (!contextAdded) {
        allContexts.remove = allContexts.remove.concat(contexts)
      }
    }
  })
  return allContexts
}
function _getContextsFromPath ( path ) { const allContexts = { add : [ ] , remove : [ ] , } _each ( _pathContexts , pathContext => { let contextAdded = false const contexts = pathContext . contexts const regexes = pathContext . regexes const paths = pathContext . paths _each ( regexes , regex => { regex . lastIndex = 0 const matches = regex . exec ( path ) if ( matches && matches . length > 0 ) { const contextsToAdd = [ ] _each ( contexts , context => { const replacedContext = context . replace ( _contextRegex , ( match , group ) => { return matches [ group ] } , ) contextsToAdd . push ( replacedContext ) } ) allContexts . add = allContexts . add . concat ( contextsToAdd ) contextAdded = true } return ! contextAdded } ) if ( ! contextAdded ) { _each ( paths , pathToTry => { if ( path === pathToTry ) { allContexts . add = allContexts . add . concat ( contexts ) contextAdded = true } return ! contextAdded } ) if ( ! contextAdded ) { allContexts . remove = allContexts . remove . concat ( contexts ) } } } ) return allContexts }
Gets the context paths that should be added based on the
given path and the context paths that should be removed
based ont he given path
@param {string} path
@returns {{add: Array, remove: Array}}
@private
Gets the context paths that should be added based on the given path and the context paths that should be removed based ont he given path