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

aql-sample-size

v1.0.0

Published

Zero-dependency ISO 2859-1 AQL sample-size lookup. Garment, electronics, medical-device buyer-audit quality inspection. Tables verified against QIMA reference.

Readme

aql-sample-size

npm version License: MIT Node

Zero-dependency ISO 2859-1 AQL sample-size lookup library. Returns the exact sample size, accept number, and reject number for any lot size, inspection level, and AQL — the same way Walmart, H&M, Target, and other major buyers calculate it for garment, electronics, and medical-device quality audits.

Tables verified against QIMA reference and ISO 2859-1:1999 standard.

What is AQL?

AQL (Acceptance Quality Limit) is the highest defect rate a buyer will accept as "good" during random sampling inspection. The ISO 2859-1 standard tells you:

  1. How many units to inspect from a lot (sample size)
  2. How many defective units make the lot acceptable (accept number)
  3. How many defective units make the lot fail (reject number)

A common garment-industry combination is AQL 2.5 at General Inspection Level II.

Install

npm install aql-sample-size

Or use directly from the JSON data files (no runtime needed):

const codeLetters = require('aql-sample-size/data/code-letters.json');
const plans = require('aql-sample-size/data/plans.json');

Quick start

const aql = require('aql-sample-size');

// Most common use: get a full sampling plan
const plan = aql.getPlan(800, 'GII', 2.5);
console.log(plan);
// → {
//     codeLetter: 'J',
//     sampleSize: 80,
//     accept: 5,
//     reject: 6,
//     lotSize: 800,
//     level: 'GII',
//     aql: 2.5
//   }

// You inspect 80 random units. Found 4 defects → accept (4 ≤ 5).
//                                Found 6 defects → reject (6 ≥ 6).
console.log(aql.decide(4, plan));  // → 'ACCEPT'
console.log(aql.decide(6, plan));  // → 'REJECT'

API

getPlan(lotSize, level, aql) → plan

The most useful function. Returns sample size + accept + reject for an entire inspection plan.

| Param | Type | Default | Description | |---|---|---|---| | lotSize | number | required | Number of units in the lot (≥ 2) | | level | string | 'GII' | 'GI', 'GII', or 'GIII' | | aql | number | 2.5 | 0.65, 1.0, 1.5, 2.5, 4.0, or 6.5 |

Returns: { codeLetter, sampleSize, accept, reject, lotSize, level, aql }

getCodeLetter(lotSize, level) → 'A'..'R'

Just the ISO 2859-1 Table A code letter. Useful if you only need the sample size class without a specific AQL.

aql.getCodeLetter(800, 'GII');   // → 'J'
aql.getCodeLetter(800, 'GIII');  // → 'K' (tightened)
aql.getCodeLetter(800, 'GI');    // → 'F' (reduced)

getSampleSize(codeLetter) → number

How many units to inspect for a given code letter.

aql.getSampleSize('J');  // → 80
aql.getSampleSize('L');  // → 200

getAllPlans(lotSize, level) → { aql: plan }

All six AQL plans for one lot size + level — useful for buyer-audit decision trees.

aql.getAllPlans(800, 'GII');
// → {
//     '0.65': { sampleSize: 80, accept: 1, reject: 2 },
//     '1':    { sampleSize: 80, accept: 2, reject: 3 },
//     '1.5':  { sampleSize: 80, accept: 3, reject: 4 },
//     '2.5':  { sampleSize: 80, accept: 5, reject: 6 },
//     '4':    { sampleSize: 80, accept: 7, reject: 8 },
//     '6.5':  { sampleSize: 80, accept: 10, reject: 11 }
//   }

decide(defects, plan) → 'ACCEPT' | 'REJECT'

Pass/fail decision for an inspection result.

const plan = aql.getPlan(2000, 'GII', 2.5);  // sample 125, accept 7, reject 8
aql.decide(3, plan);  // → 'ACCEPT'
aql.decide(8, plan);  // → 'REJECT'

Inspection levels

| Level | When to use | |---|---| | GI | Reduced inspection — low-risk products, trusted suppliers, repeat orders with clean history | | GII | Normal inspection — default for garment buyer QC (Walmart, H&M, Target, Zara, etc.) | | GIII | Tightened inspection — used after a failed inspection or for premium brands |

AQL values

| AQL | Strictness | Typical use | |---|---|---| | 0.65 | Very strict | Critical defects (medical, safety, branding) | | 1.0 | Strict | Major defects on premium brands | | 1.5 | Strict-ish | Major defects on mid-tier brands | | 2.5 | Most common | Major defects, mass-market garments | | 4.0 | Loose | Minor defects | | 6.5 | Very loose | Minor defects on low-cost goods |

Worked example — a 5,000-unit shirt order

Your factory shipped 5,000 shirts to Walmart. They inspect at AQL 2.5 / GII (standard).

const plan = aql.getPlan(5000, 'GII', 2.5);
// → { codeLetter: 'L', sampleSize: 200, accept: 10, reject: 11, ... }
  • The buyer randomly picks 200 shirts from the 5,000.
  • If ≤ 10 shirts have major defects → shipment accepted.
  • If ≥ 11 shirts have major defects → shipment rejected.

That's it. The library encodes the entire ISO 2859-1 Table II-A so you don't have to read PDFs.

Why this library exists

Most existing AQL lookups are:

  • PDF tables you have to scan visually
  • Paid commercial QC software
  • Web tools that don't expose programmable APIs

This is a tiny, zero-dependency, MIT-licensed lookup that any developer can drop into a quality-management script.

Verification

The data tables are cross-verified against:

  • ISO 2859-1:1999 official standard
  • QIMA reference tables
  • AsiaInspection / SGS / Bureau Veritas published reference cards

If you find a discrepancy, please open an issue.

Related resources

License

MIT © 2026 Santosh Rijal. Use it freely, including commercially.