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 🙏

© 2026 – Pkg Stats / Ryan Hefner

eye-test-utils

v1.0.5

Published

Validation & calculation utilities for optical prescriptions (glasses & lenses).

Readme

👓 Optical Validators Package

A robust TypeScript/JavaScript package for validating, formatting, and converting optical prescriptions (Eyeglasses and Contact Lenses).

🚀 Installation

npm install eye-test-utils
# or
yarn add eye-test-utils

📝 TypeScript Support

This package is written in TypeScript and includes type definitions out-of-the-box, offering full type safety for inputs and outputs.

🔬 EyeTestValidator

This class handles the validation and formatting of standard eyeglass prescription parameters (SPH, CYL, AXIS, ADD, PD, etc.). It ensures all values conform to required optical standards (e.g., multiples of 0.25, specific ranges, and consistent sign notation).

Key Features

  • Validation: Checks ranges and $0.25$ multiples.
  • Formatting: Ensures standard optical notation (e.g., +05.50, -01.25).
  • Transposition: Converts SPH/CYL/AXIS to the negative cylinder format.

Usage Example

  • Usage Example: Validation and Formatting SPH/CYL/AXIS
        import { EyeTestValidator } from 'eye-test-utils'; // (assuming this is the correct path)

        const validator = new EyeTestValidator();
        const sphere = -1.50;
        const cyl = -0.75;
        const axis = 180;

        const vs = validator.validateSPH(sphere);
        const vc = validator.validateCYL(cyl);
        const va = validator.validateAxis(axis);

        if (vs === null || vc === null || va === null) {
        console.error("Invalid prescription value!");
        } else {
        console.log(
            `${vs} ${vc} × ${va}`
        );
        // Output → "-01.50 -00.75 × 180" 
        }
  • Usage Example: Validation and Formatting
import { EyeTestValidator } from 'eye-test-utils';

const validator = new EyeTestValidator();

const prescriptionData = {
  sphere: "-4.50",
  cylinder: "+1.25",
  axis: "90",
  add: "2.50",
  pd: 65,
  vertexDistance: 12.5
};

const result = validator.validatePrescription(prescriptionData);

if (result.valid) {
  console.log("Prescription is valid and formatted:", result.formatted);
  /* Output:
  {
    sphere: '-04.50',
    cylinder: '+01.25',
    axis: 90,
    add: '+02.50',
    pd: 65,
    vertexDistance: 12.5
  }
  */
} else {
  console.error("Validation Errors:", result.errors);
}
  • Usage Example: Transposition (Conversion) Converts a positive cylinder prescription to the standard negative cylinder format.
const originalSPH = -2.00;
const originalCYL = +1.00;
const originalAXIS = 90;

const transposed = validator.transformSphCylAxis(
  originalSPH, 
  originalCYL, 
  originalAXIS
);

console.log("Transposed Prescription:", transposed);
/* Output (equivalent to -1.00 -1.00 x 180):
{ 
  sph: '-01.00', 
  cyl: '-01.00', // CYL is always negative
  axis: 180       // AXIS is adjusted by 90 degrees
}
*/

ContactLensValidator

This class handles the conversion of an eyeglass prescription into a Contact Lens prescription, accounting for the Vertex Distance (BV) effect.

Key Conversion Logic

  • Vertex Distance Compensation: Applies the formula $D_c = D_g / (1 - d \cdot D_g)$ where $D_c$ is contact lens power, $D_g$ is glasses power, and $d$ is vertex distance in meters. This compensation is applied if the SPH power exceeds $4$ Diopters.
  • Rounding: All final values are rounded to the nearest $0.25$ (quarter Diopter) suitable for contact lens availability.
  • Toric Calculation: Toric conversion calculates the new cylinder power after vertex compensation on the principal meridians

Usage Example: Spherical Conversion

Converts an eyeglass prescription to a spherical contact lens prescription (using the Spherical Equivalent if CYL is present).

import { ContactLensValidator } from 'eye-test-utils';

const clValidator = new ContactLensValidator();

const glassesData = { 
  SPH: -5.25, 
  CY: -1.00, 
  AX: 90, 
  BV: 12, // Vertex Distance in mm
  ADD: 2.00 
};

const sphericalResult = clValidator.convertToSpheric(glassesData);

console.log("Spherical Contact Lens Result:", sphericalResult);
/* Output (Example):
{
  SPH: '-06.00', // SPH adjusted for BV and rounded
  ADD: '+02.00', 
  'Exact SPH': '-05.87',
  AX: '',
  BV: 12
}
*/

Usage Example: Toric Conversion

Converts an eyeglass prescription to a toric contact lens prescription (maintaining cylinder), with both SPH and CYL vertex-compensated.

const toricResult = clValidator.convertToToric(glassesData);

console.log("Toric Contact Lens Result:", toricResult);
/* Output (Example):
{
  SPH: '-05.25', // SPH adjusted for BV and rounded
  CY: '-01.00', // CYL adjusted for BV and rounded
  ADD: '+02.00',
  AX: '90',
  'Exact SPH': '-05.15', 
  'Exact CY': '-01.03',
  BV: 12
}
*/

CI/CD

CI

💡 Contributing

We welcome contributions! If you have suggestions for improving validation rules, finding bugs, or adding new features, please open an issue or submit a Pull Request.

GitHub Repository: https://github.com/Elhussin/eye-test-utils.git

💬 Support & Contact

If you have any questions, need technical support, or want to discuss features, feel free to reach out:

📜 License

This project is licensed under the MIT License.