valtype::gs1::ean13(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– valtype::gs1::ean13 πŸ’–

okay bestie, so you know the valtype::gs1::ean13 manual page? that's the one. this is her. she lives in 3tcl land and she is Validation types coded. pull up a chair, we're doing barcode validation and it's lowkey iconic πŸŽ€


✨ NAME ✨

valtype::gs1::ean13 β€” validation for EAN13, no cap πŸ’…


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require snit 2

package require valtype::common

package require valtype::gs1::ean13 ?1.1?

valtype::gs1::ean13 validate value

valtype::gs1::ean13 checkdigit value

like, that's the whole vibe right there. ?1.1? means the version is optional btw, she's flexible πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

so this package implements a snit validation type for an EAN13. that's it, that's the girl 🫢

now, a validation type is just an object you use to validate Tcl values of one specific kind. for example, snit::integer β€” which is a validation type that the snit package defines β€” gets used to check that some Tcl value is actually an integer. same energy, different flavour.

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

  • it must take a single argument, which is the value being validated
  • it must do absolutely nothing if the value is valid
  • but it must throw an error if the value is invalid

watch:

valtype::gs1::ean13 validate .... ;# Does nothing
valtype::gs1::ean13 validate .... ;# Throws an error (bad EAN13).

see how that works? one of those is chill, one of those is a whole meltdown 😭

on success, validate will always return the validated value. on failure it throws with -errorcode INVALID, and sometimes there's extra stuff tacked on giving you more detail about what went wrong. it's giving helpful, honestly.


πŸŽ€ API πŸŽ€

the API this package hands you fully satisfies the spec for snit validation types, the one written up in the documentation of Snit's Not Incr Tcl. so if you've read that, you already know the shape of things. iykyk.

  • valtype::gs1::ean13 validate value β€” validates the value and returns it if it passes, possibly in a canonical form. if the value flops the validation, an error gets thrown. simple as πŸ“
  • valtype::gs1::ean13 checkdigit value β€” computes a check digit for the value. before it does any of that, it validates the value β€” except for the checkdigit itself, obviously, because how are you gonna validate a digit you haven't calculated yet πŸ’€. if the value doesn't pass, no check digit gets calculated and an error is thrown instead. periodt.

πŸ”₯ ERROR CODES πŸ”₯

like the package description said, the errors these commands throw when input validation fails use -errorcode INVALID so they can tell themselves apart from the package's own internal errors. main character boundaries, honestly πŸ‘‘

but to give you the why of the failure, the -errorCode actually goes further than that. first it carries a code naming the type itself β€” here that's EAN13 β€” and then it's followed by values describing the reason for the failure. the complete set of -errorCodes this package can throw is:

  • INVALID EAN13 CHARACTER β€” the input value had one or more bad characters, meaning characters that must not occur in the input for it to be an EAN13. like, girl, what is that letter doing there πŸ™ˆ
  • INVALID EAN13 CHECK-DIGIT β€” the check digit of the input value is wrong. this usually signals a data-entry error, with digits transposed, forgotten, etc. and of course, the input might just be an outright fake too. caught in 4k πŸ”
  • INVALID EAN13 LENGTH β€” the input value is the wrong length to be an EAN13. too short, too long, not the moment πŸ’…

😭 BUGS, IDEAS, FEEDBACK 😭

ngl, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving humble. please report them in the category valtype of the Tcllib Trackers:

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 glow up ✨

when you're proposing code changes, please provide unified diffs, i.e. the output of diff -u. that's the love language.

also note: attachments are strongly preferred over inlined patches. to attach something, go to the Edit form of the ticket immediately after you create it, then use the left-most button in the secondary navigation bar. that's the one, bestie 🫢


⭐ KEYWORDS ⭐

Checking, EAN, EAN13, European Article Number, International Article 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, dated back in the day, and she's filed under valtype::gs1::ean13(3tcl). go validate something iconic πŸ¦‹βœ¨

πŸ“¦ where this page comes from