Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

validate-npm-package-name

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-npm-package-name - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

8

example.js

@@ -5,3 +5,2 @@ var valid = require("./")

validate("example.com") // => {valid: true}
validate("CAPITALS") // => {valid: true}
validate("under_score") // => {valid: true}

@@ -16,1 +15,8 @@ validate("123numeric") // => {valid: true}

validate("_flodash") // => {valid: false, errors:["name cannot start with an underscore"]}
validate("CAPITALS") // => {valid: false, errors:["name must be lowercase"]}
// Nowadays, package names have to be lowercase
// To validate older packages, do this:
validate("CAPITALS",
{allowMixedCase: true}) // => {valid: true}
var scopedPackagePattern = new RegExp("^(?:@([^/]+?)[/])?([^/]+?)$")
var validate = module.exports = function(name) {
var validate = module.exports = function(name, options) {
var errors = []
if (!options) {
options = {
allowMixedCase: false
}
}
if (name === null) {

@@ -42,2 +48,6 @@ errors.push("name cannot be null")

if (name.toLowerCase() !== name && !options.allowMixedCase) {
errors.push("name must be lowercase")
}
if (encodeURIComponent(name) !== name) {

@@ -44,0 +54,0 @@

2

package.json
{
"name": "validate-npm-package-name",
"version": "1.0.1",
"version": "1.1.0",
"description": "Give me a string and I'll tell you if it's a valid npm package name",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,3 +9,2 @@ var valid = require("..")

t.deepEqual(valid("example.com"), {valid: true})
t.deepEqual(valid("CAPITAL-LETTERS"), {valid: true})
t.deepEqual(valid("under_score"), {valid: true})

@@ -22,2 +21,6 @@ t.deepEqual(valid("period.js"), {valid: true})

t.deepEqual(valid(""), {
valid: false,
errors: ["name length must be greater than zero"]})
t.deepEqual(valid(".start-with-period"), {

@@ -51,3 +54,14 @@ valid: false,

// Legacy Mixed-Case
t.deepEqual(valid("CAPITAL-LETTERS", {allowMixedCase: true}), {valid: true})
t.deepEqual(valid("CAPITAL-LETTERS"), {
valid: false,
errors: ["name must be lowercase"]})
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc