speakingurl icon indicating copy to clipboard operation
speakingurl copied to clipboard

Using an array as custom transformations doesn't work as expected

Open atomrc opened this issue 5 years ago • 1 comments

Hi guys,

Two problems:

  • it considers the array as an object and replace number with the value at the index of the array;
  • it mutates the array and starts adding properties to it.

Here is a test case:

var getSlug = require('speakingurl');
const custom = ['b'];

const slug = getSlug('0', { custom });
console.log(slug); // => 'b', '0' has been replaced with the custom char at index 0

console.log(custom); // => [ 'b', b: 'b' ] the array has been mutated and now have a `b` property

atomrc avatar Oct 02 '18 13:10 atomrc

There are more examples of this issue:


const slug = getSlug('top 100 waterfalls', { custom: ["."] })
console.log(slug); // => top-1..-waterfalls

david-benes avatar Feb 11 '21 08:02 david-benes