From c4b77ece6008ae9da573a1edd166debb12854f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Elgaard=20Larsen?= Date: Wed, 15 Feb 2017 10:50:18 +0100 Subject: [PATCH 1/3] Added support for isbn-utils --- isbn-utils/index.d.ts | 35 +++++++++++++++++++++++++++++++++ isbn-utils/isbn-utils-tests.ts | 36 ++++++++++++++++++++++++++++++++++ isbn-utils/tsconfig.json | 20 +++++++++++++++++++ isbn-utils/tslint.conf | 3 +++ 4 files changed, 94 insertions(+) create mode 100644 isbn-utils/index.d.ts create mode 100644 isbn-utils/isbn-utils-tests.ts create mode 100644 isbn-utils/tsconfig.json create mode 100644 isbn-utils/tslint.conf diff --git a/isbn-utils/index.d.ts b/isbn-utils/index.d.ts new file mode 100644 index 0000000000..fe2ac4dae9 --- /dev/null +++ b/isbn-utils/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for isbn-utils 1.1 +// Project: https://github.com/GitbookIO/isbn-utils +// Definitions by: Jørgen Elgaard Larsen +// 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; diff --git a/isbn-utils/isbn-utils-tests.ts b/isbn-utils/isbn-utils-tests.ts new file mode 100644 index 0000000000..91f72a0359 --- /dev/null +++ b/isbn-utils/isbn-utils-tests.ts @@ -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'); diff --git a/isbn-utils/tsconfig.json b/isbn-utils/tsconfig.json new file mode 100644 index 0000000000..f67fbd95ef --- /dev/null +++ b/isbn-utils/tsconfig.json @@ -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 + } +} diff --git a/isbn-utils/tslint.conf b/isbn-utils/tslint.conf new file mode 100644 index 0000000000..0a0094293e --- /dev/null +++ b/isbn-utils/tslint.conf @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json", +} From b6404f98898dfa9ac2f2671c60aaf4681d80d32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Elgaard=20Larsen?= Date: Fri, 24 Feb 2017 17:58:41 +0100 Subject: [PATCH 2/3] isbn-utils: Renamed tslint, added lib to tsconfig --- isbn-utils/tsconfig.json | 3 +++ isbn-utils/{tslint.conf => tslint.json} | 0 2 files changed, 3 insertions(+) rename isbn-utils/{tslint.conf => tslint.json} (100%) diff --git a/isbn-utils/tsconfig.json b/isbn-utils/tsconfig.json index f67fbd95ef..b061bf6192 100644 --- a/isbn-utils/tsconfig.json +++ b/isbn-utils/tsconfig.json @@ -6,6 +6,9 @@ "compilerOptions": { "module": "commonjs", "target": "es6", + "lib": [ + "es6" + ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, diff --git a/isbn-utils/tslint.conf b/isbn-utils/tslint.json similarity index 100% rename from isbn-utils/tslint.conf rename to isbn-utils/tslint.json From 714613318c36b3eb6e73113946f27b335740b045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Elgaard=20Larsen?= Date: Fri, 24 Feb 2017 18:03:23 +0100 Subject: [PATCH 3/3] isbn-utils: fixed tsling.json --- isbn-utils/tslint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isbn-utils/tslint.json b/isbn-utils/tslint.json index 0a0094293e..f9e30021f4 100644 --- a/isbn-utils/tslint.json +++ b/isbn-utils/tslint.json @@ -1,3 +1,3 @@ { - "extends": "../tslint.json", + "extends": "../tslint.json" }