valtype::isbn(n)

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

πŸ’– valtype::isbn β€” the manual page, bestie edition πŸ’–

okay so this is the manual page for valtype::isbn, which lives in section n of the manual (the Tcl command section, iykyk). it's all about checking whether a string is a real ISBN or just vibes. let's get into it πŸ¦‹


✨ NAME ✨

valtype::isbn β€” validation for ISBN πŸ’…


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require snit 2

package require valtype::common

package require valtype::isbn ?1.1?

valtype::isbn validate value

valtype::isbn checkdigit value

valtype::isbn 13of value

πŸŽ€ DESCRIPTION πŸŽ€

so this package ships a snit validation type for an ISBN. that's the whole job. she's focused. she's employed. periodt.

now, a validation type is basically an object you can point at Tcl values of some particular kind and be like "is this one of those?" fr fr. for example, snit::integer β€” a validation type that the snit package defines β€” exists so you can check that a Tcl value is an integer.

every validation type has a validate method, and that's the one doing the actual checking. the rules are:

  • it takes a single argument: the value being validated
  • if the value is valid, it does nothing
  • if the value is invalid, it throws an error

like so:

valtype::isbn validate .... ;# Does nothing
valtype::isbn validate .... ;# Throws an error (bad ISBN).

and here's the glow-up detail: validate always returns the validated value when it succeeds 🫢, and when it fails it throws with -errorcode INVALID, possibly with extra elements riding along that give you more deets about what went wrong. not me being thorough πŸ’…


πŸ‘‘ API πŸ‘‘

the API this package gives you satisfies the spec for snit validation types, which lives in the docs for Snit's Not Incr Tcl. no cap.

  • valtype::isbn validate value β€” validates the value and hands it back, possibly in a canonical form, if it passes. if it does not pass, an error gets thrown. simple as.
  • valtype::isbn checkdigit value β€” computes a check digit for value. before it does any of that, it validates the value β€” except for the checkdigit itself, she's skipping that part. and if the value fails validation? no check digit for you, an error instead. πŸ™ˆ
  • valtype::isbn 13of value β€” expects an old-style 10-digit ISBN and returns the canonical modern 13-digit ISBN. validate uses this to canonicalize the input, so that every other part of the system downstream can just assume it's working with modern 13-digit ISBNs. it's giving ✨glow-up transformation✨ honestly.

πŸ’€ ERROR CODES πŸ’€

like the package description said: when these commands hit an input validation failure, the error they throw uses -errorcode INVALID to set itself apart from the package's own internal errors.

but wait, there's more β€” to give you richer info about why validation flopped, the -errorCode actually goes beyond just that. first it carries a code detailing the type itself. here, that's ISBN. then it's followed by values detailing the reason for the failure. the full set of -errorCodes this package can throw is:

  • INVALID ISBN CHARACTER β€” the input had one or more bad characters, i.e. characters that literally must not show up in the input for it to be an ISBN. not allowed, bestie.
  • INVALID ISBN CHECK-DIGIT β€” the check digit of the input is wrong. this usually means a data-entry oopsie β€” digits transposed, forgotten, that whole situation. of course, the input could just be an outright fake too. πŸ’€
  • INVALID ISBN LENGTH β€” the input is the wrong length to be an ISBN. she's just not the right size for this.

πŸ› BUGS, IDEAS, FEEDBACK πŸ›

this document, and the package it describes, will undoubtedly contain bugs and other problems. it's a manual page, they all do. please report such things in the category valtype of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you have for either the package and/or the documentation β€” we want the thoughts 🫢

if you're proposing code changes, please provide unified diffs, i.e. the output of diff -u.

also note: attachments are strongly preferred over inlined patches. you can attach stuff by going to the Edit form of the ticket immediately after creating it, then using the left-most button in the secondary navigation bar. that's the one. πŸ’…


⭐ KEYWORDS ⭐

Book Number, Checking, EAN, EAN13, European Article Number, ISBN, International Article Number, International Standard Book Number, Testing, Type checking, Validation, Value checking, isA


🌈 CATEGORY 🌈

Validation, Type checking


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


and that's the whole page, bestie πŸŽ€ this was tcllib version 1.1 of valtype::isbn(n), brought to you with love. go validate something. slay πŸ’…βœ¨

πŸ“¦ where this page comes from