nameFromURL
lib.nameFromURL
Docs pulled from | This Revision | 10 minutes ago
Extract name and version from a URL as shown in the examples.
Separator sep
is used to determine the end of the extension.
Inputs
url
- 1. Function argument
sep
- 2. Function argument
Type
nameFromURL :: String -> String
Examples
lib.strings.nameFromURL
usage example
nameFromURL "https://nixos.org/releases/nix/nix-1.7/nix-1.7-x86_64-linux.tar.bz2" "-"
=> "nix"
nameFromURL "https://nixos.org/releases/nix/nix-1.7/nix-1.7-x86_64-linux.tar.bz2" "_"
=> "nix-1.7-x86"
Noogle detected
Implementation
The following is the current implementation of this function.
nameFromURL = url: sep:
let
components = splitString "/" url;
filename = lib.last components;
name = head (splitString sep filename);
in assert name != filename; name;