Skip to content

dwyl/link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

68 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

link

πŸ”— Parse, shorten and format links.

GitHub Workflow Status codecov.io Hex.pm docs Libraries.io dependency status contributions welcome HitCount

Why? πŸ€·β€β™€οΈ

We didn't find a link parsing library that did exactly what we needed so we wrote one.

What?

A micro library for parsing and formatting links for use in our App (currently in the MVP )

Note: the code is deliberately "basic". not at all "fancy" that is intentional so that it's understandable by a complete beginner to Elixir. πŸ”° Simple code is maintainable and extensible without having to waste time Googling to figure it out. That said, if you want to help refactoring for performance, please open an issue.

Who? πŸ‘€

The link library was created for us by us, the people building & using the @dwyl App. Ref: mvp#141
We don't expect this to be used by anyone else because it's probably too specific to our use case. But if you need to parse links (URLs) in your project link can help you! Checkout the API Reference.

Feedback πŸ’¬

Any feedback is very welcome. If you need a specific feature, please open an issue


How? πŸ‘©β€πŸ’»

Use this package in your Elixir / Phoenix App!

Installation ⬇️

Add link to your list of dependencies in your mix.exs file:

def deps do
  [
    {:link, "~> 1.0.11"}
  ]
end

Complete Docs: hexdocs.pm/link

Usage Examples πŸ”—

Here are a few examples we use in our MVP:

# Compact a GitHub issue URL so it doesn't waste screen space:
Link.compact("https://github.com/dwyl/mvp/issues/141")
> "dwyl/mvp#141"

# Strip the #issuecomment... from a GitHub issue URL:
Link.compact("https://github.com/dwyl/mvp/issues/141#issuecomment-1636209664")
> "dwyl/mvp#141"

# Find all RFC 3986 URLs in a String or block of text:
Link.find("My text with links http://goo.gl/3co4ae and https://git.io/top and www.dwyl.com etc.")
> ["http://goo.gl/3co4ae", "https://git.io/top", "www.dwyl.com"]

# Shorten the link using Linky (interface TBD)
Link.shorten(conn, "https://github.com/dwyl/mvp/issues/141")
> "dwy.is/mvp-141"

# Confirm if a Link (URL) is valid
Link.valid?("example")
> false
Link.valid?("https://example.com")
> true

# Find all instances of a URL in a block of text
#Β and replaces them with the "compact" version.
md = "# Hello World! https://github.com/dwyl/mvp/issues/141#issuecomment-1657954420 and https://mvp.fly.dev/"
Link.find_replace_compact(md)
"# Hello World! [dwyl/mvp#141](https://github.com/dwyl/mvp/issues/141#issuecomment-1657954420) and [mvp.fly.dev](https://mvp.fly.dev/)"

Contributing πŸ™

The easiest way to contribute is to help us extend the test/sample_urls.csv file with more valid and invalid URLs. πŸ“

Need More? πŸ™Œ

If you need a specific function, please open an issue to discuss.

Research πŸ”

If you're curious about URL RegEx, read: mathiasbynens.be/demo/url-regex

According to jasontucker.blog/8945/what-is-the-longest-tld The longest TLD you can get in 2023 is cancerresearch. Someone thought it was a good idea to have labname.cancerresearch as their domain ... a 14-letter TLD ... πŸ™„ But there are other 13-letter TLDs such as INTERNATIONAL ...

About

πŸ”— Parse, shorten and format links.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages