User:PerfektesChaos/js/isbnLib
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://en.wikipedia.org/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 |
|
.finder()
[edit]Retrieve set of library catalog URLs for a particular language.
Call | .finder(assign)
| ||
---|---|---|---|
Parameter | Type | Meaning | |
assign
|
boolean string
|
| |
Return 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 |
|
.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 |
|
.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 |
|
.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.
Every component value is an
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 |
|
mw.libs
|
isbnLib
|
mw.hook
|
isbnLib.ready
|