mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-27 14:30:49 +08:00
Added support for isbn-utils
This commit is contained in:
35
isbn-utils/index.d.ts
vendored
Normal file
35
isbn-utils/index.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Type definitions for isbn-utils 1.1
|
||||
// Project: https://github.com/GitbookIO/isbn-utils
|
||||
// Definitions by: Jørgen Elgaard Larsen <https://github.com/elhaard/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
type IGroups = any;
|
||||
|
||||
export class ISBNcodes {
|
||||
readonly source: string;
|
||||
readonly prefix: string;
|
||||
readonly group: string;
|
||||
readonly publisher: string;
|
||||
readonly article: string;
|
||||
readonly check: string;
|
||||
readonly check10: string;
|
||||
readonly check13: string;
|
||||
readonly groupname: string;
|
||||
}
|
||||
|
||||
export class ISBN {
|
||||
constructor(val: string, groups: IGroups);
|
||||
asIsbn10(hyphenate?: boolean): string;
|
||||
asIsbn13(hyphenate?: boolean): string;
|
||||
codes: ISBNcodes;
|
||||
isIsbn10(): boolean;
|
||||
isIsbn13(): boolean;
|
||||
isValid(): boolean;
|
||||
}
|
||||
|
||||
export function asIsbn10(isbn: string, hyphenate?: boolean): string;
|
||||
export function asIsbn13(isbn: string, hyphenate?: boolean): string;
|
||||
export function parse(isbn: string, groups?: IGroups): ISBN|null;
|
||||
export function hyphenate(isbn: string): string;
|
||||
export function isValid(isbn: string, groups?: IGroups): boolean;
|
||||
36
isbn-utils/isbn-utils-tests.ts
Normal file
36
isbn-utils/isbn-utils-tests.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import * as isbn from 'isbn-utils';
|
||||
|
||||
|
||||
const isbn10a: isbn.ISBN|null = isbn.parse('4873113369');
|
||||
let b: boolean;
|
||||
let s: string;
|
||||
|
||||
if (isbn10a !== null) {
|
||||
b = isbn10a.isIsbn10();
|
||||
b = isbn10a.isIsbn13();
|
||||
s = isbn10a.asIsbn10();
|
||||
s = isbn10a.asIsbn10(true);
|
||||
s = isbn10a.asIsbn13();
|
||||
s = isbn10a.asIsbn13(true);
|
||||
s = isbn10a.codes.source;
|
||||
s = isbn10a.codes.prefix;
|
||||
s = isbn10a.codes.group;
|
||||
s = isbn10a.codes.publisher;
|
||||
s = isbn10a.codes.article;
|
||||
s = isbn10a.codes.check;
|
||||
s = isbn10a.codes.check10;
|
||||
s = isbn10a.codes.check13;
|
||||
s = isbn10a.codes.groupname;
|
||||
}
|
||||
|
||||
const bad: isbn.ISBN|null = isbn.parse('invalid format');
|
||||
if (bad === null) {
|
||||
s = 'Bummer.';
|
||||
}
|
||||
|
||||
s = isbn.asIsbn13('4-87311-336-9');
|
||||
s = isbn.asIsbn13('4-87311-336-9', true);
|
||||
s = isbn.asIsbn10('978-4-87311-336-4');
|
||||
s = isbn.asIsbn10('978-4-87311-336-4', true);
|
||||
|
||||
s = isbn.hyphenate('9784873113364');
|
||||
20
isbn-utils/tsconfig.json
Normal file
20
isbn-utils/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"isbn-utils-tests.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
3
isbn-utils/tslint.conf
Normal file
3
isbn-utils/tslint.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../tslint.json",
|
||||
}
|
||||
Reference in New Issue
Block a user