Skip to content

trananhtung/parse-author

Repository files navigation

parse-author

All Contributors

Crates.io Documentation CI License

Parse an npm-style author string"Name <email> (url)" — into its name, email, and url. The format used by package.json author/contributors fields. A faithful Rust port of the parse-author npm package (and the author-regex it is built on). Zero dependencies and #![no_std].

use parse_author::parse_author;

let a = parse_author("Jon Schlinkert <jon@example.com> (https://github.com/jonschlinkert)");
assert_eq!(a.name.as_deref(), Some("Jon Schlinkert"));
assert_eq!(a.email.as_deref(), Some("jon@example.com"));
assert_eq!(a.url.as_deref(), Some("https://github.com/jonschlinkert"));

assert_eq!(parse_author("Jane Doe").name.as_deref(), Some("Jane Doe"));
assert_eq!(parse_author("<me@example.com>").email.as_deref(), Some("me@example.com"));

Why parse-author?

Tooling that reads package.json — license checkers, SBOM generators, registry mirrors, JS-build-tool ports — needs to pull the name, email, and homepage out of an author string. The shape is simple but has corners (each part optional, brackets decide the field), and this matches the canonical JS parser exactly.

[dependencies]
parse-author = "0.1"

API

Item Purpose
parse_author(input) Parse into an Author
Author { name, email, url } Each an Option<String>, present only when found

Behavior

  • The name is everything before the first < or (, trimmed.
  • A <…> segment is the email; a (…) segment is the url (the opening bracket decides the field — <…) still parses as an email).
  • An input with no word character, or one that doesn't fit the Name <email> (url) shape (an unterminated bracket, trailing junk), yields an empty Author.

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.

Thanks goes to these wonderful people:

Tung Tran
Tung Tran

💻 🚧

License

Licensed under either of Apache-2.0 or MIT at your option.

About

Parse an npm-style author string 'Name <email> (url)' into its name, email, and url. A faithful Rust port of the parse-author npm package. Zero deps, no_std.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages