Something went wrong. Try again.
This string has no description
Something went wrong. Try again.
731 B · 20 lines · Created 1d ago
Rust
123456789101112131415161718192021const MAXIMUM_PACKAGE_NAME_LEN: usize = 214;
fn is_safe_name(name: &str) -> bool { let (scope, package) = match name.strip_prefix("@") { Some(rest) => match rest.split_once("/") { Some((scope, package)) => (Some(scope), package), None => return false, }, None => (None, name), };
name.len() <= MAXIMUM_PACKAGE_NAME_LEN && !matches!(package, "node_modules") && scope.into_iter().chain([package]).all(|segment| { !matches!(segment.as_bytes().first(), None | Some(b'.' | b'_')) && segment .bytes() .all(|b| matches!(b, b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~')) })}