2017-04-01 21:07:01 +00:00
|
|
|
'use strict'
|
2016-08-30 02:19:47 +00:00
|
|
|
|
2017-05-28 02:24:46 +00:00
|
|
|
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'
|
2017-02-09 01:52:37 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
module.exports = {
|
|
|
|
/**
|
|
|
|
* Convert raw path to safe path
|
|
|
|
* @param {string} rawPath Raw path
|
|
|
|
* @returns {string} Safe path
|
|
|
|
*/
|
|
|
|
makeSafePath: (rawPath) => {
|
2017-05-28 02:24:46 +00:00
|
|
|
let rawParts = split(trim(rawPath), '/')
|
|
|
|
rawParts = map(rawParts, (r) => {
|
|
|
|
return kebabCase(deburr(trim(r)))
|
2017-04-01 21:07:01 +00:00
|
|
|
})
|
2017-02-10 01:24:28 +00:00
|
|
|
|
2017-05-28 02:24:46 +00:00
|
|
|
return join(filter(rawParts, (r) => { return !isEmpty(r) }), '/')
|
2017-04-01 21:07:01 +00:00
|
|
|
}
|
|
|
|
}
|