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"));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"| Item | Purpose |
|---|---|
parse_author(input) |
Parse into an Author |
Author { name, email, url } |
Each an Option<String>, present only when found |
- The
nameis everything before the first<or(, trimmed. - A
<…>segment is theemail; a(…)segment is theurl(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 emptyAuthor.
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 💻 🚧 |
Licensed under either of Apache-2.0 or MIT at your option.