First commit
This commit is contained in:
36
node_modules/swissqrbill/lib/cjs/shared/cleaner.cjs
generated
vendored
Normal file
36
node_modules/swissqrbill/lib/cjs/shared/cleaner.cjs
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
function cleanData(data) {
|
||||
const _cleanObject = (object) => {
|
||||
return Object.fromEntries(
|
||||
Object.entries(object).map(([key, value]) => {
|
||||
if (typeof value === "object") {
|
||||
return [key, _cleanObject(value)];
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
if (key === "account") {
|
||||
return [key, removeLineBreaks(removeSpaces(value))];
|
||||
}
|
||||
if (key === "reference") {
|
||||
return [key, removeLineBreaks(removeSpaces(value))];
|
||||
}
|
||||
if (key === "country") {
|
||||
return [key, removeLineBreaks(removeSpaces(value).toUpperCase())];
|
||||
}
|
||||
return [key, removeLineBreaks(value)];
|
||||
}
|
||||
return [key, value];
|
||||
})
|
||||
);
|
||||
};
|
||||
return _cleanObject(data);
|
||||
}
|
||||
function removeSpaces(text) {
|
||||
return text.replace(/ /g, "");
|
||||
}
|
||||
function removeLineBreaks(text) {
|
||||
return text.replace(/\n/g, "").replace(/\r/g, "");
|
||||
}
|
||||
exports.cleanData = cleanData;
|
||||
exports.removeLineBreaks = removeLineBreaks;
|
||||
exports.removeSpaces = removeSpaces;
|
||||
4
node_modules/swissqrbill/lib/cjs/shared/cleaner.d.ts
generated
vendored
Normal file
4
node_modules/swissqrbill/lib/cjs/shared/cleaner.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Data } from './types.js';
|
||||
export declare function cleanData(data: Data): Data;
|
||||
export declare function removeSpaces(text: string): string;
|
||||
export declare function removeLineBreaks(text: string): string;
|
||||
88
node_modules/swissqrbill/lib/cjs/shared/errors.cjs
generated
vendored
Normal file
88
node_modules/swissqrbill/lib/cjs/shared/errors.cjs
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
class ValidationError extends Error {
|
||||
/** @internal */
|
||||
constructor(message, params) {
|
||||
const messageWithParams = params ? resolveMessageParams(message, params) : message;
|
||||
super(messageWithParams);
|
||||
this.name = "ValidationError";
|
||||
this.code = getErrorCodeByMessage(message);
|
||||
}
|
||||
}
|
||||
function getErrorCodeByMessage(message) {
|
||||
const errorCodes = Object.keys(ValidationErrors);
|
||||
const errorCode = errorCodes.find((key) => ValidationErrors[key] === message);
|
||||
return errorCode;
|
||||
}
|
||||
function resolveMessageParams(message, params) {
|
||||
return Object.entries(params).reduce((message2, [key, value]) => {
|
||||
return message2.replace(`{${key}}`, value);
|
||||
}, message);
|
||||
}
|
||||
var ValidationErrors = /* @__PURE__ */ ((ValidationErrors2) => {
|
||||
ValidationErrors2["ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_MISSING"] = "If there is no reference, a conventional IBAN must be used.";
|
||||
ValidationErrors2["ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_REGULAR"] = "QR-IBAN requires the use of a QR-Reference.";
|
||||
ValidationErrors2["ACCOUNT_IS_REGULAR_IBAN_BUT_REFERENCE_IS_QR"] = "QR-Reference requires the use of a QR-IBAN.";
|
||||
ValidationErrors2["ACCOUNT_LENGTH_IS_INVALID"] = "The provided IBAN number '{iban}' is either too long or too short.";
|
||||
ValidationErrors2["ADDITIONAL_INFORMATION_LENGTH_IS_INVALID"] = "Additional information must be a maximum of 140 characters.";
|
||||
ValidationErrors2["ADDITIONAL_INFORMATION_TYPE_IS_INVALID"] = "Additional information must be a string.";
|
||||
ValidationErrors2["ALTERNATIVE_SCHEME_LENGTH_IS_INVALID"] = "{scheme} must be a maximum of 100 characters.";
|
||||
ValidationErrors2["ALTERNATIVE_SCHEME_TYPE_IS_INVALID"] = "{scheme} must be a string.";
|
||||
ValidationErrors2["AMOUNT_LENGTH_IS_INVALID"] = "Amount must be a maximum of 12 digits.";
|
||||
ValidationErrors2["AMOUNT_TYPE_IS_INVALID"] = "Amount must be a number.";
|
||||
ValidationErrors2["CREDITOR_ACCOUNT_COUNTRY_IS_INVALID"] = "Only CH and LI IBAN numbers are allowed.";
|
||||
ValidationErrors2["CREDITOR_ACCOUNT_IS_INVALID"] = "The provided IBAN number '{iban}' is not valid.";
|
||||
ValidationErrors2["CREDITOR_ACCOUNT_IS_UNDEFINED"] = "Creditor account cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_ADDRESS_IS_UNDEFINED"] = "Creditor address cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_ADDRESS_LENGTH_IS_INVALID"] = "Creditor address must be a maximum of 70 characters.";
|
||||
ValidationErrors2["CREDITOR_ADDRESS_TYPE_IS_INVALID"] = "Creditor address TYPE must be a string.";
|
||||
ValidationErrors2["CREDITOR_BUILDING_NUMBER_LENGTH_IS_INVALID"] = "Creditor buildingNumber must be a maximum of 16 characters.";
|
||||
ValidationErrors2["CREDITOR_BUILDING_NUMBER_TYPE_IS_INVALID"] = "Creditor buildingNumber must be either a string or a number.";
|
||||
ValidationErrors2["CREDITOR_CITY_IS_UNDEFINED"] = "Creditor city cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_CITY_LENGTH_IS_INVALID"] = "Creditor city must be a maximum of 35 characters.";
|
||||
ValidationErrors2["CREDITOR_CITY_TYPE_IS_INVALID"] = "Creditor city must be a string.";
|
||||
ValidationErrors2["CREDITOR_COUNTRY_IS_UNDEFINED"] = "Creditor country cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_COUNTRY_LENGTH_IS_INVALID"] = "Creditor country must be 2 characters.";
|
||||
ValidationErrors2["CREDITOR_COUNTRY_TYPE_IS_INVALID"] = "Creditor country must be a string.";
|
||||
ValidationErrors2["CREDITOR_IS_UNDEFINED"] = "Creditor cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_NAME_IS_UNDEFINED"] = "Creditor name cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_NAME_LENGTH_IS_INVALID"] = "Creditor name must be a maximum of 70 characters.";
|
||||
ValidationErrors2["CREDITOR_NAME_TYPE_IS_INVALID"] = "Creditor name must be a string.";
|
||||
ValidationErrors2["CREDITOR_ZIP_IS_UNDEFINED"] = "Creditor zip cannot be undefined.";
|
||||
ValidationErrors2["CREDITOR_ZIP_LENGTH_IS_INVALID"] = "Creditor zip must be a maximum of 16 characters.";
|
||||
ValidationErrors2["CREDITOR_ZIP_TYPE_IS_INVALID"] = "Creditor zip must be either a string or a number.";
|
||||
ValidationErrors2["CURRENCY_IS_UNDEFINED"] = "Currency cannot be undefined.";
|
||||
ValidationErrors2["CURRENCY_LENGTH_IS_INVALID"] = "Currency must be a length of 3 characters.";
|
||||
ValidationErrors2["CURRENCY_STRING_IS_INVALID"] = "Currency must be either 'CHF' or 'EUR'";
|
||||
ValidationErrors2["CURRENCY_TYPE_IS_INVALID"] = "Currency must be a string.";
|
||||
ValidationErrors2["DEBTOR_ADDRESS_IS_UNDEFINED"] = "Debtor address cannot be undefined.";
|
||||
ValidationErrors2["DEBTOR_ADDRESS_LENGTH_IS_INVALID"] = "Debtor address must be a maximum of 70 characters.";
|
||||
ValidationErrors2["DEBTOR_ADDRESS_TYPE_IS_INVALID"] = "Debtor address TYPE must be a string.";
|
||||
ValidationErrors2["DEBTOR_BUILDING_NUMBER_LENGTH_IS_INVALID"] = "Debtor buildingNumber must be a maximum of 16 characters.";
|
||||
ValidationErrors2["DEBTOR_BUILDING_NUMBER_TYPE_IS_INVALID"] = "Debtor buildingNumber must be either a string or a number.";
|
||||
ValidationErrors2["DEBTOR_CITY_IS_UNDEFINED"] = "Debtor city cannot be undefined.";
|
||||
ValidationErrors2["DEBTOR_CITY_LENGTH_IS_INVALID"] = "Debtor city must be a maximum of 35 characters.";
|
||||
ValidationErrors2["DEBTOR_CITY_TYPE_IS_INVALID"] = "Debtor city must be a string.";
|
||||
ValidationErrors2["DEBTOR_COUNTRY_IS_UNDEFINED"] = "Debtor country cannot be undefined.";
|
||||
ValidationErrors2["DEBTOR_COUNTRY_LENGTH_IS_INVALID"] = "Debtor country must be 2 characters.";
|
||||
ValidationErrors2["DEBTOR_COUNTRY_TYPE_IS_INVALID"] = "Debtor country must be a string.";
|
||||
ValidationErrors2["DEBTOR_IS_UNDEFINED"] = "Debtor cannot be undefined.";
|
||||
ValidationErrors2["DEBTOR_NAME_IS_UNDEFINED"] = "Debtor name cannot be undefined.";
|
||||
ValidationErrors2["DEBTOR_NAME_LENGTH_IS_INVALID"] = "Debtor name must be a maximum of 70 characters.";
|
||||
ValidationErrors2["DEBTOR_NAME_TYPE_IS_INVALID"] = "Debtor name must be a string.";
|
||||
ValidationErrors2["DEBTOR_ZIP_IS_UNDEFINED"] = "Debtor zip cannot be undefined.";
|
||||
ValidationErrors2["DEBTOR_ZIP_LENGTH_IS_INVALID"] = "Debtor zip must be a maximum of 16 characters.";
|
||||
ValidationErrors2["DEBTOR_ZIP_TYPE_IS_INVALID"] = "Debtor zip must be either a string or a number.";
|
||||
ValidationErrors2["MESSAGE_AND_ADDITIONAL_INFORMATION_LENGTH_IS_INVALID"] = "Message and additionalInformation combined must be a maximum of 140 characters.";
|
||||
ValidationErrors2["MESSAGE_LENGTH_IS_INVALID"] = "Message must be a maximum of 140 characters.";
|
||||
ValidationErrors2["MESSAGE_TYPE_IS_INVALID"] = "Message must be a string.";
|
||||
ValidationErrors2["QR_REFERENCE_IS_INVALID"] = "The provided QR-Reference '{reference}' is not valid.";
|
||||
ValidationErrors2["QR_REFERENCE_LENGTH_IS_INVALID"] = "QR-Reference must be a must be exactly 27 characters.";
|
||||
ValidationErrors2["REFERENCE_TYPE_IS_INVALID"] = "Reference must be a string.";
|
||||
ValidationErrors2["REGULAR_REFERENCE_LENGTH_IS_INVALID"] = "Creditor reference must be a maximum of 25 characters.";
|
||||
return ValidationErrors2;
|
||||
})(ValidationErrors || {});
|
||||
exports.ValidationError = ValidationError;
|
||||
exports.ValidationErrors = ValidationErrors;
|
||||
exports.getErrorCodeByMessage = getErrorCodeByMessage;
|
||||
exports.resolveMessageParams = resolveMessageParams;
|
||||
67
node_modules/swissqrbill/lib/cjs/shared/errors.d.ts
generated
vendored
Normal file
67
node_modules/swissqrbill/lib/cjs/shared/errors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/** A {@link ValidationError} is thrown when the data provided to swissqrbill is invalid. */
|
||||
export declare class ValidationError extends Error {
|
||||
/** A stable error code that can be used to identify the error programmatically. */
|
||||
code: keyof typeof ValidationErrors;
|
||||
}
|
||||
export declare enum ValidationErrors {
|
||||
ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_MISSING = "If there is no reference, a conventional IBAN must be used.",
|
||||
ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_REGULAR = "QR-IBAN requires the use of a QR-Reference.",
|
||||
ACCOUNT_IS_REGULAR_IBAN_BUT_REFERENCE_IS_QR = "QR-Reference requires the use of a QR-IBAN.",
|
||||
ACCOUNT_LENGTH_IS_INVALID = "The provided IBAN number '{iban}' is either too long or too short.",
|
||||
ADDITIONAL_INFORMATION_LENGTH_IS_INVALID = "Additional information must be a maximum of 140 characters.",
|
||||
ADDITIONAL_INFORMATION_TYPE_IS_INVALID = "Additional information must be a string.",
|
||||
ALTERNATIVE_SCHEME_LENGTH_IS_INVALID = "{scheme} must be a maximum of 100 characters.",
|
||||
ALTERNATIVE_SCHEME_TYPE_IS_INVALID = "{scheme} must be a string.",
|
||||
AMOUNT_LENGTH_IS_INVALID = "Amount must be a maximum of 12 digits.",
|
||||
AMOUNT_TYPE_IS_INVALID = "Amount must be a number.",
|
||||
CREDITOR_ACCOUNT_COUNTRY_IS_INVALID = "Only CH and LI IBAN numbers are allowed.",
|
||||
CREDITOR_ACCOUNT_IS_INVALID = "The provided IBAN number '{iban}' is not valid.",
|
||||
CREDITOR_ACCOUNT_IS_UNDEFINED = "Creditor account cannot be undefined.",
|
||||
CREDITOR_ADDRESS_IS_UNDEFINED = "Creditor address cannot be undefined.",
|
||||
CREDITOR_ADDRESS_LENGTH_IS_INVALID = "Creditor address must be a maximum of 70 characters.",
|
||||
CREDITOR_ADDRESS_TYPE_IS_INVALID = "Creditor address TYPE must be a string.",
|
||||
CREDITOR_BUILDING_NUMBER_LENGTH_IS_INVALID = "Creditor buildingNumber must be a maximum of 16 characters.",
|
||||
CREDITOR_BUILDING_NUMBER_TYPE_IS_INVALID = "Creditor buildingNumber must be either a string or a number.",
|
||||
CREDITOR_CITY_IS_UNDEFINED = "Creditor city cannot be undefined.",
|
||||
CREDITOR_CITY_LENGTH_IS_INVALID = "Creditor city must be a maximum of 35 characters.",
|
||||
CREDITOR_CITY_TYPE_IS_INVALID = "Creditor city must be a string.",
|
||||
CREDITOR_COUNTRY_IS_UNDEFINED = "Creditor country cannot be undefined.",
|
||||
CREDITOR_COUNTRY_LENGTH_IS_INVALID = "Creditor country must be 2 characters.",
|
||||
CREDITOR_COUNTRY_TYPE_IS_INVALID = "Creditor country must be a string.",
|
||||
CREDITOR_IS_UNDEFINED = "Creditor cannot be undefined.",
|
||||
CREDITOR_NAME_IS_UNDEFINED = "Creditor name cannot be undefined.",
|
||||
CREDITOR_NAME_LENGTH_IS_INVALID = "Creditor name must be a maximum of 70 characters.",
|
||||
CREDITOR_NAME_TYPE_IS_INVALID = "Creditor name must be a string.",
|
||||
CREDITOR_ZIP_IS_UNDEFINED = "Creditor zip cannot be undefined.",
|
||||
CREDITOR_ZIP_LENGTH_IS_INVALID = "Creditor zip must be a maximum of 16 characters.",
|
||||
CREDITOR_ZIP_TYPE_IS_INVALID = "Creditor zip must be either a string or a number.",
|
||||
CURRENCY_IS_UNDEFINED = "Currency cannot be undefined.",
|
||||
CURRENCY_LENGTH_IS_INVALID = "Currency must be a length of 3 characters.",
|
||||
CURRENCY_STRING_IS_INVALID = "Currency must be either 'CHF' or 'EUR'",
|
||||
CURRENCY_TYPE_IS_INVALID = "Currency must be a string.",
|
||||
DEBTOR_ADDRESS_IS_UNDEFINED = "Debtor address cannot be undefined.",
|
||||
DEBTOR_ADDRESS_LENGTH_IS_INVALID = "Debtor address must be a maximum of 70 characters.",
|
||||
DEBTOR_ADDRESS_TYPE_IS_INVALID = "Debtor address TYPE must be a string.",
|
||||
DEBTOR_BUILDING_NUMBER_LENGTH_IS_INVALID = "Debtor buildingNumber must be a maximum of 16 characters.",
|
||||
DEBTOR_BUILDING_NUMBER_TYPE_IS_INVALID = "Debtor buildingNumber must be either a string or a number.",
|
||||
DEBTOR_CITY_IS_UNDEFINED = "Debtor city cannot be undefined.",
|
||||
DEBTOR_CITY_LENGTH_IS_INVALID = "Debtor city must be a maximum of 35 characters.",
|
||||
DEBTOR_CITY_TYPE_IS_INVALID = "Debtor city must be a string.",
|
||||
DEBTOR_COUNTRY_IS_UNDEFINED = "Debtor country cannot be undefined.",
|
||||
DEBTOR_COUNTRY_LENGTH_IS_INVALID = "Debtor country must be 2 characters.",
|
||||
DEBTOR_COUNTRY_TYPE_IS_INVALID = "Debtor country must be a string.",
|
||||
DEBTOR_IS_UNDEFINED = "Debtor cannot be undefined.",
|
||||
DEBTOR_NAME_IS_UNDEFINED = "Debtor name cannot be undefined.",
|
||||
DEBTOR_NAME_LENGTH_IS_INVALID = "Debtor name must be a maximum of 70 characters.",
|
||||
DEBTOR_NAME_TYPE_IS_INVALID = "Debtor name must be a string.",
|
||||
DEBTOR_ZIP_IS_UNDEFINED = "Debtor zip cannot be undefined.",
|
||||
DEBTOR_ZIP_LENGTH_IS_INVALID = "Debtor zip must be a maximum of 16 characters.",
|
||||
DEBTOR_ZIP_TYPE_IS_INVALID = "Debtor zip must be either a string or a number.",
|
||||
MESSAGE_AND_ADDITIONAL_INFORMATION_LENGTH_IS_INVALID = "Message and additionalInformation combined must be a maximum of 140 characters.",
|
||||
MESSAGE_LENGTH_IS_INVALID = "Message must be a maximum of 140 characters.",
|
||||
MESSAGE_TYPE_IS_INVALID = "Message must be a string.",
|
||||
QR_REFERENCE_IS_INVALID = "The provided QR-Reference '{reference}' is not valid.",
|
||||
QR_REFERENCE_LENGTH_IS_INVALID = "QR-Reference must be a must be exactly 27 characters.",
|
||||
REFERENCE_TYPE_IS_INVALID = "Reference must be a string.",
|
||||
REGULAR_REFERENCE_LENGTH_IS_INVALID = "Creditor reference must be a maximum of 25 characters."
|
||||
}
|
||||
700
node_modules/swissqrbill/lib/cjs/shared/qr-code-generator.cjs
generated
vendored
Normal file
700
node_modules/swissqrbill/lib/cjs/shared/qr-code-generator.cjs
generated
vendored
Normal file
@@ -0,0 +1,700 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
exports.qrcodegen = void 0;
|
||||
((qrcodegen2) => {
|
||||
const _QrCode = class _QrCode {
|
||||
/*-- Constructor (low level) and fields --*/
|
||||
// Creates a new QR Code with the given version number,
|
||||
// error correction level, data codeword bytes, and mask number.
|
||||
// This is a low-level API that most users should not use directly.
|
||||
// A mid-level API is the encodeSegments() function.
|
||||
constructor(version, errorCorrectionLevel, dataCodewords, msk) {
|
||||
this.version = version;
|
||||
this.errorCorrectionLevel = errorCorrectionLevel;
|
||||
this.modules = [];
|
||||
this.isFunction = [];
|
||||
if (version < _QrCode.MIN_VERSION || version > _QrCode.MAX_VERSION)
|
||||
throw "Version value out of range";
|
||||
if (msk < -1 || msk > 7)
|
||||
throw "Mask value out of range";
|
||||
this.size = version * 4 + 17;
|
||||
const row = [];
|
||||
for (let i = 0; i < this.size; i++)
|
||||
row.push(false);
|
||||
for (let i = 0; i < this.size; i++) {
|
||||
this.modules.push(row.slice());
|
||||
this.isFunction.push(row.slice());
|
||||
}
|
||||
this.drawFunctionPatterns();
|
||||
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
||||
this.drawCodewords(allCodewords);
|
||||
if (msk == -1) {
|
||||
let minPenalty = 1e9;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
this.applyMask(i);
|
||||
this.drawFormatBits(i);
|
||||
const penalty = this.getPenaltyScore();
|
||||
if (penalty < minPenalty) {
|
||||
msk = i;
|
||||
minPenalty = penalty;
|
||||
}
|
||||
this.applyMask(i);
|
||||
}
|
||||
}
|
||||
assert(0 <= msk && msk <= 7);
|
||||
this.mask = msk;
|
||||
this.applyMask(msk);
|
||||
this.drawFormatBits(msk);
|
||||
this.isFunction = [];
|
||||
}
|
||||
/*-- Static factory functions (high level) --*/
|
||||
// Returns a QR Code representing the given Unicode text string at the given error correction level.
|
||||
// As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
|
||||
// Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
|
||||
// QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
|
||||
// ecl argument if it can be done without increasing the version.
|
||||
static encodeText(text, ecl) {
|
||||
const segs = qrcodegen2.QrSegment.makeSegments(text);
|
||||
return _QrCode.encodeSegments(segs, ecl);
|
||||
}
|
||||
// Returns a QR Code representing the given binary data at the given error correction level.
|
||||
// This function always encodes using the binary segment mode, not any text mode. The maximum number of
|
||||
// bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
|
||||
// The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
|
||||
static encodeBinary(data, ecl) {
|
||||
const seg = qrcodegen2.QrSegment.makeBytes(data);
|
||||
return _QrCode.encodeSegments([seg], ecl);
|
||||
}
|
||||
/*-- Static factory functions (mid level) --*/
|
||||
// Returns a QR Code representing the given segments with the given encoding parameters.
|
||||
// The smallest possible QR Code version within the given range is automatically
|
||||
// chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
||||
// may be higher than the ecl argument if it can be done without increasing the
|
||||
// version. The mask number is either between 0 to 7 (inclusive) to force that
|
||||
// mask, or -1 to automatically choose an appropriate mask (which may be slow).
|
||||
// This function allows the user to create a custom sequence of segments that switches
|
||||
// between modes (such as alphanumeric and byte) to encode text in less space.
|
||||
// This is a mid-level API; the high-level API is encodeText() and encodeBinary().
|
||||
static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
||||
if (!(_QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode.MAX_VERSION) || mask < -1 || mask > 7)
|
||||
throw "Invalid value";
|
||||
let version;
|
||||
let dataUsedBits;
|
||||
for (version = minVersion; ; version++) {
|
||||
const dataCapacityBits2 = _QrCode.getNumDataCodewords(version, ecl) * 8;
|
||||
const usedBits = QrSegment.getTotalBits(segs, version);
|
||||
if (usedBits <= dataCapacityBits2) {
|
||||
dataUsedBits = usedBits;
|
||||
break;
|
||||
}
|
||||
if (version >= maxVersion)
|
||||
throw "Data too long";
|
||||
}
|
||||
for (const newEcl of [_QrCode.Ecc.MEDIUM, _QrCode.Ecc.QUARTILE, _QrCode.Ecc.HIGH]) {
|
||||
if (boostEcl && dataUsedBits <= _QrCode.getNumDataCodewords(version, newEcl) * 8)
|
||||
ecl = newEcl;
|
||||
}
|
||||
const bb = [];
|
||||
for (const seg of segs) {
|
||||
appendBits(seg.mode.modeBits, 4, bb);
|
||||
appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
|
||||
for (const b of seg.getData())
|
||||
bb.push(b);
|
||||
}
|
||||
assert(bb.length == dataUsedBits);
|
||||
const dataCapacityBits = _QrCode.getNumDataCodewords(version, ecl) * 8;
|
||||
assert(bb.length <= dataCapacityBits);
|
||||
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
||||
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
||||
assert(bb.length % 8 == 0);
|
||||
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
|
||||
appendBits(padByte, 8, bb);
|
||||
const dataCodewords = [];
|
||||
while (dataCodewords.length * 8 < bb.length)
|
||||
dataCodewords.push(0);
|
||||
bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
|
||||
return new _QrCode(version, ecl, dataCodewords, mask);
|
||||
}
|
||||
/*-- Accessor methods --*/
|
||||
// Returns the color of the module (pixel) at the given coordinates, which is false
|
||||
// for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
||||
// If the given coordinates are out of bounds, then false (light) is returned.
|
||||
getModule(x, y) {
|
||||
return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
|
||||
}
|
||||
/*-- Private helper methods for constructor: Drawing function modules --*/
|
||||
// Reads this object's version field, and draws and marks all function modules.
|
||||
drawFunctionPatterns() {
|
||||
for (let i = 0; i < this.size; i++) {
|
||||
this.setFunctionModule(6, i, i % 2 == 0);
|
||||
this.setFunctionModule(i, 6, i % 2 == 0);
|
||||
}
|
||||
this.drawFinderPattern(3, 3);
|
||||
this.drawFinderPattern(this.size - 4, 3);
|
||||
this.drawFinderPattern(3, this.size - 4);
|
||||
const alignPatPos = this.getAlignmentPatternPositions();
|
||||
const numAlign = alignPatPos.length;
|
||||
for (let i = 0; i < numAlign; i++) {
|
||||
for (let j = 0; j < numAlign; j++) {
|
||||
if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
|
||||
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
||||
}
|
||||
}
|
||||
this.drawFormatBits(0);
|
||||
this.drawVersion();
|
||||
}
|
||||
// Draws two copies of the format bits (with its own error correction code)
|
||||
// based on the given mask and this object's error correction level field.
|
||||
drawFormatBits(mask) {
|
||||
const data = this.errorCorrectionLevel.formatBits << 3 | mask;
|
||||
let rem = data;
|
||||
for (let i = 0; i < 10; i++)
|
||||
rem = rem << 1 ^ (rem >>> 9) * 1335;
|
||||
const bits = (data << 10 | rem) ^ 21522;
|
||||
assert(bits >>> 15 == 0);
|
||||
for (let i = 0; i <= 5; i++)
|
||||
this.setFunctionModule(8, i, getBit(bits, i));
|
||||
this.setFunctionModule(8, 7, getBit(bits, 6));
|
||||
this.setFunctionModule(8, 8, getBit(bits, 7));
|
||||
this.setFunctionModule(7, 8, getBit(bits, 8));
|
||||
for (let i = 9; i < 15; i++)
|
||||
this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
||||
for (let i = 0; i < 8; i++)
|
||||
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
||||
for (let i = 8; i < 15; i++)
|
||||
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
||||
this.setFunctionModule(8, this.size - 8, true);
|
||||
}
|
||||
// Draws two copies of the version bits (with its own error correction code),
|
||||
// based on this object's version field, iff 7 <= version <= 40.
|
||||
drawVersion() {
|
||||
if (this.version < 7)
|
||||
return;
|
||||
let rem = this.version;
|
||||
for (let i = 0; i < 12; i++)
|
||||
rem = rem << 1 ^ (rem >>> 11) * 7973;
|
||||
const bits = this.version << 12 | rem;
|
||||
assert(bits >>> 18 == 0);
|
||||
for (let i = 0; i < 18; i++) {
|
||||
const color = getBit(bits, i);
|
||||
const a = this.size - 11 + i % 3;
|
||||
const b = Math.floor(i / 3);
|
||||
this.setFunctionModule(a, b, color);
|
||||
this.setFunctionModule(b, a, color);
|
||||
}
|
||||
}
|
||||
// Draws a 9*9 finder pattern including the border separator,
|
||||
// with the center module at (x, y). Modules can be out of bounds.
|
||||
drawFinderPattern(x, y) {
|
||||
for (let dy = -4; dy <= 4; dy++) {
|
||||
for (let dx = -4; dx <= 4; dx++) {
|
||||
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
||||
const xx = x + dx;
|
||||
const yy = y + dy;
|
||||
if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
|
||||
this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Draws a 5*5 alignment pattern, with the center module
|
||||
// at (x, y). All modules must be in bounds.
|
||||
drawAlignmentPattern(x, y) {
|
||||
for (let dy = -2; dy <= 2; dy++) {
|
||||
for (let dx = -2; dx <= 2; dx++)
|
||||
this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
|
||||
}
|
||||
}
|
||||
// Sets the color of a module and marks it as a function module.
|
||||
// Only used by the constructor. Coordinates must be in bounds.
|
||||
setFunctionModule(x, y, isDark) {
|
||||
this.modules[y][x] = isDark;
|
||||
this.isFunction[y][x] = true;
|
||||
}
|
||||
/*-- Private helper methods for constructor: Codewords and masking --*/
|
||||
// Returns a new byte string representing the given data with the appropriate error correction
|
||||
// codewords appended to it, based on this object's version and error correction level.
|
||||
addEccAndInterleave(data) {
|
||||
const ver = this.version;
|
||||
const ecl = this.errorCorrectionLevel;
|
||||
if (data.length != _QrCode.getNumDataCodewords(ver, ecl))
|
||||
throw "Invalid argument";
|
||||
const numBlocks = _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
||||
const blockEccLen = _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
|
||||
const rawCodewords = Math.floor(_QrCode.getNumRawDataModules(ver) / 8);
|
||||
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
||||
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
||||
const blocks = [];
|
||||
const rsDiv = _QrCode.reedSolomonComputeDivisor(blockEccLen);
|
||||
for (let i = 0, k = 0; i < numBlocks; i++) {
|
||||
const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
||||
k += dat.length;
|
||||
const ecc = _QrCode.reedSolomonComputeRemainder(dat, rsDiv);
|
||||
if (i < numShortBlocks)
|
||||
dat.push(0);
|
||||
blocks.push(dat.concat(ecc));
|
||||
}
|
||||
const result = [];
|
||||
for (let i = 0; i < blocks[0].length; i++) {
|
||||
blocks.forEach((block, j) => {
|
||||
if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
|
||||
result.push(block[i]);
|
||||
});
|
||||
}
|
||||
assert(result.length == rawCodewords);
|
||||
return result;
|
||||
}
|
||||
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
||||
// data area of this QR Code. Function modules need to be marked off before this is called.
|
||||
drawCodewords(data) {
|
||||
if (data.length != Math.floor(_QrCode.getNumRawDataModules(this.version) / 8))
|
||||
throw "Invalid argument";
|
||||
let i = 0;
|
||||
for (let right = this.size - 1; right >= 1; right -= 2) {
|
||||
if (right == 6)
|
||||
right = 5;
|
||||
for (let vert = 0; vert < this.size; vert++) {
|
||||
for (let j = 0; j < 2; j++) {
|
||||
const x = right - j;
|
||||
const upward = (right + 1 & 2) == 0;
|
||||
const y = upward ? this.size - 1 - vert : vert;
|
||||
if (!this.isFunction[y][x] && i < data.length * 8) {
|
||||
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(i == data.length * 8);
|
||||
}
|
||||
// XORs the codeword modules in this QR Code with the given mask pattern.
|
||||
// The function modules must be marked and the codeword bits must be drawn
|
||||
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
||||
// the same mask value a second time will undo the mask. A final well-formed
|
||||
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
||||
applyMask(mask) {
|
||||
if (mask < 0 || mask > 7)
|
||||
throw "Mask value out of range";
|
||||
for (let y = 0; y < this.size; y++) {
|
||||
for (let x = 0; x < this.size; x++) {
|
||||
let invert;
|
||||
switch (mask) {
|
||||
case 0:
|
||||
invert = (x + y) % 2 == 0;
|
||||
break;
|
||||
case 1:
|
||||
invert = y % 2 == 0;
|
||||
break;
|
||||
case 2:
|
||||
invert = x % 3 == 0;
|
||||
break;
|
||||
case 3:
|
||||
invert = (x + y) % 3 == 0;
|
||||
break;
|
||||
case 4:
|
||||
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
|
||||
break;
|
||||
case 5:
|
||||
invert = x * y % 2 + x * y % 3 == 0;
|
||||
break;
|
||||
case 6:
|
||||
invert = (x * y % 2 + x * y % 3) % 2 == 0;
|
||||
break;
|
||||
case 7:
|
||||
invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
|
||||
break;
|
||||
default:
|
||||
throw "Unreachable";
|
||||
}
|
||||
if (!this.isFunction[y][x] && invert)
|
||||
this.modules[y][x] = !this.modules[y][x];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Calculates and returns the penalty score based on state of this QR Code's current modules.
|
||||
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
|
||||
getPenaltyScore() {
|
||||
let result = 0;
|
||||
for (let y = 0; y < this.size; y++) {
|
||||
let runColor = false;
|
||||
let runX = 0;
|
||||
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
||||
for (let x = 0; x < this.size; x++) {
|
||||
if (this.modules[y][x] == runColor) {
|
||||
runX++;
|
||||
if (runX == 5)
|
||||
result += _QrCode.PENALTY_N1;
|
||||
else if (runX > 5)
|
||||
result++;
|
||||
} else {
|
||||
this.finderPenaltyAddHistory(runX, runHistory);
|
||||
if (!runColor)
|
||||
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
|
||||
runColor = this.modules[y][x];
|
||||
runX = 1;
|
||||
}
|
||||
}
|
||||
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode.PENALTY_N3;
|
||||
}
|
||||
for (let x = 0; x < this.size; x++) {
|
||||
let runColor = false;
|
||||
let runY = 0;
|
||||
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
||||
for (let y = 0; y < this.size; y++) {
|
||||
if (this.modules[y][x] == runColor) {
|
||||
runY++;
|
||||
if (runY == 5)
|
||||
result += _QrCode.PENALTY_N1;
|
||||
else if (runY > 5)
|
||||
result++;
|
||||
} else {
|
||||
this.finderPenaltyAddHistory(runY, runHistory);
|
||||
if (!runColor)
|
||||
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
|
||||
runColor = this.modules[y][x];
|
||||
runY = 1;
|
||||
}
|
||||
}
|
||||
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode.PENALTY_N3;
|
||||
}
|
||||
for (let y = 0; y < this.size - 1; y++) {
|
||||
for (let x = 0; x < this.size - 1; x++) {
|
||||
const color = this.modules[y][x];
|
||||
if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1])
|
||||
result += _QrCode.PENALTY_N2;
|
||||
}
|
||||
}
|
||||
let dark = 0;
|
||||
for (const row of this.modules)
|
||||
dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
|
||||
const total = this.size * this.size;
|
||||
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
||||
assert(0 <= k && k <= 9);
|
||||
result += k * _QrCode.PENALTY_N4;
|
||||
assert(0 <= result && result <= 2568888);
|
||||
return result;
|
||||
}
|
||||
/*-- Private helper functions --*/
|
||||
// Returns an ascending list of positions of alignment patterns for this version number.
|
||||
// Each position is in the range [0,177), and are used on both the x and y axes.
|
||||
// This could be implemented as lookup table of 40 variable-length lists of integers.
|
||||
getAlignmentPatternPositions() {
|
||||
if (this.version == 1)
|
||||
return [];
|
||||
else {
|
||||
const numAlign = Math.floor(this.version / 7) + 2;
|
||||
const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
||||
const result = [6];
|
||||
for (let pos = this.size - 7; result.length < numAlign; pos -= step)
|
||||
result.splice(1, 0, pos);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
|
||||
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
||||
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
||||
static getNumRawDataModules(ver) {
|
||||
if (ver < _QrCode.MIN_VERSION || ver > _QrCode.MAX_VERSION)
|
||||
throw "Version number out of range";
|
||||
let result = (16 * ver + 128) * ver + 64;
|
||||
if (ver >= 2) {
|
||||
const numAlign = Math.floor(ver / 7) + 2;
|
||||
result -= (25 * numAlign - 10) * numAlign - 55;
|
||||
if (ver >= 7)
|
||||
result -= 36;
|
||||
}
|
||||
assert(208 <= result && result <= 29648);
|
||||
return result;
|
||||
}
|
||||
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
|
||||
// QR Code of the given version number and error correction level, with remainder bits discarded.
|
||||
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
|
||||
static getNumDataCodewords(ver, ecl) {
|
||||
return Math.floor(_QrCode.getNumRawDataModules(ver) / 8) - _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
||||
}
|
||||
// Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
|
||||
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
|
||||
static reedSolomonComputeDivisor(degree) {
|
||||
if (degree < 1 || degree > 255)
|
||||
throw "Degree out of range";
|
||||
const result = [];
|
||||
for (let i = 0; i < degree - 1; i++)
|
||||
result.push(0);
|
||||
result.push(1);
|
||||
let root = 1;
|
||||
for (let i = 0; i < degree; i++) {
|
||||
for (let j = 0; j < result.length; j++) {
|
||||
result[j] = _QrCode.reedSolomonMultiply(result[j], root);
|
||||
if (j + 1 < result.length)
|
||||
result[j] ^= result[j + 1];
|
||||
}
|
||||
root = _QrCode.reedSolomonMultiply(root, 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
|
||||
static reedSolomonComputeRemainder(data, divisor) {
|
||||
const result = divisor.map((_) => 0);
|
||||
for (const b of data) {
|
||||
const factor = b ^ result.shift();
|
||||
result.push(0);
|
||||
divisor.forEach((coef, i) => result[i] ^= _QrCode.reedSolomonMultiply(coef, factor));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
|
||||
// are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
|
||||
static reedSolomonMultiply(x, y) {
|
||||
if (x >>> 8 != 0 || y >>> 8 != 0)
|
||||
throw "Byte out of range";
|
||||
let z = 0;
|
||||
for (let i = 7; i >= 0; i--) {
|
||||
z = z << 1 ^ (z >>> 7) * 285;
|
||||
z ^= (y >>> i & 1) * x;
|
||||
}
|
||||
assert(z >>> 8 == 0);
|
||||
return z;
|
||||
}
|
||||
// Can only be called immediately after a light run is added, and
|
||||
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
||||
finderPenaltyCountPatterns(runHistory) {
|
||||
const n = runHistory[1];
|
||||
assert(n <= this.size * 3);
|
||||
const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
|
||||
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
||||
}
|
||||
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
||||
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
||||
if (currentRunColor) {
|
||||
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
||||
currentRunLength = 0;
|
||||
}
|
||||
currentRunLength += this.size;
|
||||
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
||||
return this.finderPenaltyCountPatterns(runHistory);
|
||||
}
|
||||
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
||||
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
||||
if (runHistory[0] == 0)
|
||||
currentRunLength += this.size;
|
||||
runHistory.pop();
|
||||
runHistory.unshift(currentRunLength);
|
||||
}
|
||||
};
|
||||
_QrCode.MIN_VERSION = 1;
|
||||
_QrCode.MAX_VERSION = 40;
|
||||
_QrCode.PENALTY_N1 = 3;
|
||||
_QrCode.PENALTY_N2 = 3;
|
||||
_QrCode.PENALTY_N3 = 40;
|
||||
_QrCode.PENALTY_N4 = 10;
|
||||
_QrCode.ECC_CODEWORDS_PER_BLOCK = [
|
||||
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
||||
//0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
||||
[-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
||||
// Low
|
||||
[-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
|
||||
// Medium
|
||||
[-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
||||
// Quartile
|
||||
[-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
|
||||
// High
|
||||
];
|
||||
_QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
|
||||
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
||||
//0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
||||
[-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
|
||||
// Low
|
||||
[-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
|
||||
// Medium
|
||||
[-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
|
||||
// Quartile
|
||||
[-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
|
||||
// High
|
||||
];
|
||||
let QrCode = _QrCode;
|
||||
qrcodegen2.QrCode = QrCode;
|
||||
function appendBits(val, len, bb) {
|
||||
if (len < 0 || len > 31 || val >>> len != 0)
|
||||
throw "Value out of range";
|
||||
for (let i = len - 1; i >= 0; i--)
|
||||
bb.push(val >>> i & 1);
|
||||
}
|
||||
function getBit(x, i) {
|
||||
return (x >>> i & 1) != 0;
|
||||
}
|
||||
function assert(cond) {
|
||||
if (!cond)
|
||||
throw "Assertion error";
|
||||
}
|
||||
const _QrSegment = class _QrSegment {
|
||||
/*-- Constructor (low level) and fields --*/
|
||||
// Creates a new QR Code segment with the given attributes and data.
|
||||
// The character count (numChars) must agree with the mode and the bit buffer length,
|
||||
// but the constraint isn't checked. The given bit buffer is cloned and stored.
|
||||
constructor(mode, numChars, bitData) {
|
||||
this.mode = mode;
|
||||
this.numChars = numChars;
|
||||
this.bitData = bitData;
|
||||
if (numChars < 0)
|
||||
throw "Invalid argument";
|
||||
this.bitData = bitData.slice();
|
||||
}
|
||||
/*-- Static factory functions (mid level) --*/
|
||||
// Returns a segment representing the given binary data encoded in
|
||||
// byte mode. All input byte arrays are acceptable. Any text string
|
||||
// can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
||||
static makeBytes(data) {
|
||||
const bb = [];
|
||||
for (const b of data)
|
||||
appendBits(b, 8, bb);
|
||||
return new _QrSegment(_QrSegment.Mode.BYTE, data.length, bb);
|
||||
}
|
||||
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
||||
static makeNumeric(digits) {
|
||||
if (!_QrSegment.isNumeric(digits))
|
||||
throw "String contains non-numeric characters";
|
||||
const bb = [];
|
||||
for (let i = 0; i < digits.length; ) {
|
||||
const n = Math.min(digits.length - i, 3);
|
||||
appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1, bb);
|
||||
i += n;
|
||||
}
|
||||
return new _QrSegment(_QrSegment.Mode.NUMERIC, digits.length, bb);
|
||||
}
|
||||
// Returns a segment representing the given text string encoded in alphanumeric mode.
|
||||
// The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
||||
// dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||
static makeAlphanumeric(text) {
|
||||
if (!_QrSegment.isAlphanumeric(text))
|
||||
throw "String contains unencodable characters in alphanumeric mode";
|
||||
const bb = [];
|
||||
let i;
|
||||
for (i = 0; i + 2 <= text.length; i += 2) {
|
||||
let temp = _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
||||
temp += _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
||||
appendBits(temp, 11, bb);
|
||||
}
|
||||
if (i < text.length)
|
||||
appendBits(_QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
||||
return new _QrSegment(_QrSegment.Mode.ALPHANUMERIC, text.length, bb);
|
||||
}
|
||||
// Returns a new mutable list of zero or more segments to represent the given Unicode text string.
|
||||
// The result may use various segment modes and switch modes to optimize the length of the bit stream.
|
||||
static makeSegments(text) {
|
||||
if (text == "")
|
||||
return [];
|
||||
else if (_QrSegment.isNumeric(text))
|
||||
return [_QrSegment.makeNumeric(text)];
|
||||
else if (_QrSegment.isAlphanumeric(text))
|
||||
return [_QrSegment.makeAlphanumeric(text)];
|
||||
else
|
||||
return [_QrSegment.makeBytes(_QrSegment.toUtf8ByteArray(text))];
|
||||
}
|
||||
// Returns a segment representing an Extended Channel Interpretation
|
||||
// (ECI) designator with the given assignment value.
|
||||
static makeEci(assignVal) {
|
||||
const bb = [];
|
||||
if (assignVal < 0)
|
||||
throw "ECI assignment value out of range";
|
||||
else if (assignVal < 1 << 7)
|
||||
appendBits(assignVal, 8, bb);
|
||||
else if (assignVal < 1 << 14) {
|
||||
appendBits(2, 2, bb);
|
||||
appendBits(assignVal, 14, bb);
|
||||
} else if (assignVal < 1e6) {
|
||||
appendBits(6, 3, bb);
|
||||
appendBits(assignVal, 21, bb);
|
||||
} else
|
||||
throw "ECI assignment value out of range";
|
||||
return new _QrSegment(_QrSegment.Mode.ECI, 0, bb);
|
||||
}
|
||||
// Tests whether the given string can be encoded as a segment in numeric mode.
|
||||
// A string is encodable iff each character is in the range 0 to 9.
|
||||
static isNumeric(text) {
|
||||
return _QrSegment.NUMERIC_REGEX.test(text);
|
||||
}
|
||||
// Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
||||
// A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
||||
// (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
||||
static isAlphanumeric(text) {
|
||||
return _QrSegment.ALPHANUMERIC_REGEX.test(text);
|
||||
}
|
||||
/*-- Methods --*/
|
||||
// Returns a new copy of the data bits of this segment.
|
||||
getData() {
|
||||
return this.bitData.slice();
|
||||
}
|
||||
// (Package-private) Calculates and returns the number of bits needed to encode the given segments at
|
||||
// the given version. The result is infinity if a segment has too many characters to fit its length field.
|
||||
static getTotalBits(segs, version) {
|
||||
let result = 0;
|
||||
for (const seg of segs) {
|
||||
const ccbits = seg.mode.numCharCountBits(version);
|
||||
if (seg.numChars >= 1 << ccbits)
|
||||
return Infinity;
|
||||
result += 4 + ccbits + seg.bitData.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Returns a new array of bytes representing the given string encoded in UTF-8.
|
||||
static toUtf8ByteArray(str) {
|
||||
str = encodeURI(str);
|
||||
const result = [];
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
if (str.charAt(i) != "%")
|
||||
result.push(str.charCodeAt(i));
|
||||
else {
|
||||
result.push(parseInt(str.substr(i + 1, 2), 16));
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
_QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
|
||||
_QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
|
||||
_QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
||||
let QrSegment = _QrSegment;
|
||||
qrcodegen2.QrSegment = QrSegment;
|
||||
})(exports.qrcodegen || (exports.qrcodegen = {}));
|
||||
((qrcodegen2) => {
|
||||
((QrCode2) => {
|
||||
const _Ecc = class _Ecc {
|
||||
// The QR Code can tolerate about 30% erroneous codewords
|
||||
/*-- Constructor and fields --*/
|
||||
constructor(ordinal, formatBits) {
|
||||
this.ordinal = ordinal;
|
||||
this.formatBits = formatBits;
|
||||
}
|
||||
};
|
||||
_Ecc.LOW = new _Ecc(0, 1);
|
||||
_Ecc.MEDIUM = new _Ecc(1, 0);
|
||||
_Ecc.QUARTILE = new _Ecc(2, 3);
|
||||
_Ecc.HIGH = new _Ecc(3, 2);
|
||||
let Ecc = _Ecc;
|
||||
QrCode2.Ecc = Ecc;
|
||||
})(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
|
||||
})(exports.qrcodegen || (exports.qrcodegen = {}));
|
||||
((qrcodegen2) => {
|
||||
((QrSegment2) => {
|
||||
const _Mode = class _Mode {
|
||||
/*-- Constructor and fields --*/
|
||||
constructor(modeBits, numBitsCharCount) {
|
||||
this.modeBits = modeBits;
|
||||
this.numBitsCharCount = numBitsCharCount;
|
||||
}
|
||||
/*-- Method --*/
|
||||
// (Package-private) Returns the bit width of the character count field for a segment in
|
||||
// this mode in a QR Code at the given version number. The result is in the range [0, 16].
|
||||
numCharCountBits(ver) {
|
||||
return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
|
||||
}
|
||||
};
|
||||
_Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
|
||||
_Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
|
||||
_Mode.BYTE = new _Mode(4, [8, 16, 16]);
|
||||
_Mode.KANJI = new _Mode(8, [8, 10, 12]);
|
||||
_Mode.ECI = new _Mode(7, [0, 0, 0]);
|
||||
let Mode = _Mode;
|
||||
QrSegment2.Mode = Mode;
|
||||
})(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
|
||||
})(exports.qrcodegen || (exports.qrcodegen = {}));
|
||||
93
node_modules/swissqrbill/lib/cjs/shared/qr-code-generator.d.ts
generated
vendored
Normal file
93
node_modules/swissqrbill/lib/cjs/shared/qr-code-generator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
export declare namespace qrcodegen {
|
||||
type bit = number;
|
||||
type byte = number;
|
||||
type int = number;
|
||||
export class QrCode {
|
||||
readonly version: int;
|
||||
readonly errorCorrectionLevel: QrCode.Ecc;
|
||||
static encodeText(text: string, ecl: QrCode.Ecc): QrCode;
|
||||
static encodeBinary(data: Readonly<Array<byte>>, ecl: QrCode.Ecc): QrCode;
|
||||
static encodeSegments(segs: Readonly<Array<QrSegment>>, ecl: QrCode.Ecc, minVersion?: int, maxVersion?: int, mask?: int, boostEcl?: boolean): QrCode;
|
||||
readonly size: int;
|
||||
readonly mask: int;
|
||||
private readonly modules;
|
||||
private readonly isFunction;
|
||||
constructor(version: int, errorCorrectionLevel: QrCode.Ecc, dataCodewords: Readonly<Array<byte>>, msk: int);
|
||||
getModule(x: int, y: int): boolean;
|
||||
private drawFunctionPatterns;
|
||||
private drawFormatBits;
|
||||
private drawVersion;
|
||||
private drawFinderPattern;
|
||||
private drawAlignmentPattern;
|
||||
private setFunctionModule;
|
||||
private addEccAndInterleave;
|
||||
private drawCodewords;
|
||||
private applyMask;
|
||||
private getPenaltyScore;
|
||||
private getAlignmentPatternPositions;
|
||||
private static getNumRawDataModules;
|
||||
private static getNumDataCodewords;
|
||||
private static reedSolomonComputeDivisor;
|
||||
private static reedSolomonComputeRemainder;
|
||||
private static reedSolomonMultiply;
|
||||
private finderPenaltyCountPatterns;
|
||||
private finderPenaltyTerminateAndCount;
|
||||
private finderPenaltyAddHistory;
|
||||
static readonly MIN_VERSION: int;
|
||||
static readonly MAX_VERSION: int;
|
||||
private static readonly PENALTY_N1;
|
||||
private static readonly PENALTY_N2;
|
||||
private static readonly PENALTY_N3;
|
||||
private static readonly PENALTY_N4;
|
||||
private static readonly ECC_CODEWORDS_PER_BLOCK;
|
||||
private static readonly NUM_ERROR_CORRECTION_BLOCKS;
|
||||
}
|
||||
export class QrSegment {
|
||||
readonly mode: QrSegment.Mode;
|
||||
readonly numChars: int;
|
||||
private readonly bitData;
|
||||
static makeBytes(data: Readonly<Array<byte>>): QrSegment;
|
||||
static makeNumeric(digits: string): QrSegment;
|
||||
static makeAlphanumeric(text: string): QrSegment;
|
||||
static makeSegments(text: string): Array<QrSegment>;
|
||||
static makeEci(assignVal: int): QrSegment;
|
||||
static isNumeric(text: string): boolean;
|
||||
static isAlphanumeric(text: string): boolean;
|
||||
constructor(mode: QrSegment.Mode, numChars: int, bitData: Array<bit>);
|
||||
getData(): Array<bit>;
|
||||
static getTotalBits(segs: Readonly<Array<QrSegment>>, version: int): number;
|
||||
private static toUtf8ByteArray;
|
||||
private static readonly NUMERIC_REGEX;
|
||||
private static readonly ALPHANUMERIC_REGEX;
|
||||
private static readonly ALPHANUMERIC_CHARSET;
|
||||
}
|
||||
export {};
|
||||
}
|
||||
export declare namespace qrcodegen.QrCode {
|
||||
type int = number;
|
||||
export class Ecc {
|
||||
readonly ordinal: int;
|
||||
readonly formatBits: int;
|
||||
static readonly LOW: Ecc;
|
||||
static readonly MEDIUM: Ecc;
|
||||
static readonly QUARTILE: Ecc;
|
||||
static readonly HIGH: Ecc;
|
||||
private constructor();
|
||||
}
|
||||
export {};
|
||||
}
|
||||
export declare namespace qrcodegen.QrSegment {
|
||||
type int = number;
|
||||
export class Mode {
|
||||
readonly modeBits: int;
|
||||
private readonly numBitsCharCount;
|
||||
static readonly NUMERIC: Mode;
|
||||
static readonly ALPHANUMERIC: Mode;
|
||||
static readonly BYTE: Mode;
|
||||
static readonly KANJI: Mode;
|
||||
static readonly ECI: Mode;
|
||||
private constructor();
|
||||
numCharCountBits(ver: int): int;
|
||||
}
|
||||
export {};
|
||||
}
|
||||
155
node_modules/swissqrbill/lib/cjs/shared/qr-code.cjs
generated
vendored
Normal file
155
node_modules/swissqrbill/lib/cjs/shared/qr-code.cjs
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const cleaner = require("./cleaner.cjs");
|
||||
const qrCodeGenerator = require("./qr-code-generator.cjs");
|
||||
const validator = require("./validator.cjs");
|
||||
const utils = require("./utils.cjs");
|
||||
function generateQRData(data) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const cleanedData = cleaner.cleanData(data);
|
||||
validator.validateData(cleanedData);
|
||||
const amount = (_a = cleanedData.amount) == null ? void 0 : _a.toFixed(2);
|
||||
const reference = utils.getReferenceType(cleanedData.reference);
|
||||
const qrData = [
|
||||
"SPC",
|
||||
// Swiss Payments Code
|
||||
"0200",
|
||||
// Version
|
||||
"1",
|
||||
// Coding Type UTF-8
|
||||
(_b = cleanedData.creditor.account) != null ? _b : "",
|
||||
// IBAN
|
||||
"S",
|
||||
// Address Type
|
||||
cleanedData.creditor.name,
|
||||
// Name
|
||||
cleanedData.creditor.address,
|
||||
// Address
|
||||
cleanedData.creditor.buildingNumber ? `${cleanedData.creditor.buildingNumber}` : "",
|
||||
`${cleanedData.creditor.zip}`,
|
||||
// Zip
|
||||
cleanedData.creditor.city,
|
||||
// City
|
||||
cleanedData.creditor.country,
|
||||
// Country
|
||||
"",
|
||||
// 1x Empty
|
||||
"",
|
||||
// 2x Empty
|
||||
"",
|
||||
// 3x Empty
|
||||
"",
|
||||
// 4x Empty
|
||||
"",
|
||||
// 5x Empty
|
||||
"",
|
||||
// 6x Empty
|
||||
"",
|
||||
// 7x Empty
|
||||
amount != null ? amount : "",
|
||||
// Amount
|
||||
cleanedData.currency,
|
||||
// Currency
|
||||
...cleanedData.debtor ? [
|
||||
"S",
|
||||
// Address Type
|
||||
cleanedData.debtor.name,
|
||||
// Name
|
||||
cleanedData.debtor.address,
|
||||
// Address
|
||||
cleanedData.debtor.buildingNumber ? `${cleanedData.debtor.buildingNumber}` : "",
|
||||
`${cleanedData.debtor.zip}`,
|
||||
// Zip
|
||||
cleanedData.debtor.city,
|
||||
// City
|
||||
(_c = cleanedData.debtor.country) != null ? _c : ""
|
||||
// Country
|
||||
] : [
|
||||
"",
|
||||
// Empty address type
|
||||
"",
|
||||
// Empty name
|
||||
"",
|
||||
// Empty address
|
||||
"",
|
||||
// Empty building number
|
||||
"",
|
||||
// Empty zip field
|
||||
"",
|
||||
// Empty city field
|
||||
""
|
||||
// Empty country
|
||||
],
|
||||
reference,
|
||||
// Reference type
|
||||
(_d = cleanedData.reference) != null ? _d : "",
|
||||
// Reference
|
||||
(_e = cleanedData.message) != null ? _e : "",
|
||||
// Unstructured message
|
||||
"EPD",
|
||||
// End of payment data
|
||||
(_f = cleanedData.additionalInformation) != null ? _f : "",
|
||||
// Additional information
|
||||
...cleanedData.av1 ? [
|
||||
cleanedData.av1
|
||||
] : [],
|
||||
...cleanedData.av2 ? [
|
||||
cleanedData.av2
|
||||
] : []
|
||||
];
|
||||
return qrData.join("\n");
|
||||
}
|
||||
function renderQRCode(data, size, renderBlockFunction) {
|
||||
const qrData = generateQRData(data);
|
||||
const eci = qrCodeGenerator.qrcodegen.QrSegment.makeEci(26);
|
||||
const segments = qrCodeGenerator.qrcodegen.QrSegment.makeSegments(qrData);
|
||||
const qrCode = qrCodeGenerator.qrcodegen.QrCode.encodeSegments([eci, ...segments], qrCodeGenerator.qrcodegen.QrCode.Ecc.MEDIUM, 10, 25);
|
||||
const blockSize = size / qrCode.size;
|
||||
for (let x = 0; x < qrCode.size; x++) {
|
||||
const xPos = x * blockSize;
|
||||
for (let y = 0; y < qrCode.size; y++) {
|
||||
const yPos = y * blockSize;
|
||||
if (qrCode.getModule(x, y)) {
|
||||
renderBlockFunction(xPos, yPos, blockSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function renderSwissCross(size, renderRectFunction) {
|
||||
const scale = size / utils.mm2pt(46);
|
||||
const swissCrossWhiteBackgroundSize = utils.mm2pt(7) * scale;
|
||||
const swissCrossBlackBackgroundSize = utils.mm2pt(6) * scale;
|
||||
const swissCrossThickness = utils.mm2pt(1.17) * scale;
|
||||
const swissCrossLength = utils.mm2pt(3.89) * scale;
|
||||
renderRectFunction(
|
||||
size / 2 - swissCrossWhiteBackgroundSize / 2,
|
||||
size / 2 - swissCrossWhiteBackgroundSize / 2,
|
||||
swissCrossWhiteBackgroundSize,
|
||||
swissCrossWhiteBackgroundSize,
|
||||
"white"
|
||||
);
|
||||
renderRectFunction(
|
||||
size / 2 - swissCrossBlackBackgroundSize / 2,
|
||||
size / 2 - swissCrossBlackBackgroundSize / 2,
|
||||
swissCrossBlackBackgroundSize,
|
||||
swissCrossBlackBackgroundSize,
|
||||
"black"
|
||||
);
|
||||
renderRectFunction(
|
||||
size / 2 - swissCrossLength / 2,
|
||||
size / 2 - swissCrossThickness / 2,
|
||||
swissCrossLength,
|
||||
swissCrossThickness,
|
||||
"white"
|
||||
);
|
||||
renderRectFunction(
|
||||
size / 2 - swissCrossThickness / 2,
|
||||
size / 2 - swissCrossLength / 2,
|
||||
swissCrossThickness,
|
||||
swissCrossLength,
|
||||
"white"
|
||||
);
|
||||
}
|
||||
exports.generateQRData = generateQRData;
|
||||
exports.renderQRCode = renderQRCode;
|
||||
exports.renderSwissCross = renderSwissCross;
|
||||
4
node_modules/swissqrbill/lib/cjs/shared/qr-code.d.ts
generated
vendored
Normal file
4
node_modules/swissqrbill/lib/cjs/shared/qr-code.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Data } from './types.js';
|
||||
export declare function generateQRData(data: Data): string;
|
||||
export declare function renderQRCode(data: Data, size: number, renderBlockFunction: (x: number, y: number, blockSize: number) => void): void;
|
||||
export declare function renderSwissCross(size: number, renderRectFunction: (x: number, y: number, width: number, height: number, fillColor: string) => void): void;
|
||||
61
node_modules/swissqrbill/lib/cjs/shared/translations.cjs
generated
vendored
Normal file
61
node_modules/swissqrbill/lib/cjs/shared/translations.cjs
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const translations = {
|
||||
DE: {
|
||||
acceptancePoint: "Annahmestelle",
|
||||
account: "Konto / Zahlbar an",
|
||||
additionalInformation: "Zusätzliche Informationen",
|
||||
amount: "Betrag",
|
||||
currency: "Währung",
|
||||
inFavourOf: "Zugunsten",
|
||||
payableBy: "Zahlbar durch",
|
||||
payableByName: "Zahlbar durch (Name/Adresse)",
|
||||
paymentPart: "Zahlteil",
|
||||
receipt: "Empfangsschein",
|
||||
reference: "Referenz",
|
||||
separate: "Vor der Einzahlung abzutrennen"
|
||||
},
|
||||
EN: {
|
||||
acceptancePoint: "Acceptance point",
|
||||
account: "Account / Payable to",
|
||||
additionalInformation: "Additional information",
|
||||
amount: "Amount",
|
||||
currency: "Currency",
|
||||
inFavourOf: "In favour of",
|
||||
payableBy: "Payable by",
|
||||
payableByName: "Payable by (name/address)",
|
||||
paymentPart: "Payment part",
|
||||
receipt: "Receipt",
|
||||
reference: "Reference",
|
||||
separate: "Separate before paying in"
|
||||
},
|
||||
FR: {
|
||||
acceptancePoint: "Point de dépôt",
|
||||
account: "Compte / Payable à",
|
||||
additionalInformation: "Informations supplémentaires",
|
||||
amount: "Montant",
|
||||
currency: "Monnaie",
|
||||
inFavourOf: "En faveur de",
|
||||
payableBy: "Payable par",
|
||||
payableByName: "Payable par (nom/adresse)",
|
||||
paymentPart: "Section paiement",
|
||||
receipt: "Récépissé",
|
||||
reference: "Référence",
|
||||
separate: "A détacher avant le versement"
|
||||
},
|
||||
IT: {
|
||||
acceptancePoint: "Punto di accettazione",
|
||||
account: "Conto / Pagabile a",
|
||||
additionalInformation: "Informazioni supplementari",
|
||||
amount: "Importo",
|
||||
currency: "Valuta",
|
||||
inFavourOf: "A favore di",
|
||||
payableBy: "Pagabile da",
|
||||
payableByName: "Pagabile da (nome/indirizzo)",
|
||||
paymentPart: "Sezione pagamento",
|
||||
receipt: "Ricevuta",
|
||||
reference: "Riferimento",
|
||||
separate: "Da staccare prima del versamento"
|
||||
}
|
||||
};
|
||||
exports.translations = translations;
|
||||
58
node_modules/swissqrbill/lib/cjs/shared/translations.d.ts
generated
vendored
Normal file
58
node_modules/swissqrbill/lib/cjs/shared/translations.d.ts
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
export declare const translations: {
|
||||
DE: {
|
||||
acceptancePoint: string;
|
||||
account: string;
|
||||
additionalInformation: string;
|
||||
amount: string;
|
||||
currency: string;
|
||||
inFavourOf: string;
|
||||
payableBy: string;
|
||||
payableByName: string;
|
||||
paymentPart: string;
|
||||
receipt: string;
|
||||
reference: string;
|
||||
separate: string;
|
||||
};
|
||||
EN: {
|
||||
acceptancePoint: string;
|
||||
account: string;
|
||||
additionalInformation: string;
|
||||
amount: string;
|
||||
currency: string;
|
||||
inFavourOf: string;
|
||||
payableBy: string;
|
||||
payableByName: string;
|
||||
paymentPart: string;
|
||||
receipt: string;
|
||||
reference: string;
|
||||
separate: string;
|
||||
};
|
||||
FR: {
|
||||
acceptancePoint: string;
|
||||
account: string;
|
||||
additionalInformation: string;
|
||||
amount: string;
|
||||
currency: string;
|
||||
inFavourOf: string;
|
||||
payableBy: string;
|
||||
payableByName: string;
|
||||
paymentPart: string;
|
||||
receipt: string;
|
||||
reference: string;
|
||||
separate: string;
|
||||
};
|
||||
IT: {
|
||||
acceptancePoint: string;
|
||||
account: string;
|
||||
additionalInformation: string;
|
||||
amount: string;
|
||||
currency: string;
|
||||
inFavourOf: string;
|
||||
payableBy: string;
|
||||
payableByName: string;
|
||||
paymentPart: string;
|
||||
receipt: string;
|
||||
reference: string;
|
||||
separate: string;
|
||||
};
|
||||
};
|
||||
1
node_modules/swissqrbill/lib/cjs/shared/types.cjs
generated
vendored
Normal file
1
node_modules/swissqrbill/lib/cjs/shared/types.cjs
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
134
node_modules/swissqrbill/lib/cjs/shared/types.d.ts
generated
vendored
Normal file
134
node_modules/swissqrbill/lib/cjs/shared/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
export interface Data {
|
||||
/**
|
||||
* Creditor related data.
|
||||
*/
|
||||
creditor: Creditor;
|
||||
/**
|
||||
* The currency to be used. **3 characters.**.
|
||||
*/
|
||||
currency: "CHF" | "EUR";
|
||||
/**
|
||||
* Additional information. **Max 140 characters.**.
|
||||
*
|
||||
* Bill information contain coded information for automated booking of the payment. The data is not forwarded with the payment.
|
||||
*/
|
||||
additionalInformation?: string;
|
||||
/**
|
||||
* The amount. **Max. 12 digits.**.
|
||||
*/
|
||||
amount?: number;
|
||||
/**
|
||||
* Alternative scheme. **Max. 100 characters.**.
|
||||
*
|
||||
* Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf).
|
||||
*/
|
||||
av1?: string;
|
||||
/**
|
||||
* Alternative scheme. **Max. 100 characters.**.
|
||||
*
|
||||
* Parameter character chain of the alternative scheme according to the syntax definition in the [“Alternative scheme” section](https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-en.pdf).
|
||||
*/
|
||||
av2?: string;
|
||||
/**
|
||||
* Debtor related data.
|
||||
*/
|
||||
debtor?: Debtor;
|
||||
/**
|
||||
* A message. **Max. 140 characters.**.
|
||||
*
|
||||
* Message can be used to indicate the payment purpose or for additional textual information about payments with a structured reference.
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* A reference number. **Max 27 characters.**.
|
||||
*
|
||||
* QR-IBAN: Maximum 27 characters. Must be filled if a QR-IBAN is used.
|
||||
* Creditor Reference (ISO 11649): Maximum 25 characters.
|
||||
*/
|
||||
reference?: string;
|
||||
}
|
||||
export interface Debtor {
|
||||
/**
|
||||
* Address. **Max 70 characters.**.
|
||||
*/
|
||||
address: string;
|
||||
/**
|
||||
* City. **Max 35 characters.**.
|
||||
*/
|
||||
city: string;
|
||||
/**
|
||||
* Country code. **2 characters.**.
|
||||
*/
|
||||
country: string;
|
||||
/**
|
||||
* Name. **Max. 70 characters.**.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Postal code. **Max 16 characters.**.
|
||||
*/
|
||||
zip: number | string;
|
||||
/**
|
||||
* Building number. **Max 16 characters.**.
|
||||
*/
|
||||
buildingNumber?: number | string;
|
||||
}
|
||||
export interface Creditor extends Debtor {
|
||||
/**
|
||||
* The IBAN. **21 characters.**.
|
||||
*/
|
||||
account: string;
|
||||
}
|
||||
interface QRBillOptions {
|
||||
/**
|
||||
* Font used for the QR-Bill.
|
||||
* Fonts other than Helvetica must be registered in the PDFKit document. {@link http://pdfkit.org/docs/text.html#fonts}.
|
||||
*
|
||||
* @default 'Helvetica'
|
||||
* @example
|
||||
* ```ts
|
||||
* // Register the font
|
||||
* pdf.registerFont("Liberation-Sans", "path/to/LiberationSans-Regular.ttf");
|
||||
* pdf.registerFont("Liberation-Sans-Bold", "path/to/LiberationSans-Bold.ttf");
|
||||
*
|
||||
* const qrBill = new SwissQRBill(data, { fontName: "Liberation-Sans" });
|
||||
* ```
|
||||
*/
|
||||
fontName?: "Arial" | "Frutiger" | "Helvetica" | "Liberation Sans";
|
||||
/**
|
||||
* The language with which the bill is rendered.
|
||||
*
|
||||
* @default `DE`
|
||||
*/
|
||||
language?: "DE" | "EN" | "FR" | "IT";
|
||||
/**
|
||||
* Whether you want render the outlines. This option may be disabled if you use perforated paper.
|
||||
*
|
||||
* @default `true`
|
||||
*/
|
||||
outlines?: boolean;
|
||||
/**
|
||||
* Whether you want to show the scissors icons or the text `Separate before paying in`.
|
||||
*
|
||||
* **Warning:** Setting **scissors** to false sets **separate** to true. To disable scissors and separate, you have to set both options to false.
|
||||
*
|
||||
* @default `true`
|
||||
*/
|
||||
scissors?: boolean;
|
||||
}
|
||||
export interface PDFOptions extends QRBillOptions {
|
||||
/**
|
||||
* Whether you want to show the text `Separate before paying in` rather than the scissors icons.
|
||||
*
|
||||
* **Warning:** Setting **separate** to true sets **scissors** to false. To disable scissors and separate, you have to set both options to false.
|
||||
*
|
||||
* @default `false`
|
||||
*/
|
||||
separate?: boolean;
|
||||
}
|
||||
export interface SVGOptions extends QRBillOptions {
|
||||
}
|
||||
export type Language = Exclude<QRBillOptions["language"], undefined>;
|
||||
export type FontName = Exclude<QRBillOptions["fontName"], undefined>;
|
||||
export type Currency = Exclude<Data["currency"], undefined>;
|
||||
export {};
|
||||
172
node_modules/swissqrbill/lib/cjs/shared/utils.cjs
generated
vendored
Normal file
172
node_modules/swissqrbill/lib/cjs/shared/utils.cjs
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
function isQRIBAN(iban) {
|
||||
iban = iban.replace(/ /g, "");
|
||||
const QRIID = iban.substring(4, 9);
|
||||
return +QRIID >= 3e4 && +QRIID <= 31999;
|
||||
}
|
||||
function isIBANValid(iban) {
|
||||
iban = iban.replace(/ /g, "").toUpperCase();
|
||||
iban = iban.substring(4) + iban.substring(0, 4);
|
||||
return mod97(iban) === 1;
|
||||
}
|
||||
function formatIBAN(iban) {
|
||||
var _a;
|
||||
const ibanArray = iban.replace(/ /g, "").match(/.{1,4}/g);
|
||||
return (_a = ibanArray == null ? void 0 : ibanArray.join(" ")) != null ? _a : iban;
|
||||
}
|
||||
function isQRReference(reference) {
|
||||
reference = reference.replace(/ /g, "");
|
||||
if (reference.length !== 27) {
|
||||
return false;
|
||||
}
|
||||
if (!/^\d+$/.test(reference)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function isQRReferenceValid(reference) {
|
||||
reference = reference.replace(/ /g, "");
|
||||
if (!isQRReference(reference)) {
|
||||
return false;
|
||||
}
|
||||
const ref = reference.substring(0, 26);
|
||||
const checksum = reference.substring(26, 27);
|
||||
const calculatedChecksum = calculateQRReferenceChecksum(ref);
|
||||
return calculatedChecksum === checksum;
|
||||
}
|
||||
function isSCORReference(reference) {
|
||||
reference = reference.replace(/ /g, "").toUpperCase();
|
||||
if (!reference.startsWith("RF")) {
|
||||
return false;
|
||||
}
|
||||
if (reference.length < 5 || reference.length > 25) {
|
||||
return false;
|
||||
}
|
||||
if (!/^[\dA-Z]+$/.test(reference)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function isSCORReferenceValid(reference) {
|
||||
reference = reference.replace(/ /g, "");
|
||||
if (!isSCORReference(reference)) {
|
||||
return false;
|
||||
}
|
||||
const ref = reference.substring(4);
|
||||
if (Number.isNaN(reference)) {
|
||||
return false;
|
||||
}
|
||||
const checksum = reference.substring(2, 4);
|
||||
if (Number.isNaN(checksum)) {
|
||||
return false;
|
||||
}
|
||||
const calculatedChecksum = calculateSCORReferenceChecksum(ref);
|
||||
return calculatedChecksum === checksum;
|
||||
}
|
||||
function calculateSCORReferenceChecksum(reference) {
|
||||
reference = reference.replace(/ /g, "");
|
||||
const checksum = 98 - mod97(`${reference}RF00`);
|
||||
return `${checksum}`.padStart(2, "0");
|
||||
}
|
||||
function calculateQRReferenceChecksum(reference) {
|
||||
return mod10(reference);
|
||||
}
|
||||
function formatQRReference(reference) {
|
||||
const trimmedReference = reference.replace(/ /g, "");
|
||||
const match = trimmedReference.substring(2).match(/.{1,5}/g);
|
||||
return match ? `${trimmedReference.substring(0, 2)} ${match.join(" ")}` : reference;
|
||||
}
|
||||
function formatSCORReference(reference) {
|
||||
var _a;
|
||||
const trimmedReference = reference.replace(/ /g, "");
|
||||
const match = trimmedReference.match(/.{1,4}/g);
|
||||
return (_a = match == null ? void 0 : match.join(" ")) != null ? _a : reference;
|
||||
}
|
||||
function formatReference(reference) {
|
||||
const referenceType = getReferenceType(reference);
|
||||
if (referenceType === "QRR") {
|
||||
return formatQRReference(reference);
|
||||
} else if (referenceType === "SCOR") {
|
||||
return formatSCORReference(reference);
|
||||
}
|
||||
return reference;
|
||||
}
|
||||
function formatAmount(amount) {
|
||||
const amountString = amount.toFixed(2);
|
||||
const amountArray = amountString.split(".");
|
||||
let formattedAmountWithoutDecimals = "";
|
||||
for (let x = amountArray[0].length - 1, i = 1; x >= 0; x--, i++) {
|
||||
formattedAmountWithoutDecimals = amountArray[0][x] + formattedAmountWithoutDecimals;
|
||||
if (i === 3) {
|
||||
formattedAmountWithoutDecimals = ` ${formattedAmountWithoutDecimals}`;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
return `${formattedAmountWithoutDecimals.trim()}.${amountArray[1]}`;
|
||||
}
|
||||
function mm2pt(millimeters) {
|
||||
return millimeters * 2.83465;
|
||||
}
|
||||
function pt2mm(points) {
|
||||
return points / 2.83465;
|
||||
}
|
||||
function mm2px(millimeters) {
|
||||
return millimeters * 960 / 254;
|
||||
}
|
||||
function px2mm(pixels) {
|
||||
return pixels * 254 / 960;
|
||||
}
|
||||
function getReferenceType(reference) {
|
||||
if (typeof reference === "undefined") {
|
||||
return "NON";
|
||||
} else if (isQRReference(reference)) {
|
||||
return "QRR";
|
||||
} else {
|
||||
return "SCOR";
|
||||
}
|
||||
}
|
||||
function mod97(input) {
|
||||
const charCodeOfLetterA = "A".charCodeAt(0);
|
||||
const inputArr = input.split("");
|
||||
for (let i = 0; i < inputArr.length; i++) {
|
||||
const charCode = inputArr[i].charCodeAt(0);
|
||||
if (charCode >= charCodeOfLetterA) {
|
||||
inputArr[i] = `${charCode - charCodeOfLetterA + 10}`;
|
||||
}
|
||||
}
|
||||
input = inputArr.join("");
|
||||
let remainder = 0;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const digit = +input[i];
|
||||
remainder = (10 * remainder + digit) % 97;
|
||||
}
|
||||
return remainder;
|
||||
}
|
||||
function mod10(input) {
|
||||
const trimmedInput = input.replace(/ /g, "");
|
||||
const table = [0, 9, 4, 6, 8, 2, 7, 1, 3, 5];
|
||||
let carry = 0;
|
||||
for (let i = 0; i < trimmedInput.length; i++) {
|
||||
carry = table[(carry + parseInt(trimmedInput.substring(i, i + 1), 10)) % 10];
|
||||
}
|
||||
return ((10 - carry) % 10).toString();
|
||||
}
|
||||
exports.calculateQRReferenceChecksum = calculateQRReferenceChecksum;
|
||||
exports.calculateSCORReferenceChecksum = calculateSCORReferenceChecksum;
|
||||
exports.formatAmount = formatAmount;
|
||||
exports.formatIBAN = formatIBAN;
|
||||
exports.formatQRReference = formatQRReference;
|
||||
exports.formatReference = formatReference;
|
||||
exports.formatSCORReference = formatSCORReference;
|
||||
exports.getReferenceType = getReferenceType;
|
||||
exports.isIBANValid = isIBANValid;
|
||||
exports.isQRIBAN = isQRIBAN;
|
||||
exports.isQRReference = isQRReference;
|
||||
exports.isQRReferenceValid = isQRReferenceValid;
|
||||
exports.isSCORReference = isSCORReference;
|
||||
exports.isSCORReferenceValid = isSCORReferenceValid;
|
||||
exports.mm2pt = mm2pt;
|
||||
exports.mm2px = mm2px;
|
||||
exports.pt2mm = pt2mm;
|
||||
exports.px2mm = px2mm;
|
||||
128
node_modules/swissqrbill/lib/cjs/shared/utils.d.ts
generated
vendored
Normal file
128
node_modules/swissqrbill/lib/cjs/shared/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Checks whether the given iban is a QR-IBAN or not.
|
||||
*
|
||||
* @param iban The IBAN to be checked.
|
||||
* @returns `true` if the given IBAN is a QR-IBAN and `false` otherwise.
|
||||
*/
|
||||
export declare function isQRIBAN(iban: string): boolean;
|
||||
/**
|
||||
* Validates the given IBAN.
|
||||
*
|
||||
* @param iban The IBAN to be checked.
|
||||
* @returns `true` if the checksum of the given IBAN is valid and `false` otherwise.
|
||||
*/
|
||||
export declare function isIBANValid(iban: string): boolean;
|
||||
/**
|
||||
* Formats the given IBAN according the specifications to be easily readable.
|
||||
*
|
||||
* @param iban The IBAN to be formatted.
|
||||
* @returns The formatted IBAN.
|
||||
*/
|
||||
export declare function formatIBAN(iban: string): string;
|
||||
/**
|
||||
* Checks whether the given reference is a QR-Reference or not.
|
||||
*
|
||||
* @param reference The Reference to be checked.
|
||||
* @returns `true` if the given reference is a QR-Reference and `false` otherwise.
|
||||
* @remarks The QR-Reference is a 27 digits long string containing only digits. The last digit is the checksum.
|
||||
*/
|
||||
export declare function isQRReference(reference: string): boolean;
|
||||
/**
|
||||
* Validates the given QR-Reference.
|
||||
*
|
||||
* @param reference The reference to be checked.
|
||||
* @returns `true` if the given reference is valid and `false` otherwise.
|
||||
*/
|
||||
export declare function isQRReferenceValid(reference: string): boolean;
|
||||
/**
|
||||
* Checks whether the given reference is a SCOR-Reference or not.
|
||||
*
|
||||
* @param reference The Reference to be checked.
|
||||
* @returns `true` if the given reference is a SCOR-Reference and `false` otherwise.
|
||||
* @remarks The SCOR-Reference is an alphanumeric string beginning with 'RF' and containing a 2 digit checksum and a max 21 digits long reference.
|
||||
*/
|
||||
export declare function isSCORReference(reference: string): boolean;
|
||||
/**
|
||||
* Validates the given SCOR-Reference.
|
||||
*
|
||||
* @param reference The reference to be checked.
|
||||
* @returns `true` if the given reference is valid and `false` otherwise.
|
||||
*/
|
||||
export declare function isSCORReferenceValid(reference: string): boolean;
|
||||
/**
|
||||
* Calculates the checksum according to the ISO 11649 standard.
|
||||
*
|
||||
* @param reference The max 21 digits long reference (without the "RF" and the 2 digit checksum) whose checksum should be calculated.
|
||||
* @returns The calculated checksum as 2 digit string.
|
||||
*/
|
||||
export declare function calculateSCORReferenceChecksum(reference: string): string;
|
||||
/**
|
||||
* Calculates the checksum according the specifications.
|
||||
*
|
||||
* @param reference The 26 digits long reference (without the checksum) whose checksum should be calculated.
|
||||
* @returns The calculated checksum.
|
||||
*/
|
||||
export declare function calculateQRReferenceChecksum(reference: string): string;
|
||||
/**
|
||||
* Formats the given QR-Reference according the specifications to be easily readable.
|
||||
*
|
||||
* @param reference The QR-Reference to be formatted.
|
||||
* @returns The formatted QR-Reference.
|
||||
*/
|
||||
export declare function formatQRReference(reference: string): string;
|
||||
/**
|
||||
* Formats the given SCOR-Reference according the specifications to be easily readable.
|
||||
*
|
||||
* @param reference The SCOR-Reference to be formatted.
|
||||
* @returns The formatted SCOR-Reference.
|
||||
*/
|
||||
export declare function formatSCORReference(reference: string): string;
|
||||
/**
|
||||
* Detects the type of the given reference and formats it according the specifications to be easily readable.
|
||||
*
|
||||
* @param reference The reference to be formatted.
|
||||
* @returns The formatted reference.
|
||||
*/
|
||||
export declare function formatReference(reference: string): string;
|
||||
/**
|
||||
* Formats the given amount according the specifications to be easily readable.
|
||||
*
|
||||
* @param amount Containing the amount to be formatted.
|
||||
* @returns The formatted amount.
|
||||
*/
|
||||
export declare function formatAmount(amount: number): string;
|
||||
/**
|
||||
* Converts millimeters to points.
|
||||
*
|
||||
* @param millimeters The millimeters you want to convert to points.
|
||||
* @returns The converted millimeters in points.
|
||||
*/
|
||||
export declare function mm2pt(millimeters: number): number;
|
||||
/**
|
||||
* Converts points to millimeters.
|
||||
*
|
||||
* @param points The points you want to convert to millimeters.
|
||||
* @returns The converted points in millimeters.
|
||||
*/
|
||||
export declare function pt2mm(points: number): number;
|
||||
/**
|
||||
* Converts millimeters to pixels.
|
||||
*
|
||||
* @param millimeters The millimeters you want to convert to pixels.
|
||||
* @returns The converted millimeters in pixels.
|
||||
*/
|
||||
export declare function mm2px(millimeters: number): number;
|
||||
/**
|
||||
* Converts pixels to millimeters.
|
||||
*
|
||||
* @param pixels Containing the pixels you want to convert to millimeters.
|
||||
* @returns The converted pixels in millimeters.
|
||||
*/
|
||||
export declare function px2mm(pixels: number): number;
|
||||
/**
|
||||
* Detects the type of the given reference.
|
||||
*
|
||||
* @param reference The reference to get the type of.
|
||||
* @returns The type of the given reference.
|
||||
*/
|
||||
export declare function getReferenceType(reference: string | undefined): "NON" | "QRR" | "SCOR";
|
||||
216
node_modules/swissqrbill/lib/cjs/shared/validator.cjs
generated
vendored
Normal file
216
node_modules/swissqrbill/lib/cjs/shared/validator.cjs
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const errors = require("./errors.cjs");
|
||||
const utils = require("./utils.cjs");
|
||||
function validateData(data) {
|
||||
if (data.reference !== void 0) {
|
||||
if (typeof data.reference !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.REFERENCE_TYPE_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.message !== void 0) {
|
||||
if (typeof data.message !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.MESSAGE_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.message.length > 140) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.MESSAGE_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.additionalInformation !== void 0) {
|
||||
if (typeof data.additionalInformation !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ADDITIONAL_INFORMATION_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.additionalInformation.length > 140) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ADDITIONAL_INFORMATION_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.message !== void 0 && data.additionalInformation !== void 0) {
|
||||
if (data.additionalInformation.length + data.message.length > 140) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.MESSAGE_AND_ADDITIONAL_INFORMATION_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.av1 !== void 0) {
|
||||
if (typeof data.av1 !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ALTERNATIVE_SCHEME_TYPE_IS_INVALID, { scheme: "AV1" });
|
||||
}
|
||||
if (data.av1.length > 100) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ALTERNATIVE_SCHEME_LENGTH_IS_INVALID, { scheme: "AV1" });
|
||||
}
|
||||
}
|
||||
if (data.av2 !== void 0) {
|
||||
if (typeof data.av2 !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ALTERNATIVE_SCHEME_TYPE_IS_INVALID, { scheme: "AV2" });
|
||||
}
|
||||
if (data.av2.length > 100) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ALTERNATIVE_SCHEME_LENGTH_IS_INVALID, { scheme: "AV2" });
|
||||
}
|
||||
}
|
||||
if (data.creditor === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_IS_UNDEFINED);
|
||||
}
|
||||
if (data.creditor.account === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ACCOUNT_IS_UNDEFINED);
|
||||
}
|
||||
if (!data.creditor.account.startsWith("CH") && !data.creditor.account.startsWith("LI")) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ACCOUNT_COUNTRY_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.account.length !== 21) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ACCOUNT_LENGTH_IS_INVALID, { iban: data.creditor.account });
|
||||
}
|
||||
if (data.creditor.name === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_NAME_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.creditor.name !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_NAME_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.name.length > 70) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_NAME_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.address === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ADDRESS_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.creditor.address !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ADDRESS_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.address.length > 70) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ADDRESS_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.buildingNumber !== void 0) {
|
||||
if (typeof data.creditor.buildingNumber !== "string" && typeof data.creditor.buildingNumber !== "number") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_BUILDING_NUMBER_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.buildingNumber.toString().length > 16) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_BUILDING_NUMBER_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.creditor.zip === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ZIP_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.creditor.zip !== "string" && typeof data.creditor.zip !== "number") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ZIP_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.zip.toString().length > 16) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ZIP_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.city === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_CITY_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.creditor.city !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_CITY_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.city.length > 35) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_CITY_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.country === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_COUNTRY_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.creditor.country !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_COUNTRY_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.creditor.country.length !== 2) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_COUNTRY_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.amount !== void 0) {
|
||||
if (typeof data.amount !== "number") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.AMOUNT_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.amount.toFixed(2).toString().length > 12) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.AMOUNT_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.currency === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CURRENCY_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.currency !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CURRENCY_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.currency.length !== 3) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CURRENCY_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.currency !== "CHF" && data.currency !== "EUR") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CURRENCY_STRING_IS_INVALID);
|
||||
}
|
||||
if (data.debtor !== void 0) {
|
||||
if (data.debtor.name === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_NAME_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.debtor.name !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_NAME_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.name.length > 70) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_NAME_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.address === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_ADDRESS_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.debtor.address !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_ADDRESS_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.address.length > 70) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_ADDRESS_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.buildingNumber !== void 0) {
|
||||
if (typeof data.debtor.buildingNumber !== "string" && typeof data.debtor.buildingNumber !== "number") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_BUILDING_NUMBER_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.buildingNumber.toString().length > 16) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_BUILDING_NUMBER_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (data.debtor.zip === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_ZIP_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.debtor.zip !== "string" && typeof data.debtor.zip !== "number") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_ZIP_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.zip.toString().length > 16) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_ZIP_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.city === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_CITY_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.debtor.city !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_CITY_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.city.length > 35) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_CITY_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.country === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_COUNTRY_IS_UNDEFINED);
|
||||
}
|
||||
if (typeof data.debtor.country !== "string") {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_COUNTRY_TYPE_IS_INVALID);
|
||||
}
|
||||
if (data.debtor.country.length !== 2) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.DEBTOR_COUNTRY_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
if (utils.isIBANValid(data.creditor.account) === false) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.CREDITOR_ACCOUNT_IS_INVALID, { iban: data.creditor.account });
|
||||
}
|
||||
if (utils.isQRIBAN(data.creditor.account)) {
|
||||
if (data.reference === void 0) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_MISSING);
|
||||
}
|
||||
if (data.reference.length !== 27) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.QR_REFERENCE_LENGTH_IS_INVALID);
|
||||
}
|
||||
if (utils.isQRReference(data.reference)) {
|
||||
if (!utils.isQRReferenceValid(data.reference)) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.QR_REFERENCE_IS_INVALID, { reference: data.reference });
|
||||
}
|
||||
} else {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ACCOUNT_IS_QR_IBAN_BUT_REFERENCE_IS_REGULAR);
|
||||
}
|
||||
} else {
|
||||
if (data.reference !== void 0) {
|
||||
if (utils.isQRReference(data.reference)) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.ACCOUNT_IS_REGULAR_IBAN_BUT_REFERENCE_IS_QR);
|
||||
}
|
||||
if (data.reference.length > 25) {
|
||||
throw new errors.ValidationError(errors.ValidationErrors.REGULAR_REFERENCE_LENGTH_IS_INVALID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.validateData = validateData;
|
||||
8
node_modules/swissqrbill/lib/cjs/shared/validator.d.ts
generated
vendored
Normal file
8
node_modules/swissqrbill/lib/cjs/shared/validator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Data } from './types.js';
|
||||
/**
|
||||
* Validate the provided data.
|
||||
*
|
||||
* @param data The data to validate.
|
||||
* @throws { ValidationError } If the data is invalid.
|
||||
*/
|
||||
export declare function validateData(data: Data): void;
|
||||
Reference in New Issue
Block a user