{"size": 3133, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/pkg/scribblings/name.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-doc/pkg/scribblings/name.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-doc/pkg/scribblings/name.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 39.6582278481, "max_line_length": 96, "alphanum_fraction": 0.6358123205}
#lang scribble/manual
@(require (for-label racket/base
                     racket/contract/base
                     pkg/name))
                     

@title[#:tag "name"]{Package Source Parsing}

@defmodule[pkg/name]{The @racketmodname[pkg/name] library provides
functions for parsing and normalizing a package source, especially for
extracting a package name.}


@defproc[(package-source-format? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is @racket['name] , @racket['file],
@racket['dir], @racket['git], @racket['github], @racket['clone], @racket['file-url],
@racket['dir-url], @racket['link], or @racket['static-link], and
returns @racket[#f] otherwise.

The @racket['link] and @racket['static-link] formats are the same as
@racket['dir] in terms of parsing, but they are treated differently
for tasks such as package installation. The @racket['clone] format
is similarly the same as @racket['github] or @racket['git] in terms of
parsing.

@history[#:changed "6.1.1.1" @elem{Added @racket['git].}
         #:changed "6.1.1.5" @elem{Added @racket['clone].}]}


@defproc[(package-source->name [source string?]
                               [type (or/c package-source-format? #f)
                                #f])
          (or/c #f string?)]{

Extracts the @tech{package name} from a @tech{package source}, where
the package source type is inferred if @racket[type] is @racket[#f].
If a valid name cannot be inferred, the result is @racket[#f].}


@defproc[(package-source->name+type [source string?]
                                    [type (or/c package-source-format? #f) #f]
                                    [#:complain complain-proc (string? string? . -> . any) void]
                                    [#:must-infer-name? must-infer-name? boolean? #f]
                                    [#:link-dirs? link-dir? boolean?])
          (values (or/c #f string?)
                  (or/c package-source-format? #f))]{

Like @racket[package-source->name], but also returns the type of the
source (which is useful when the type is inferred). If the source is
not well-formed, the second result can be @racket[#f].

The @racket[complain-proc] function is applied when @racket[source] is
ill-formed. The arguments to @racket[complain-proc] are
@racket[source] and an error message.

If @racket[must-infer-name?] is true, then @racket[complain-proc]
is called if a valid name cannot be inferred from @racket[source].

If @racket[link-dirs?] is true, then a directory path is reported as
type @racket['link] instead of @racket['dir].}


@defproc[(package-source->path [source string?]
                               [type (or/c #f 'file 'dir 'link 'static-link) #f])
         path?]{

Converts a file or directory package source to a filesystem path.

The @racket[package-source->path] function is different from
@racket[string->path] in the case that @racket[source] starts with
@litchar{file://}. Also, if @racket[type] is @racket['dir],
@racket['link], or @racket['static-link], then
@racket[path->directory-path] is used to ensure that the result path
refers to a directory.

@history[#:added "10.0.1.11"]}

