🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

esr-code-line

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esr-code-line - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+1
-1
package.json
{
"name": "esr-code-line",
"version": "1.0.0",
"version": "1.0.1",
"description": "A code line generator for orange payment slips used in Switzerland",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -10,5 +10,8 @@ import {

test("Pads prices in CHF to the left with zeros.", () => {
const codeRequiresPadding = pad("1", 8);
expect(codeRequiresPadding).toBe("00000001");
const codeRequiresPaddingEightDigits = pad("1", 8);
expect(codeRequiresPaddingEightDigits).toBe("00000001");
const requiresPaddingToTwoDigits = pad("5", 2);
expect(requiresPaddingToTwoDigits).toBe("05");
const codeExactRequiredLength = pad("12345678", 8);

@@ -77,1 +80,21 @@ expect(codeExactRequiredLength).toBe("12345678");

});
test("Doesn't include price if zero or empty", () => {
const priceZero = codeLine({
slipType: "04",
amountFrancsOrEuros: "0",
amountRappenOrCents: "0",
referenceNumber: "12 34567 89012 34567 89012 34567",
customerNumber: "01-162-8",
});
expect(priceZero).toBe("042>123456789012345678901234567+ 010001628>");
const priceEmpty = codeLine({
slipType: "04",
amountFrancsOrEuros: "",
amountRappenOrCents: "",
referenceNumber: "12 34567 89012 34567 89012 34567",
customerNumber: "01-162-8",
});
expect(priceEmpty).toBe("042>123456789012345678901234567+ 010001628>");
});

@@ -51,6 +51,14 @@ const CHECK_DIGIT_TABLE = [0, 9, 4, 6, 8, 2, 7, 1, 3, 5];

export function codeLine(req: SlipRequirements): string {
const paddedAmountFrancsOrEuros = pad(req.amountFrancsOrEuros.toString(), 8);
const paddedAmountFrancsOrEuros =
parseInt(req.amountFrancsOrEuros) > 0
? pad(req.amountFrancsOrEuros, 8)
: "";
const paddedRappenOrCents =
parseInt(req.amountRappenOrCents) > 0
? pad(req.amountRappenOrCents, 2)
: "";
const checkDigit1 = checkDigit(
req.slipType + paddedAmountFrancsOrEuros + req.amountRappenOrCents
req.slipType + paddedAmountFrancsOrEuros + paddedRappenOrCents
);

@@ -65,3 +73,3 @@

paddedAmountFrancsOrEuros +
req.amountRappenOrCents +
paddedRappenOrCents +
checkDigit1 +

@@ -68,0 +76,0 @@ AUXILIARY_CHARACTER_1 +