Jump to content

User:PerfektesChaos/js/isbnLib

From Wikipedia, the free encyclopedia

JavaScript function library of utilities to analyze and format ISBN.

Libraries of WikiSyntaxTextMod (WSTM) are shared and made available internally.

Installation

[edit]

Gadget programmers need to wait for correct installation of this script before any function can be used. This requires two steps, loading and executing.

if ( ! mw.loader.getState( "ext.gadget.isbnLib" ) ) {
   mw.loader.state( { "ext.gadget.isbnLib": "loading" } );
   mw.loader.load( "https://wiki.riteme.site/w/index.php?"
                   + "title=User:PerfektesChaos/js/"
                   + "isbnLib/r.js"
                   + "&bcache=1&maxage=604800"
                   + "&action=raw&ctype=text/javascript" );
}
mw.hook( "isbnLib.ready" ).add( mainTask );

Loading again would not be meaningful if already done. Therefore the state of this script is checked first. Another gadget which also uses this script library might have loaded already.

When loading of all components has been completed, the isbnLib.ready hook will be fired.

Here is mainTask a callback function with the actual functionality of the user application.

function mainTask( application ) may use one parameter. That is the application object for the library. It is supposed to be mapped into mw.libs.isbnLib also.

API

[edit]

All API functions are components of the application parameter in the hook function, which is mapped to the mw.libs.isbnLib application object.

.factory()

[edit]

Create a RegExp string for ISBN detection, to find even faulty formatted ISBN.

Call .factory(attribute)
Parameter Type Meaning
attribute boolean true: URLs are excluded from detection
Return value
  • string – string for RegExp; null if no libraries

.finder()

[edit]

Retrieve set of library catalog URLs for a particular language.

Call .finder(assign)
Parameter Type Meaning
assign boolean
string
  • false – language independent set
  • string with language code; result will append particular catalogs for this language.
Return value

Array of URL strings

  • Every string is supposed to contain a # to be replaced by ISBN value

.flip()

[edit]

Retrieve corresponding ISBN-10 for ISBN-13, or ISBN-13 for ISBN-10.

Call .flip(adjust)
Parameter Type Meaning
adjust string ISBN (ID only, freestyle, no keyword) even non-ASCII characters
Return value
  • string – counterpart for adjust
  • falseadjust is invalid
  • null – required module not yet available

.focus()

[edit]

Guess language(s) from ISBN.

Call .focus(about)
Parameter Type Meaning
about string ISBN (ID only, freestyle, no keyword) even non-ASCII characters
Return value
  • string – space separated list of ISO 639 codes
  • false – not detected
  • null – required module not yet available

.format()

[edit]

Format an ISBN.

Call .format(adjust,additional)
Parameter Type Meaning
adjust string ISBN (ID only, freestyle, no keyword) even non-ASCII characters
additional boolean
optional
true: return Array rather than string
Return value
  • string – ASCII-formatted adjust
  • Array – Two elements; [0] is 10 or 13; [1] is formatted adjust
  • falseadjust is invalid
  • null – required module not yet available

.furnish()

[edit]

Add resolvers to default catalogs.

Call .furnish(add)
Parameter Type Meaning
add object Every component is a language code as of ISO 639.
  • qqq – language independent set

Every component value is an Array of URL strings.

  • Every string is supposed to contain a # to be replaced by ISBN value.

Repeated identical definitions will be ignored.

Internals

[edit]

The library is utilising components of WikiSyntaxTextMod (currently S and U).

A qunit test is available.

Codes

[edit]
Source code
ResourceLoader
  • ext.gadget.isbnLib (installation launched)
  • ext.gadget.isbnLib/* (all components)
  • Dependencies:
    • user:PerfektesChaos/WikiSyntaxTextMod/S
    • user:PerfektesChaos/WikiSyntaxTextMod/U
mw.libs isbnLib
mw.hook isbnLib.ready