Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
ocrgenerator
Advanced tools
Swedish invoice number generator based on modulus 10.
Swedish banks can take an invoice number that is validated against four algorithms, all based on modulus 10 or Luhn. The purpose of this project is to generate such invoice numbers from almost any given string.
Functions:
generate(from[, options])
: generate invoice number with length control and checksum digitssoft(from)
: same as generate without optionshard(from)
: same as generate without optionsfixed(from, fixedLength)
: generate with fixed length, padded with preceeding zeros if too short and capped from left if too longcalculateChecksumReversed(ocr[, options])
: calculate checksum from rightvalidate(ocr[, options])
: validate ocr according to modulus 10validateHard(ocr)
: validate against hard algorithm, invalid control digit is unacceptablevalidateSoft(ocr)
: same as validateHard, invalid control digit is unacceptable, i.e. a falsy result is acceptedvalidateVariableLength(ocr)
: controls checksum and length controlvalidateFixedLength(ocr, length1[, length2])
: validate fixed length, takes ocr and one length, and one optional length, either must matchProperties:
MIN_LENGTH
: 2MAX_LENGTH
: 25The above tresholds - MIN_LENGTH
and MAX_LENGTH
- is the expected invoice number length range for bankgirot, for plusgirot it is 5 and 15.
Generate invoice number with length control and checksum.
Arguments:
from
: any given string, e.g. customer number + date + amountoptions
: optional options
minLength
: defaults to MIN_LENGTH
maxLength
: defaults to MAX_LENGTH
Returns:
numbers
: the actual generated invoice numberlengthControl
: length control digitcontrol
: control digitlength
: lengthsum
: checksumerror_code
: occasional error
ERR_OCR_OUT_OF_RANGE
: OCR reference length was out of range, i.e. < minLength
or > maxLength
message
: occasional error messageExample:
import { generate } from 'ocrgenerator';
const invoiceNo = generate('Customer007:Date2019-12-24:Amount$200');
console.log(invoiceNo); // {numbers: '0072019122420063'}
Modulus 10 reversed:
Customer007:Date2019-12-24:Amount$200
007 2019 12 24 200 l = 16 % 10 = 6
* 212 1212 12 12 121 2
----------------------------------------------
001 2011 14 28 200 1
+ 004 0008 00 00 000 2
----------------------------------------------
sum 005 2009 14 28 200 3 = 37
The length is the expected total number of digits in the invoice number, i.e. add one for length control and one for control digit.
total invoice number length: n = 14 + 1 + 1 = 16
length control: l = n % 10 = 6
Since the algoritm is in reversed, the length control is at first position - index 0, so times 2:
reference control digit: c = 10 - sum % 10 = 10 - 37 % 10 = 10 - 7 = 3
Invoice number: '00720191224200' + l + c = '0072019122420063'
Validate ocr according to modulus 10 and return object describing what went wrong if invalid.
Arguments:
ocr
: invoice numberoptions
: optional options
minLength
: defaults to MIN_LENGTH
maxLength
: defaults to MAX_LENGTH
Returns:
valid
: boolean indicating that the modulus 10 check was successfullsum
: checksumcontrol
: expected control digiterror_code
: occasional error
ERR_OCR_INVALID_CHAR
: a character has sneeked into ocrERR_OCR_OUT_OF_RANGE
: OCR reference was out of range, i.e. < 2 or > 25message
: occasional error messageExample:
import { validate } from 'ocrgenerator';
console.log(validate('0072019122420063')); // true
console.log(validate('0072019122420063' + '7')); // false
console.log(validate('0072019122420063' + 'A')); // sneaky character
console.log(validate('0072019122420063', { maxLength: 15 }));
Validate your invoice number at bankgirot
[1.0.8] - 2024-05-19
FAQs
Swedish invoice no generator
The npm package ocrgenerator receives a total of 198 weekly downloads. As such, ocrgenerator popularity was classified as not popular.
We found that ocrgenerator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.