public export interface IParsedPackageName { remarks scope : string ; remarks unscopedName : string ; } /**
 * Result object returned by  PackageName . tryParse public export interface IParsedPackageNameOrError extends IParsedPackageName { /**
     * If the input string could not be parsed, then this string will contain a nonempty
     * error message.  Otherwise it will be an empty string.
     */ error : string ; } /**
 * Options that configure the validation rules used by a  PackageNameParser instance.
 *
 *  remarks public export interface IPackageNameParserOptions { /**
     * If true, allows upper-case letters in package names.
     * This improves compatibility with some legacy private registries that still allow that.
     */ allowUpperCase ? : boolean ; } remarks If you do not need to customize the parser configuration, it is recommended to use  PackageName * which exposes these operations as a simple static class.
 *
 *  public export class PackageNameParser { private static readonly _invalidNameCharactersRegExp : RegExp = /[^A-Za-z0-9\-_\.]/ ; private readonly _options : IPackageNameParserOptions ; public constructor ( options = { } ) { this . _options = { ... options } ; } remarks returns an  IParsedPackageNameOrError structure whose `error` property will be
     * nonempty if the string could not be parsed.
      public tryParse ( packageName ) { const result = { scope : '' , unscopedName : '' , error : '' } ; let input = packageName ; if ( input === null || input === undefined ) { result . error = 'The package name must not be null or undefined' ; return result ; } if ( packageName . length > 214 ) { result . error = 'The package name cannot be longer than 214 characters' ; return result ; } if ( input [ 0 ] === '@' ) { const indexOfScopeSlash = input . indexOf ( '/' ) ; if ( indexOfScopeSlash <= 0 ) { result . scope = input ; result . error = `Error parsing "${ packageName }": The scope must be followed by a slash` ; return result ; } result . scope = input . substr ( 0 , indexOfScopeSlash ) ; input = input . substr ( indexOfScopeSlash + 1 ) ; } result . unscopedName = input ; if ( result . scope === '@' ) { result . error = `Error parsing "${ packageName }": The scope name cannot be empty` ; return result ; } if ( result . unscopedName === '' ) { result . error = 'The package name must not be empty' ; return result ; } if ( result . unscopedName [ 0 ] === '.' || result . unscopedName [ 0 ] === '_' ) { result . error = `The package name "${ packageName }" starts with an invalid character` ; return result ; } const nameWithoutScopeSymbols = ( result . scope ? result . scope . slice ( 1 , - 1 ) : '' ) + result . unscopedName ; if ( ! this . _options . allowUpperCase ) { if ( result . scope !== result . scope . toLowerCase ( ) ) { result . error = `The package scope "${ result . scope }" must not contain upper case characters` ; return result ; } } const match = nameWithoutScopeSymbols . match ( PackageNameParser . _invalidNameCharactersRegExp ) ; if ( match ) { result . error = `The package name "${ packageName }" contains an invalid character: "${ match [ 0 ] }"` ; return result ; } return result ; } /**
     * Same as  PackageName . tryParse , except this throws an exception if the input
     * cannot be parsed.
     *  remarks public parse ( packageName ) { const result = this . tryParse ( packageName ) ; if ( result . error ) { throw new Error ( result . error ) ; } return result ; } /**
     * {@inheritDoc IParsedPackageName.scope}
     */ public getScope ( packageName ) { return this . parse ( packageName ) . scope ; } /**
     * {@inheritDoc IParsedPackageName.unscopedName}
     */ public getUnscopedName ( packageName ) { return this . parse ( packageName ) . unscopedName ; } remarks public isValidName ( packageName ) { const result = this . tryParse ( packageName ) ; return ! result . error ; } /**
     * Throws an exception if the specified name is not a valid package name.
     * The packageName must not be an empty string.
     */ public validate ( packageName ) { this . parse ( packageName ) ; } param scope param unscopedName returns public combineParts ( scope , unscopedName ) { if ( scope !== '' ) { if ( scope [ 0 ] !== '@' ) { throw new Error ( 'The scope must start with an "@" character' ) ; } } if ( scope . indexOf ( '/' ) >= 0 ) { throw new Error ( 'The scope must not contain a "/" character' ) ; } if ( unscopedName [ 0 ] === '@' ) { throw new Error ( 'The unscopedName cannot start with an "@" character' ) ; } if ( unscopedName . indexOf ( '/' ) >= 0 ) { throw new Error ( 'The unscopedName must not contain a "/" character' ) ; } let result ; if ( scope === '' ) { result = unscopedName ; } else { result = scope + '/' + unscopedName ; } this . validate ( result ) ; return result ; } } remarks This is the default implementation of  PackageNameParser , exposed as a convenient static class.
 * If you need to configure the parsing rules, use `PackageNameParser` instead.
 *
 *  public export class PackageName { private static readonly _parser : PackageNameParser = new PackageNameParser ( ) ; /** {@inheritDoc PackageNameParser.tryParse} */ public static tryParse ( packageName ) { return PackageName . _parser . tryParse ( packageName ) ; } /** {@inheritDoc PackageNameParser.parse} */ public static parse ( packageName ) { return this . _parser . parse ( packageName ) ; } /** {@inheritDoc PackageNameParser.getScope} */ public static getScope ( packageName ) { return this . _parser . getScope ( packageName ) ; } /** {@inheritDoc PackageNameParser.getUnscopedName} */ public static getUnscopedName ( packageName ) { return this . _parser . getUnscopedName ( packageName ) ; } /** {@inheritDoc PackageNameParser.isValidName} */ public static isValidName ( packageName ) { return this . _parser . isValidName ( packageName ) ; } /** {@inheritDoc PackageNameParser.validate} */ public static validate ( packageName ) { return this . _parser . validate ( packageName ) ; } /** {@inheritDoc PackageNameParser.combineParts} */ public static combineParts ( scope , unscopedName ) { return this . _parser . combineParts ( scope , unscopedName ) ; } }