{"id":22025167,"url":"https://github.com/drexed/lite-uxid","last_synced_at":"2025-05-07T09:34:28.287Z","repository":{"id":34978802,"uuid":"193734528","full_name":"drexed/lite-uxid","owner":"drexed","description":"Generate or obfuscate Id's using different patterns","archived":false,"fork":false,"pushed_at":"2024-10-15T23:41:51.000Z","size":132,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-15T12:03:41.738Z","etag":null,"topics":["hashid","nanoid","rails","ruby","ulid","uxid"],"latest_commit_sha":null,"homepage":"http://drexed.github.io/lite-uxid","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drexed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-25T15:26:13.000Z","updated_at":"2024-10-09T03:25:27.000Z","dependencies_parsed_at":"2024-11-30T07:14:55.730Z","dependency_job_id":"f09a822b-a136-460e-8080-276a4e46a3cc","html_url":"https://github.com/drexed/lite-uxid","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":"0.020408163265306145","last_synced_commit":"0f5fa0f544712bb3db448cdeeeb4d65ae7548686"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-uxid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-uxid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-uxid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drexed%2Flite-uxid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drexed","download_url":"https://codeload.github.com/drexed/lite-uxid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252851629,"owners_count":21814185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hashid","nanoid","rails","ruby","ulid","uxid"],"created_at":"2024-11-30T07:14:46.773Z","updated_at":"2025-05-07T09:34:28.237Z","avatar_url":"https://github.com/drexed.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lite::Uxid\n\n[![Gem Version](https://badge.fury.io/rb/lite-uxid.svg)](http://badge.fury.io/rb/lite-uxid)\n[![Build Status](https://travis-ci.org/drexed/lite-uxid.svg?branch=master)](https://travis-ci.org/drexed/lite-uxid)\n\nLite::Uxid is a library for generating or obfuscating ID's based on different patterns.\nIt's very useful to hide the number of resources in your database and protect against enumeration attacks.\nBy default, it implements websafe variants of each type.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'lite-uxid'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install lite-uxid\n\n## Table of Contents\n\n* [Configuration](#configuration)\n* [Usage](#usage)\n* [Options](#options)\n* [Reversible](#reversible)\n    * [HashID](#hashid)\n    * [ObfuscateID](#obfuscateid)\n* [Irreversible](#Irreversible)\n    * [NanoID](#nanoid)\n    * [ULID](#ulid)\n    * [UUID](#uuid)\n* [ActiveRecord](#active_record)\n* [Benchmarks](#benchmarks)\n\n## Configuration\n\n`rails g lite:uxid:install` will generate the following file in your application root:\n`config/initalizers/lite_uxid.rb`\n\n```ruby\nLite::Uxid.configure do |config|\n  # HashID\n  config.hashid_charset = Lite::Uxid::ALPHANUMERIC\n  config.hashid_salt = 1_369_136\n\n  # NanoID\n  config.nanoid_charset = Lite::Uxid::WEB_SAFE\n  config.nanoid_size = 21\n\n  # ObfuscatedID\n  config.obfuscateid_spin = 0\n\n  # ULID\n  config.ulid_charset = Lite::Uxid::COCKFORDS_32\n  config.ulid_size = 26\n\n  # UUID\n  config.uuid_version = 4\nend\n```\n\n## Usage\n\n### Instance call\n\n```ruby\ncoder = Lite::Uxid::Reversible::Hashid.new(10, size: 12)\ncoder.encode #=\u003e '67wGI0'\n```\n\n### Class call\n```ruby\nLite::Uxid::Reversible::Hashid.decode('67wGI0', size: 12) #=\u003e 10\n```\n\n## Options\n\nLocal options can be passed to override global options.\n\n```ruby\nLite::Uxid::Irreversible::Ulid.encode(charset: 'abc123', size: 12) #=\u003e 'a3b12c12c3ca'\n```\n\nPassable options are:\n\n```ruby\n{\n  charset: 'string',  # Available for: hashid, nanoid, ulid\n  salt:    'string',  # Available for: hashid\n  size:    'integer', # Available for: nanoid, ulid\n  spin:    'integer', # Available for: obfuscateid\n  version: 'integer', # Available for: uuid\n  prefix:  'string'   # Available for: hashid, nanoid, ulid, uuid\n}\n```\n\n## Reversible\n\n### HashID\n\n- [More information](https://hashids.org)\n\n```ruby\nLite::Uxid::Reversible::Hashid.encode(10)             #=\u003e '7pau2oXSklq0'\nLite::Uxid::Reversible::Hashid.decode('7pau2oXSklq0') #=\u003e 10\n```\n\n### NanoID\n\n- [More information](https://github.com/ai/nanoid)\n\n```ruby\nLite::Uxid::Irreversible::Nanoid.encode #=\u003e 'sMuNUa3Cegn6r5GRQ4Ij2'\n```\n\n## Irreversible\n\n### ObfuscateID\n\n- [More information](https://github.com/namick/scatter_swap)\n\n```ruby\nLite::Uxid::Reversible::Obfuscateid.encode(10)         #=\u003e 2056964183\nLite::Uxid::Reversible::Obfuscateid.decode(2056964183) #=\u003e 10\n```\n\n### ULID\n\n- [More information](https://github.com/ulid/spec)\n\n```ruby\nLite::Uxid::Irreversible::Ulid.encode #=\u003e '01GJAY9KGR539EZF4QWYEJGSN7'\n```\n\n### UUID\n\nImplements `v4` and `v7` of the specification.\n- [More information](https://en.wikipedia.org/wiki/Universally_unique_identifier)\n\n```ruby\nLite::Uxid::Irreversible::Uuid.encode #=\u003e '4376a67e-1189-44b3-a599-7f7566bf105b'\n```\n\n## ActiveRecord\n\n### Table\n\nAdd the following attribute to all corresponding tables.\n\n```ruby\n# NOTE: null: true has to be set for HashID's\n# since an ID must exist before it gets created.\nt.string :uxid, null: false, index: { unique: true }\n```\n\nIf using UUID or ULID and your database supports it:\n\n```ruby\nt.uuid :uxid, null: false, index: { unique: true }\n```\n\n**Setup**\n\n`uxid` attribute will be automatically generated and applied when the record is created.\n\n### Mixin\n```ruby\nclass User \u003c ActiveRecord::Base\n  # Pick one:\n  include Lite::Uxid::Record::Hashid\n  include Lite::Uxid::Record::Nanoid\n  include Lite::Uxid::Record::Obfuscateid\n  include Lite::Uxid::Record::Ulid\n  include Lite::Uxid::Record::Uuid\nend\n```\n\nHashID, NanoID, ULID, and UUID modules allow prefixing via the `uxid_prefix` method.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  include Lite::Uxid::Record::Hashid\n\n  def uxid_prefix\n    \"usr_\"\n  end\nend\n```\n\nUsing the `hashid` and `nanoid` above provide handy methods to find records by uxid.\n\n```ruby\nuser = User.new\nuser.id_to_uxid #=\u003e Encodes the records id to uxid\nuser.uxid_to_id #=\u003e Decodes the records uxid to id\n\nUser.find_by_uxid('x123')  #=\u003e Find record by uxid\nUser.find_by_uxid!('x123') #=\u003e Raises an ActiveRecord::RecordNotFound error if not found\n```\n\n## Benchmarks\n\nThe classes ranked from fastest to slowest are `UUID`, `HashID`, `NanoID`, `ULID`, and `ObfuscateID`. Here are the latest results:\n\n```\nCalculating -------------------------------------\n              Hashid    135.993k (± 2.9%) i/s    (7.35 μs/i) -    681.588k in   5.016413s\n         Obfuscateid     30.702k (± 2.2%) i/s   (32.57 μs/i) -    155.907k in   5.080592s\n              NanoID     99.327k (± 1.5%) i/s   (10.07 μs/i) -    504.135k in   5.076630s\n                ULID     82.211k (± 2.3%) i/s   (12.16 μs/i) -    418.455k in   5.092823s\n             UUID v4    237.629k (± 6.8%) i/s    (4.21 μs/i) -      1.190M in   5.040477s\n             UUID v7    234.956k (±13.8%) i/s    (4.26 μs/i) -      1.153M in   5.051057s\n\nComparison:\n             UUID v4:   237629.0 i/s\n             UUID v7:   234955.9 i/s - same-ish: difference falls within error\n              Hashid:   135993.5 i/s - 1.75x  slower\n              NanoID:    99327.3 i/s - 2.39x  slower\n                ULID:    82210.7 i/s - 2.89x  slower\n         Obfuscateid:    30702.0 i/s - 7.74x  slower\n```\n\nView how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/drexed/lite-uxid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Lite::Uxid project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/drexed/lite-uxid/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrexed%2Flite-uxid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrexed%2Flite-uxid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrexed%2Flite-uxid/lists"}