summaryrefslogtreecommitdiff
path: root/app/models/packages/npm.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/packages/npm.rb')
-rw-r--r--app/models/packages/npm.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/packages/npm.rb b/app/models/packages/npm.rb
new file mode 100644
index 00000000000..e49199d911c
--- /dev/null
+++ b/app/models/packages/npm.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+module Packages
+ module Npm
+ # from "@scope/package-name" return "scope" or nil
+ def self.scope_of(package_name)
+ return unless package_name
+ return unless package_name.starts_with?('@')
+ return unless package_name.include?('/')
+
+ package_name.match(Gitlab::Regex.npm_package_name_regex)&.captures&.first
+ end
+ end
+end