A standalone package for ISO 3297:2022 (AKA ISSN) parsing, validating, and formatting.
deno add jsr:@alg/issn
Other Install Options
npx jsr add @alg/issn
bunx jsr add @alg/issn
pnpm i jsr:@alg/issn
yarn add jsr:@alg/issn
vlt install jsr:@alg/issn
The default endpoint of this library (@alg/issn
) default exports an ISSN
class that validates, parses, and formats strings according to the latest ISO
3279 standard. Specific versions of the standard can be accessed in their
respective exports: @alg/isbn/2022
. Each of these modules default exports an
ISSN class that adheres to that particular standard. The interfaces for these
classes are the same.
When parsing ISSN values, the format and check digit is validated. Below are some examples of ISBNs being parsed:
import ISSN from "@alg/issn";
const delayed = ISSN.parseOrThrow("ISSN 2046-1933");
console.log(delayed.digits()); // 20461933
console.log(delayed.toString()); // ISSN 2046-1933
const skeptic = ISSN.parseOrThrow("01946730");
console.log(skeptic.digits()); // 01946730
console.log(skeptic.toString()); // ISSN 0194-6730
Three static constructor methods for parsing ISBNs are available:
ISSN.parseOrThrow
: Throws if an ISSN is not valid with a reasonISSN.parseResult
: Returns an object indicating whether the parsing was successful of the form{result: ISSN}|{err: reason}
ISSN.parseOrUndefined
: Returns an ISSN or undefined if the given string is not a valid ISSN
For example:
import ISSN from "@alg/issn";
try {
ISSN.parseOrThrow("ISSN 2046-1934");
} catch (e) {
console.log(e.toString()); // Error: Invalid ISSN Check Digit
}
console.log(ISSN.parseResult("12046-19")); // { err: "Invalid ISSN format" }
console.log(ISSN.parseOrUndefined("ISSN 2046-1934")); // undefined
The reasons for failure are:
- Invalid ISSN format
- Invalid ISSN Check Digit
To simply validate strings without parsing them, the ISSN.isValid
static
method will return true
if the given string is a valid ISSN and false
otherwise:
import ISSN from "@alg/issn";
console.log(ISSN.isValid("ISSN 2046-1933")); // true
console.log(ISSN.isValid("ISSN 2046-1934")); // false