UNPKG

@nuintun/qrcode

Version:

A pure JavaScript QRCode encode and decode library.

62 lines (57 loc) 1.54 kB
/** * @module QRCode * @package @nuintun/qrcode * @license MIT * @version 5.0.2 * @author nuintun <nuintun@qq.com> * @description A pure JavaScript QRCode encode and decode library. * @see https://github.com/nuintun/qrcode#readme */ 'use strict'; const Charset = require('../../common/Charset.cjs'); /** * @module asserts */ function assertContent(content) { if (content === '') { throw new Error('segment content should be at least 1 character'); } } function assertCharset(charset) { if (!(charset instanceof Charset.Charset)) { throw new Error('illegal charset'); } } function assertHints(hints) { const { fnc1 } = hints; // FNC1. if (fnc1 != null) { const [mode] = fnc1; if (mode !== 'GS1' && mode !== 'AIM') { throw new Error('illegal fn1 hint'); } if (mode === 'AIM') { const [, indicator] = fnc1; if (indicator < 0 || indicator > 0xff || !Number.isInteger(indicator)) { throw new Error('illegal fn1 application indicator'); } } } } function assertLevel(level) { if (['L', 'M', 'Q', 'H'].indexOf(level) < 0) { throw new Error('illegal error correction level'); } } function assertVersion(version) { if (version !== 'Auto') { if (version < 1 || version > 40 || !Number.isInteger(version)) { throw new Error('illegal version'); } } } exports.assertCharset = assertCharset; exports.assertContent = assertContent; exports.assertHints = assertHints; exports.assertLevel = assertLevel; exports.assertVersion = assertVersion;