#npm-package #validate #name #error #warnings #true

validate_npm_package_name

A crate to validate npm package name

1 unstable release

0.1.0 Oct 10, 2024

#2 in #true

Download history 109/week @ 2024-10-05 29/week @ 2024-10-12 6/week @ 2024-10-19 1/week @ 2024-10-26

65 downloads per month
Used in npm_pkg

MIT license

7KB
92 lines

validate_npm_package_name

A crate to validate npm package name

Install

cargo add validate_npm_package_name

Usage

Valid Names

use validate_npm_package_name::validate;

validate(&String::from("some-package"));
validate(&String::from("@npm/abc"));

Validate Result

validate_npm_package_name::ValidateResult {
    valid_for_new_packages: true,
    valid_for_old_packages: true,
    warnings: None,
    errors: None
}

Invalid Names

use validate_npm_package_name::validate;

validate(&String::from("s/l/a/s/h/e/s"));

Validate Result

validate_npm_package_name::ValidateResult {
    valid_for_new_packages: true,
    valid_for_old_packages: true,
    warnings: None,
    errors: Some(vec![String::from(
        "name can only contain URL-friendly characters"
    )])
}

Dependencies

~2.2–3MB
~55K SLoC