aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-07 23:23:34 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-07 23:23:34 -0700
commitcc2c50ad0918cd37dc74c87327791e9db9c62175 (patch)
tree6f034a669ae5d61f46c5e4f301b90f648c26781d /src/string_immutable.zig
parentf990df97ce533d2a2f6b017c5e3eb6e0c153d5e4 (diff)
downloadbun-cc2c50ad0918cd37dc74c87327791e9db9c62175.tar.gz
bun-cc2c50ad0918cd37dc74c87327791e9db9c62175.tar.zst
bun-cc2c50ad0918cd37dc74c87327791e9db9c62175.zip
[bun install] Implement `bun link`
Diffstat (limited to '')
-rw-r--r--src/string_immutable.zig38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 4d856b966..540572b6f 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -82,6 +82,44 @@ pub inline fn containsAny(in: anytype, target: string) bool {
return false;
}
+/// https://docs.npmjs.com/cli/v8/configuring-npm/package-json
+/// - The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
+/// - The names of scoped packages can begin with a dot or an underscore. This is not permitted without a scope.
+/// - New packages must not have uppercase letters in the name.
+/// - The name ends up being part of a URL, an argument on the command line, and
+/// a folder name. Therefore, the name can't contain any non-URL-safe
+/// characters.
+pub inline fn isNPMPackageName(target: string) bool {
+ if (target.len >= 215) return false;
+ switch (target[0]) {
+ 'a'...'z',
+ '0'...'9',
+ '$',
+ '@',
+ '-',
+ => {},
+ else => return false,
+ }
+ if (target.len == 1) return true;
+
+ var slash_count: usize = 0;
+
+ for (target[1..]) |c| {
+ switch (c) {
+ 'A'...'Z', 'a'...'z', '0'...'9', '$', '-', '_', '.' => {},
+ '/' => {
+ if (slash_count > 0) {
+ return false;
+ }
+ slash_count += 1;
+ },
+ else => return false,
+ }
+ }
+
+ return true;
+}
+
pub inline fn indexAny(in: anytype, target: string) ?usize {
for (in) |str, i| if (indexOf(str, target) != null) return i;
return null;