You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
662 B

  1. 'use strict'
  2. import deburr from 'lodash/deburr'
  3. import filter from 'lodash/filter'
  4. import isEmpty from 'lodash/isEmpty'
  5. import join from 'lodash/join'
  6. import kebabCase from 'lodash/kebabCase'
  7. import map from 'lodash/map'
  8. import split from 'lodash/split'
  9. import trim from 'lodash/trim'
  10. module.exports = {
  11. /**
  12. * Convert raw path to safe path
  13. * @param {string} rawPath Raw path
  14. * @returns {string} Safe path
  15. */
  16. makeSafePath: (rawPath) => {
  17. let rawParts = split(trim(rawPath), '/')
  18. rawParts = map(rawParts, (r) => {
  19. return kebabCase(deburr(trim(r)))
  20. })
  21. return join(filter(rawParts, (r) => { return !isEmpty(r) }), '/')
  22. }
  23. }