npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kontonummer

v4.0.1

Published

A validator for swedish banking numbers

Downloads

6,310

Readme

Kontonummer

JavaScript Style Guide test release codecov

This is a reimagination of jop-io/kontonummer.js with some additional goals:

  • Provide a similar API to Personnummer
  • Stretch goal: Calculate IBAN (and BIC/SWIFT-code)
  • Stretch goal: Handle BankGirot and PlusGirot numbers

Some Code (c) Jonas Persson and Tobbe Lundberg which they have gracefully released under a MIT license. See LICENCE

This implementation is written in TypeScript but the following specification should be applicable to other languages as well. But some language specific modifications may be required.

Important Caveat

As explained in the research section below there are some bank account numbers that is impossible to validate (as they do not have a check digit) that are indistinguishable from validatable accounts. I recommend using this library on form input fields but do not prevent form submission if the account number is reported as invalid. A good idea would be something like a warning saying "there is a chance this is not a valid bank account number you may want to double check."

Specification [v1]

Class

The package should include a class that which should be the return value of parse

class Kontonummer {
  constructor (sortingCode: string | number, accountNumber: string | number, options?: InitOptions)
  constructor (sortingCodeAndAccountNumber: string | number, options?: InitOptions)
}
  • sortingCode (sv. clearing nummer) should be one of the following formats
    • SSSS
    • SSSS-C
  • accountNumber the allowed length varies, further explained in section Account Number White-space should be allowed in any position. Basically, only characters matches the regex /\d/ should be taken into consideration all other characters should be discarded.
  • sortingCodeAndAccountNumber should be one of the following formats (where S is sorting code, A is account number and C is a check digit. White-space should be allowed in any position. Basically, only characters matches the regex /\d/ should be taken into consideration all other characters should be discarded.
    • SSSS,AC
    • SSSSAC
    • S-C,AC
    • S-CAC
    • S-C,A-C
    • S-CA-C
    • etc.

InitOptions

  • mode: 'strict' | 'semi' | 'lax'
    • strict should validate sorting code, account number length and account number check digit. Should throw if any of these checks fail.
    • semi should do strict checks for type 1 account numbers (4+7) but lax checks for type 2 account numbers.
    • lax should not throw if the check digit of the account number cannot be validated. Should instead set the valid property to false if the check digit or length is invalid. Should still throw for invalid sorting codes.

Properties

The class should expose the following properties once initialised

class Kontonummer {
  readonly bankName: string
  readonly sortingCode: string
  readonly accountNumber: string
  readonly type: 1 | 2
  readonly comment: 1 | 2 | 3
  readonly valid: boolean // only relevant in `lax` mode
}

Errors

All methods except for validate should throw an exception or return an error as a second return value. Error handling may be different depending on language. The exception/error class should be prefixed with Kontonummer.

Parse

The class should include a static parse method that creates a new instance of the class. It should take the same arguments as the class constructor. This function should also be an exported standalone method of the package.

Pseudocode:

class Kontonummer {
  static parse (...args) {
    return new Kontonummer(...args)
  }
}

export const parse = Kontonummer.parse

Validate

The class should include a static validate method that attempts to parse the provided input and returns a boolean that indicates if it succeeded. validate should not accept any options. This function should also be an exported standalone method of the package.

Pseudocode:

class Kontonummer {
  validate (sortingCode, accountNumber)
  validate (sortingCodeAndAccountNumber) {
    try {
      new Kontonummer(sortingCode, accountNumber)
      return true
    } catch {
      return false
    }
  }
}

export const validate = Kontonummer.validate

Format

Format key:

  • S: Sorting Code
  • A: Account number
  • C: Check digit
  • K: IBAN check digit
  • B: IBAN bank code

The class should include a public format method that returns the sortingCode and accountNumber in one string. Some different formats should be available. If no argument is provided it should default to numeric.

type Format = 'numeric' | 'pretty'
type Part = 'full' | 'sortingCode' | 'accountNumber'

class Kontonummer {
  format (format?: Format = 'numeric', part?: Part = 'full'): string
}

| Name | Format | | ---- | ---- | | numeric(default) | S[C]ACwhere the account number is padded to the appropriate max length depending on account type | | pretty | Depends on type and bank, see research below |

[] brackets marks optional

Research

Moved to swantzter.se where I plan to publish research on other topics as well