npmpackagename

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

README

go-npmpackagename

Check whether a string is a valid npm package name or not

This Go module exports a single function (Validate(input []byte)) that takes a byte slice (ie., a string) as input and tells you whether it's a valid npm package name or not.

Notice that it also returns warnings to notify you about inputs that were okay by the previous npm naming rules but are no more.

For an input package name to be valid for the newer npm naming rules, this function must give no error and no warnings (empty slice).

Rules

Below the current list of rules that valid npm package names must conform to:

  • length greater than 0
  • length less than 214 characters (allowed previously)
  • no uppercase characters (allowed previously)
  • must not contain any non URL safe characters
  • must not start with a dot or an underscore
  • must not contain any of characters in [~'!()*] (allowed previously)
  • must not be the same as a Node.JS core module (allowed previously)
  • must not be the same as a string in the blacklist

Documentation

Index

Constants

View Source
const (
	WarnBuiltin = iota
	WarnTooLong
	WarnMixCase
	WarnSpecialChars
)

Variables

View Source
var (
	ErroEmpty          = errors.New("name lenght must be greater than zero")
	ErroDot            = errors.New("name cannot start with a dot")
	Erro_              = errors.New("name cannot start with an underscore")
	ErroNonURLFriendly = errors.New("name can only contain URL friendly characters")
	ErroBlacklist      = errors.New("name is in blacklist")
	ErroTrim           = errors.New("name cannot containg leading or trailing spaces")
)

Define sentinel errors

Functions

This section is empty.

Types

type Warning

type Warning int

func Validate

func Validate(input []byte) (bool, []Warning, error)

Validate validates the input npm package name.

Notice that npm newer versions follow stricter naming rules. For an input package name to be valid for newer npm rules, this function must give no error AND no warnings (empty slice).

When this function returns an error, the input package name is invalid even for previous npm naming rules.

In case this function returns warnings only, then the input package name is only valid for the previous npm naming rules.

func (Warning) String

func (w Warning) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL