pages.js 662 Bytes
Newer Older
1
'use strict'
2

3 4 5 6 7 8 9 10
import deburr from 'lodash/deburr'
import filter from 'lodash/filter'
import isEmpty from 'lodash/isEmpty'
import join from 'lodash/join'
import kebabCase from 'lodash/kebabCase'
import map from 'lodash/map'
import split from 'lodash/split'
import trim from 'lodash/trim'
11

12 13 14 15 16 17 18
module.exports = {
  /**
   * Convert raw path to safe path
   * @param {string} rawPath Raw path
   * @returns {string} Safe path
   */
  makeSafePath: (rawPath) => {
19 20 21
    let rawParts = split(trim(rawPath), '/')
    rawParts = map(rawParts, (r) => {
      return kebabCase(deburr(trim(r)))
22
    })
23

24
    return join(filter(rawParts, (r) => { return !isEmpty(r) }), '/')
25 26
  }
}