npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

massbank

v0.1.0

Published

Utilities to submit massbank data

Readme

massbank

NPM version npm download test coverage license

A TypeScript/JavaScript library for validating MassBank record files. This library provides validation for MassBank format 2.6.0, ensuring compliance with MassBank standards for automated submission to the MassBank-data repository.

Installation

npm install massbank

Usage

Basic File Validation

import { validate } from 'massbank';

// Validate a single file
const result = await validate('path/to/MSBNK-test-TST00001.txt');

if (result.success) {
  console.log('Validation passed!');
  console.log('Accession:', result.accessions[0]);
} else {
  console.error('❌ Validation failed:');
  result.errors.forEach((error) => {
    console.error(`  Line ${error.line}: ${error.message}`);
  });
}

In-Memory Validation

import { validateContent } from 'massbank';

// Validate record text without file I/O
const recordText = `ACCESSION: MSBNK-test-TST00001
RECORD_TITLE: Test Record
//`;

const result = await validateContent(recordText, 'MSBNK-test-TST00001.txt');

With Options

import { validate } from 'massbank';
import { FifoLogger } from 'fifo-logger';

const logger = new FifoLogger({ level: 'info' });

const result = await validate('record.txt', {
  legacy: true, // Enable legacy mode for less strict validation
  logger: logger, // Optional logger for validation messages
});

Validation Rules

The validator performs the following checks:

  1. Parse Validation - Ensures the record can be parsed correctly according to MassBank format 2.6.0
  2. ACCESSION Matching - Validates that ACCESSION field matches the filename (CRITICAL for MassBank-data repository)
    • Example: File MSBNK-test-TST00001.txt must contain ACCESSION: MSBNK-test-TST00001
  3. Unrecognized Fields - Warns about unrecognized field names (helps catch typos like RECRD_TITLE instead of RECORD_TITLE)
  4. Non-Standard Characters - Warns about non-standard ASCII characters (non-blocking)
  5. Serialization Round-Trip - Ensures parse → serialize → compare matches exactly (guarantees no data loss)

API Reference

validate(filePath, options?)

Validate a single MassBank record file.

Parameters:

  • filePath: string - Path to the .txt file to validate
  • options?: ValidationOptions - Optional validation options

Returns: Promise<ValidationResult>

ValidationResult:

interface ValidationResult {
  success: boolean; // true if no errors
  errors: ValidationError[]; // Array of validation errors
  warnings: ValidationWarning[]; // Array of warnings (non-blocking)
  accessions: string[]; // Extracted ACCESSION values
  filesProcessed: number; // Number of files processed (always 1)
}

validateContent(text, filename, options?)

Validate in-memory MassBank record content (no file I/O).

Parameters:

  • text: string - The MassBank record text
  • filename: string - Logical filename for error reporting (e.g., 'user-upload.txt')
  • options?: ValidationOptions - Optional validation options

Returns: Promise<ValidationResult>

MassBank Format 2.6.0 Compliance

This library enforces MassBank format 2.6.0 standards, including:

  • ACCESSION format: MSBNK-[ContributorID]-[RecordID]
    • Contributor ID: up to 32 characters (letters, digits, underscore)
    • Record ID: up to 64 characters (capital letters, digits, underscore)
  • Filename matching: File must be named {ACCESSION}.txt
  • Required fields: ACCESSION, RECORD_TITLE, DATE, AUTHORS, LICENSE, and more
  • SPLASH validation: Optional spectral hash validation via API

Requirements

  • Node.js 18+ (for native fetch support in SPLASH validation)
  • No external runtime dependencies (only optional fifo-logger)

License

MIT