Documentation
¶
Overview ¶
pkg/identifiers/identifiers.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CandidateForms ¶ added in v0.0.30
CandidateForms returns all plausible canonical forms of a user-provided identifier value for lookup purposes. Because the type is not known at query time (a user may search by ISBN, ASIN, or UUID without specifying which), this enumerates the normalized variants across the supported types so a single query can match legacy rows stored in any format. The raw input is always included as the first element. Duplicates are removed. Returns nil for an empty or whitespace-only input.
Each candidate form is only added if the input plausibly represents that type. This prevents false positives like `"ref-9780316769488-v2"` — a vendor id whose digits happen to contain a valid ISBN substring — from matching real ISBN rows. Specifically:
- ISBN candidate is added only if the raw input consists exclusively of digits/hyphens/spaces (with optional leading "ISBN"/"ISBN:") AND the normalized form passes an ISBN-10 or ISBN-13 checksum.
- Uppercased ASIN candidate is added only if the uppercased form matches the ASIN pattern.
- Lowercased UUID candidate (with `urn:uuid:` prefix stripped) is added only if the stripped form matches the UUID pattern.
func Key ¶ added in v0.0.30
Key returns a stable comparison key for an identifier, using the canonical form of the value. Two identifiers with semantically identical values but cosmetic differences (hyphens, prefixes, case) produce the same Key, so diff-based code (e.g. scan reconciliation) can tell when a set has actually changed without treating "978-0-316-76948-8" and "9780316769488" as distinct.
func NormalizeISBN ¶
NormalizeISBN removes hyphens, spaces, and common prefixes from an ISBN.
func NormalizeValue ¶ added in v0.0.30
NormalizeValue returns a canonical form of an identifier value for storage, based on its type. ISBN-10/13 values are stripped of hyphens/spaces/prefixes; ASINs are uppercased; UUIDs are lowercased with any urn:uuid: prefix removed; all other types are returned with surrounding whitespace trimmed.
func ValidateISBN10 ¶
ValidateISBN10 validates an ISBN-10 checksum. ISBN-10 uses modulo 11 with weights 10,9,8,7,6,5,4,3,2,1.
func ValidateISBN13 ¶
ValidateISBN13 validates an ISBN-13 checksum. ISBN-13 uses alternating weights of 1 and 3.
Types ¶
type Type ¶
type Type string
Type represents the type of identifier.
func DetectType ¶
DetectType determines the identifier type from a value and optional scheme. If the scheme is recognized, it takes precedence. Unknown or empty schemes fall through to value-based pattern matching so we still pick up identifiers emitted with vendor-specific scheme names (e.g. Calibre's "MOBI-ASIN", or arbitrary publisher tags) when the value itself is unambiguous.