identifiers

package
v0.0.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 3 Imported by: 0

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

func CandidateForms(value string) []string

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

func Key(identifierType, value string) string

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

func NormalizeISBN(value string) string

NormalizeISBN removes hyphens, spaces, and common prefixes from an ISBN.

func NormalizeValue added in v0.0.30

func NormalizeValue(identifierType, value string) string

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

func ValidateISBN10(isbn string) bool

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

func ValidateISBN13(isbn string) bool

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.

const (
	TypeISBN10    Type = "isbn_10"
	TypeISBN13    Type = "isbn_13"
	TypeASIN      Type = "asin"
	TypeUUID      Type = "uuid"
	TypeGoodreads Type = "goodreads"
	TypeGoogle    Type = "google"
	TypeOther     Type = "other"
	TypeUnknown   Type = ""
)

func DetectType

func DetectType(value, scheme string) Type

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL