ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - jsonmaur/namor: A subdomain-safe name generator
A subdomain-safe name generator. Contribute to jsonmaur/namor development by creating an account on GitHub.
Visit Site

GitHub - jsonmaur/namor: A subdomain-safe name generator

GitHub - jsonmaur/namor: A subdomain-safe name generator

Namor

Namor is a name generator for Elixir that creates random, url-friendly names. This comes in handy if you need to generate unique subdomains like many PaaS/SaaS providers do, or unique names for anything else. Supports compile-time dictionary loading, subdomain validation with reserved names, custom dictionaries and reserved word lists, alternate dictionaries, and more.

See a demo here. Also available for Javascript.

Please Note: Generated names are not always guaranteed to be unique. To reduce the chances of collision, you can increase the length of the trailing number (see here for collision stats). Always be sure to check your database before assuming a generated value is unique.

Installation

def deps do
  [
    {:namor, "~> 1.0"}
  ]
end

Getting Started

iex> require Namor

iex> Namor.generate()
{:ok, "sandwich-invent"}

iex> Namor.generate(salt: 5)
{:ok, "sandwich-invent-s86uo"}

iex> Namor.generate(words: 3, dictionary: :rugged)
{:ok, "savage-whiskey-stain"}

An example module that generates subdomains for users (does not check for database uniqueness):

defmodule MyApp.Subdomains do
  use Namor

  @salt_length 5

  def get_new_subdomain(nil), do: Namor.generate(salt: @salt_length)

  def get_new_subdomain(name) do
    with false <- Namor.reserved?(name),
         subdomain <- Namor.with_salt(name, @salt_length),
         true <- Namor.subdomain?(subdomain) do
      {:ok, subdomain}
    else
      _ -> {:error, :invalid_subdomain}
    end
  end
end

Collision Stats

The following stats give you the total number of permutations based on the word count (without a salt), and can help you make a decision on how long to make your salt. This data is based on the number of words we currently have in our dictionary files.

:default dictionary
  • 1-word combinations: 7,948
  • 2-word combinations: 11,386,875
  • 3-word combinations: 12,382,548,750
  • 4-word combinations: 23,217,278,906,250
:rugged dictionary
  • 1-word combinations: 735
  • 2-word combinations: 127,400
  • 3-word combinations: 14,138,880
  • 4-word combinations: 3,958,886,400

Custom Dictionaries

In order for our dictionary files to be loaded into your application during compilation, generate/1 and reserved?/1 are defined as a macros. This means they can only be used after calling use Namor or require Namor, which should be done during compilation (and not inside a function). If you want to use your own dictionary, consider calling Namor.Helpers.get_dict!/2 in a place that executes during compilation and not runtime. For example:

┌── dictionaries/
│  ┌── foobar/
│  │  ┌── adjectives.txt
│  │  ├── nouns.txt
│  │  └── verbs.txt
│  └── reserved.txt
defmodule MyApp.Subdomains do
  use Namor

  @salt_length 5
  @base_path Path.expand("./dictionaries", __DIR__)

  @reserved Namor.Helpers.get_dict!("reserved.txt", @base_path)
  @dictionary Namor.Helpers.get_dict!(:foobar, @base_path)

  defp reserved, do: @reserved
  defp dictionary, do: @dictionary

  def get_new_subdomain(nil), do: Namor.generate([salt: @salt_length], dictionary())

  def get_new_subdomain(name) do
    with false <- Namor.reserved?(name, reserved()),
         subdomain <- Namor.with_salt(name, @salt_length),
         true <- Namor.subdomain?(subdomain) do
      {:ok, subdomain}
    else
      _ -> {:error, :invalid_subdomain}
    end
  end
end

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory