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.
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:
- How many units to inspect from a lot (sample size)
- How many defective units make the lot acceptable (accept number)
- How many defective units make the lot fail (reject number)
A common garment-industry combination is AQL 2.5 at General Inspection Level II.
npm install aql-sample-sizeOr 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');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'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 }
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)How many units to inspect for a given code letter.
aql.getSampleSize('J'); // → 80
aql.getSampleSize('L'); // → 200All 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 }
// }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'| 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 | 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 |
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.
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.
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.
- Interactive lookup tables — scanerp.pro/aql — browser tool for the same 135 combinations
- Practical guide for garment factories — scanerp.pro/blog/fabric-inspection-4-point-system-guide.html
- Garment factory ERP with AQL integration — scanerp.pro
MIT © 2026 Santosh Rijal. Use it freely, including commercially.
Part of the Scan ERP open-source garment toolkit — production-tested utilities for CMT factory operations, all MIT licensed:
- aql-sample-size — ISO 2859-1 sample-size lookup (zero-dependency data library)
- garment-aql-calculator — Full AQL inspection decision engine with pass/fail logic
- garment-bundle-id — Bundle QR code generator + parser (STYLE-LOT-COLOR-SIZE-BUNDLE# format)
- garment-cmt-cost — CMT cost calculator with 13-country CPM comparison
- garment-dhu-calculator — Defects Per Hundred Units with defect-type breakdown + multi-checker aggregation
- garment-fabric-consumption — Fabric consumption (knit GSM × area, woven marker length)
- garment-line-efficiency — Line efficiency, target output, line balance / bottleneck detection
- garment-piece-rate — Piece-rate earnings calculator with bonuses and overtime
- garment-smv-calculator — Stopwatch SMV/SAM with Westinghouse performance rating
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.