index.js 504 B

123456789101112131415161718
  1. /*!
  2. * dashify <https://github.com/jonschlinkert/dashify>
  3. *
  4. * Copyright (c) 2015-2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. module.exports = (str, options) => {
  9. if (typeof str !== 'string') throw new TypeError('expected a string');
  10. return str.trim()
  11. .replace(/([a-z])([A-Z])/g, '$1-$2')
  12. .replace(/\W/g, m => /[À-ž]/.test(m) ? m : '-')
  13. .replace(/^-+|-+$/g, '')
  14. .replace(/-{2,}/g, m => options && options.condense ? '-' : m)
  15. .toLowerCase();
  16. };