CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-verdaccio

A lightweight private npm proxy registry application with comprehensive package management, authentication, and web interface capabilities

Pending
Overview
Eval results
Files

utilities.mddocs/

Utility Functions

Core utility functions for package management, validation, data processing, and system operations.

Capabilities

Validation Utilities

Object and data validation functions for type checking and data integrity.

/**
 * Check whether an element is an Object
 * @param obj - The element to check
 * @returns Boolean indicating if element is an object
 */
function isObject(obj: any): boolean;

/**
 * Check whether an element is an Object or Array (deprecated)
 * @param obj - The element to check
 * @returns Boolean indicating if element is object or array
 */
function isObjectOrArray(obj: any): boolean;

/**
 * Check whether the path already exists as a directory
 * @param path - Directory path to check
 * @returns Boolean indicating if directory exists
 */
function folderExists(path: string): boolean;

/**
 * Check whether the path already exists as a file
 * @param path - File path to check
 * @returns Boolean indicating if file exists
 */
function fileExists(path: string): boolean;

Package Version Management

Utilities for handling semantic versioning and package metadata.

/**
 * Tag a package version with a distribution tag
 * @param data - Package manifest data
 * @param version - Version string to tag
 * @param tag - Distribution tag name (e.g., 'latest', 'beta')
 * @returns Boolean indicating if tagging was successful
 */
function tagVersion(data: Manifest, version: string, tag: string): boolean;

/**
 * Get version object from package metadata with semver handling
 * @param pkg - Package manifest
 * @param version - Version string or semver range
 * @returns Version object or undefined if not found
 */
function getVersion(pkg: Manifest, version: any): Version | void;

/**
 * Sort version strings using semantic versioning rules
 * @param listVersions - Array of version strings
 * @returns Sorted array of valid version strings
 */
function semverSort(listVersions: string[]): string[];

/**
 * Normalize distribution tags in package manifest
 * @param pkg - Package manifest to normalize
 */
function normalizeDistTags(pkg: Manifest): void;

/**
 * Check if package version is valid and exists in metadata
 * @param packageMeta - Package metadata object
 * @param packageVersion - Version string to validate
 * @returns Boolean indicating if version is valid and exists
 */
function isVersionValid(packageMeta: any, packageVersion: any): boolean;

/**
 * Check if package has any deprecated versions
 * @param pkgInfo - Package manifest
 * @returns Boolean indicating if any version is deprecated
 */
function isRelatedToDeprecation(pkgInfo: Manifest): boolean;

Network and Address Parsing

URL and network address parsing utilities with support for various protocols.

/**
 * Parse internet address with protocol, host, and port detection
 * Supports: https:localhost:1234, localhost:1234, 1234, http::1234,
 * https://localhost:443/, http://[::1]:443/, unix:/tmp/http.sock
 * @param urlAddress - Address string to parse
 * @returns Parsed address object or null if invalid
 */
function parseAddress(urlAddress: any): {
  proto: string;
  host?: string;
  port?: number;
  path?: string;
} | null;

Usage Examples:

// Parse various address formats
parseAddress("https://localhost:4873");
// { proto: "https", host: "localhost", port: 4873 }

parseAddress("localhost:4873");
// { proto: "http", host: "localhost", port: 4873 }

parseAddress("4873");
// { proto: "http", host: "localhost", port: 4873 }

parseAddress("unix:/tmp/verdaccio.sock");
// { proto: "http", path: "/tmp/verdaccio.sock" }

Time and Interval Parsing

Parse time interval strings with unit support.

/**
 * Parse time interval string to milliseconds
 * Supports units: ms, s, m, h, d, w, M, y
 * @param interval - Interval string (e.g., "5m", "2h 30m", "1d")
 * @returns Interval in milliseconds
 * @throws Error for invalid interval format
 */
function parseInterval(interval: any): number;

Usage Examples:

parseInterval("5m");        // 300000 (5 minutes)
parseInterval("2h 30m");    // 9000000 (2.5 hours)
parseInterval("1d");        // 86400000 (1 day)
parseInterval(3600);        // 3600000 (1 hour from number)

Data Processing Utilities

General data manipulation and formatting utilities.

/**
 * Sort packages by name with optional direction
 * @param packages - Array of package objects with name property
 * @param orderAscending - Sort direction (true for ascending)
 * @returns Sorted array of packages
 */
function sortByName(packages: any[], orderAscending?: boolean): string[];

/**
 * Add npm scope prefix to package name
 * @param scope - Scope name (without @)
 * @param packageName - Package name
 * @returns Scoped package name (@scope/packageName)
 */
function addScope(scope: string, packageName: string): string;

/**
 * Remove specified properties from object
 * @param propertiesToDelete - Array of property names to remove
 * @param objectItem - Object to modify
 * @returns Modified object with properties removed
 */
function deleteProperties(propertiesToDelete: string[], objectItem: any): any;

/**
 * Create masked string for sensitive data display
 * @param str - String to mask
 * @param charNum - Number of characters to show at start/end
 * @returns Masked string (e.g., "abc...xyz")
 */
function mask(str: string, charNum?: number): string;

/**
 * URL-encode scoped package names for URI usage
 * @param packageName - Package name (may include scope)
 * @returns URL-encoded package name
 */
function encodeScopedUri(packageName: string): string;

/**
 * Check if versions object has more than one key
 * @param versions - Versions object to check
 * @returns Boolean indicating if multiple versions exist
 */
function hasDiffOneKey(versions: any): boolean;

README Processing

Package README file processing and validation utilities.

/**
 * Process package README content with fallback handling
 * @param packageName - Package name for logging
 * @param readme - README content string
 * @returns Processed README content or error message
 */
function parseReadme(packageName: string, readme: string): string | void;

Error Handling Utilities

Standardized error creation and handling functions.

/**
 * Collection of error factory functions for HTTP responses
 */
const ErrorCode: {
  getConflict(message?: string): Error;
  getBadData(message?: string): Error;
  getBadRequest(message?: string): Error;
  getInternalError(message?: string): Error;
  getUnauthorized(message?: string): Error;
  getForbidden(message?: string): Error;
  getServiceUnavailable(message?: string): Error;
  getNotFound(message?: string): Error;
  getCode(code: number, message?: string): Error;
};

Usage Examples:

// Create standardized errors
throw ErrorCode.getNotFound("Package not found");
throw ErrorCode.getUnauthorized("Authentication required");
throw ErrorCode.getBadRequest("Invalid package data");

Additional Utility Functions

Additional helper functions for package validation and data processing.

/**
 * Check if package version is valid and exists in metadata
 * @param packageMeta - Package metadata object
 * @param packageVersion - Version string to validate
 * @returns Boolean indicating if version is valid and exists
 */
function isVersionValid(packageMeta: any, packageVersion: any): boolean;

/**
 * Check if package has any deprecated versions
 * @param pkgInfo - Package manifest
 * @returns Boolean indicating if any version is deprecated
 */
function isRelatedToDeprecation(pkgInfo: Manifest): boolean;

/**
 * Check if login functionality is enabled in configuration
 * @param config - Verdaccio configuration object
 * @returns Boolean indicating if login is enabled
 */
function hasLogin(config: Config): boolean;

/**
 * Build authentication token utility (re-exported from @verdaccio/utils)
 * @param token - Token data
 * @returns Built token string
 */
function buildToken(token: any): string;

Type Definitions

interface Manifest {
  name: string;
  versions: { [version: string]: Version };
  "dist-tags": { [tag: string]: string };
  [key: string]: any;
}

interface Version {
  name: string;
  version: string;
  description?: string;
  main?: string;
  dependencies?: { [name: string]: string };
  devDependencies?: { [name: string]: string };
  [key: string]: any;
}

interface Config {
  storage: string;
  auth?: any;
  uplinks?: { [name: string]: any };
  packages?: { [pattern: string]: any };
  web?: {
    login?: boolean;
    [key: string]: any;
  };
  [key: string]: any;
}

Constants

Key constants used throughout the utility functions:

  • DEFAULT_DOMAIN: "localhost"
  • DEFAULT_PORT: 4873
  • DEFAULT_PROTOCOL: "http"
  • DIST_TAGS: "dist-tags"

These utilities form the foundation for Verdaccio's package management, configuration handling, and data processing capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-verdaccio

docs

cli.md

configuration.md

http-api.md

index.md

server-management.md

utilities.md

tile.json