vinkla / hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
https://hashids.org/php
MIT License
5.26k stars 417 forks source link

decodeToString method, for simple decoding #196

Closed beregovoy closed 8 months ago

beregovoy commented 8 months ago

My case of using your lib is usually encode/decode simple integer ID. So after every decode i have to get first value of this array. I never used array of decoded variables so need at simple method which will just return me string of imploded values of decode.

I used my own class, which extends lib, on my projects, but want to offer you little function to add this functional )

I added simple method like helper.

public function decodeToString(string $hash): string
{
    return implode($this->decode($hash));
}

Tests was extended also :)

vinkla commented 8 months ago

Thanks for the suggestion. This is something I won't add to the package. I leave it up to users to implement this functionality instead.