+
Skip to content
/ issn Public

[Push Mirror] A standalone package for ISO 3297:2022 (AKA ISSN) parsing, validating, and formatting

License

Notifications You must be signed in to change notification settings

alg-js/issn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@alg/issn

Repository License JSR

A standalone package for ISO 3297:2022 (AKA ISSN) parsing, validating, and formatting.

Install

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

Example

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 reason
  • ISSN.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

About

[Push Mirror] A standalone package for ISO 3297:2022 (AKA ISSN) parsing, validating, and formatting

Topics

Resources

License

Stars

Watchers

Forks

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载