test-custom.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* global describe,it */
  2. var getSlug = require('../lib/speakingurl');
  3. describe('getSlug with custom replacement', function () {
  4. 'use strict';
  5. it('should be transliterated', function (done) {
  6. getSlug('буу', {
  7. lang: false,
  8. custom: {
  9. 'б': 'б',
  10. 'у': 'у'
  11. }
  12. })
  13. .should.eql('буу');
  14. getSlug('[nodejs]', {
  15. custom: {
  16. '[': '[',
  17. ']': ']'
  18. }
  19. })
  20. .should.eql('[nodejs]');
  21. getSlug('[Äpfel]', {
  22. custom: {
  23. '[': '[',
  24. ']': ']'
  25. }
  26. })
  27. .should.eql('[aepfel]');
  28. getSlug('[Äpfel]', {
  29. lang: false,
  30. custom: {
  31. '[': '[',
  32. ']': ']'
  33. }
  34. })
  35. .should.eql('[aepfel]');
  36. done();
  37. });
  38. it('should be extended with allowed chars', function (done) {
  39. getSlug('буу', {
  40. custom: ['б', 'у']
  41. })
  42. .should.eql('буу');
  43. getSlug('[Knöpfe]', {
  44. custom: ['[', ']']
  45. })
  46. .should.eql('[knoepfe]');
  47. getSlug('[Knöpfe & Ösen]', {
  48. custom: ['[', ']']
  49. })
  50. .should.eql('[knoepfe-and-oesen]');
  51. getSlug('[Knöpfe & Ösen]', {
  52. custom: ['[', ']'],
  53. lang: 'de'
  54. })
  55. .should.eql('[knoepfe-und-oesen]');
  56. getSlug('[Knöpfe]', {
  57. maintainCase: true,
  58. custom: ['[', ']']
  59. })
  60. .should.eql('[Knoepfe]');
  61. getSlug('[Knöpfe haben Löcher]', {
  62. titleCase: true,
  63. custom: ['[', ']']
  64. })
  65. .should.eql('[Knoepfe-Haben-Loecher]');
  66. getSlug('[knöpfe haben runde löcher]', {
  67. titleCase: ['haben', 'runde'],
  68. custom: ['[', ']']
  69. })
  70. .should.eql('[Knoepfe-haben-runde-Loecher]');
  71. getSlug('[knöpfe haben runde löcher]', {
  72. titleCase: ['haben', 'runde'],
  73. maintainCase: true,
  74. custom: ['[', ']']
  75. })
  76. .should.eql('[Knoepfe-haben-runde-Loecher]');
  77. done();
  78. });
  79. });