valtype::verhoeff(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– valtype::verhoeff β€” bestie, it's a validation type era πŸ’–

This is the manual page for valtype::verhoeff(n) from the Validation types family, and yes we're gonna read the whole thing together, no skipping, it's not that kind of party. πŸŽ€


✨ NAME ✨

valtype::verhoeff β€” validation for a plain number that's rockin' a VERHOEFF checkdigit πŸ’…


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require snit 2

package require valtype::common

package require valtype::verhoeff ?1.1?

valtype::verhoeff validate value

valtype::verhoeff checkdigit value

(the ?1.1? means that version is optional, she's flexible like that πŸ¦‹)


πŸ’œ DESCRIPTION πŸ’œ

Okay so, this package implements a snit validation type for a plain number with a VERHOEFF checkdigit. Slay.

A validation type is basically an object you can use to validate Tcl values of a particular kind. Like, for example, snit::integer is a validation type defined by the snit package, and it's used to validate that a Tcl value is an integer. She checks IDs, essentially. πŸ’…

Every single validation type has a validate method that does the validating. This method must take a single argument β€” the value to be validated. And further, bestie, it must do nothing if the value is valid, but throw an error if the value is invalid:

valtype::verhoeff validate .... ;# Does nothing
valtype::verhoeff validate .... ;# Throws an error (bad verhoeff checkdigit).

The validate method will always return the validated value on success, and it'll throw the -errorcode INVALID on error β€” possibly with extra elements that spill more tea about what exactly went wrong. 😭


πŸ”₯ API πŸ”₯

The API this package serves up satisfies the spec of snit validation types found in the documentation of Snit's Not Incr Tcl. Periodt.

  • valtype::verhoeff validate value β€” This method validates the value and returns it, possibly in a canonical form, if it passes. If the value does not pass the validation, an error gets thrown. No in-between, no "almost valid", she doesn't do participation trophies. πŸ’€
  • valtype::verhoeff checkdigit value β€” This method computes a check digit for the value. Before it does any of that, the value gets validated β€” except for a checkdigit. If the value doesn't pass validation, no check digit is calculated and an error is thrown instead. So like, fix the input first, then we'll talk. πŸ™ˆ

⭐ ERROR CODES ⭐

Like the package description already said, the errors thrown by the commands of this package in response to input validation failures use the -errorcode INVALID to distinguish themselves from package internal errors. Iconic of them honestly. πŸ‘‘

But to give you more detailed info about why the validation flopped, the -errorCode actually goes beyond that. First, it'll contain a code detailing the type itself. Here, that's VERHOEFF. Then it's followed by values detailing the reason for the failure. The full set of -errorCodes this package can throw are:

  • INVALID VERHOEFF CHARACTER β€” The input value contained one or more bad characters, i.e. characters which must not occur in the input for it to be a plain number with a VERHOEFF checkdigit. Rude little characters, not invited to the function. 😭
  • INVALID VERHOEFF CHECK-DIGIT β€” The check digit of the input value is wrong. This usually signals a data-entry error, with digits transposed, forgotten, etc. Of course, the input may be an outright fake too. πŸ’€ Not naming names but... some values are lying.

πŸ¦‹ BUGS, IDEAS, FEEDBACK πŸ¦‹

This document, and the package it describes, will undoubtedly contain bugs and other problems. (not me being self-aware, we love growth 🌱) Please report such in the category valtype of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation. We're listening, fr fr. 🫢

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. That's the vibe check right there. ✨


🌈 KEYWORDS 🌈

Checking, Testing, Type checking, Validation, Value checking, isA, verhoeff


πŸŽ€ CATEGORY πŸŽ€

Validation, Type checking


Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>


And that's the whole page bestie, you ate it. πŸ’… This was tcllib version 1.1 of valtype::verhoeff(n) β€” go forth and validate, main character. 🌟 πŸ¦‹πŸ’œπŸ“

πŸ“¦ where this page comes from