dodo / node-slug

slugifies even utf-8 chars!
MIT License
1.07k stars 94 forks source link

C vs. C# produce same slug "c" #35

Closed anthonyettinger closed 9 years ago

anthonyettinger commented 9 years ago

This is causing a duplicate key error in my database.

C# is slugified to c, which conflicts with slug for C. Is there anyway to override this? Like maybe replacing # with sharp or pound.

ralyodio commented 9 years ago

I found a solution. Without being too destructive.

    //overrides
    if ( this.nameLower === 'c#' ) {
        slug.charmap['#'] = 'sharp';
    } else if ( this.nameLower === '.net' ) {
        slug.charmap['.'] = 'dot';
    } else if ( this.nameLower === 'c++' ) {
        slug.charmap['+'] = 'plus';
    }
dodo commented 9 years ago

Nice, that you found a good solution so quickly. Your example is a very specific case of replacement logic which would be better suited as a small library instead of a feature of this package, IMHO.