Skip to content

drmcoder/aql-sample-size

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Related Packages — Scan ERP Garment Toolkit

Part of the Scan ERP open-source garment toolkit — production-tested utilities for CMT factory operations, all MIT licensed:

See the curated awesome-garment-erp list for the full Scan ERP ecosystem, or visit scanerp.pro for the production garment manufacturing ERP this toolkit powers.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors