|
@@ -1,13 +1,11 @@
|
|
|
import {Book, DamageLogger, Librarian} from './interfaces';
|
|
|
import {Category} from "./enums";
|
|
|
import {
|
|
|
- Encyclopedia,
|
|
|
- Journal,
|
|
|
ReferenceItem,
|
|
|
UniversityLibrarian
|
|
|
} from "./classes";
|
|
|
|
|
|
-function GetAllBooks(): Book[] {
|
|
|
+export function GetAllBooks(): Book[] {
|
|
|
const books = [
|
|
|
{
|
|
|
author: 'James Joyce',
|
|
@@ -42,7 +40,7 @@ function GetAllBooks(): Book[] {
|
|
|
return books;
|
|
|
}
|
|
|
|
|
|
-function LogFirstAvailable(books = GetAllBooks()): void {
|
|
|
+export function LogFirstAvailable(books = GetAllBooks()): void {
|
|
|
|
|
|
const numberOfBooks: number = books.length;
|
|
|
let firstAvailable: string = '';
|
|
@@ -57,7 +55,7 @@ function LogFirstAvailable(books = GetAllBooks()): void {
|
|
|
console.log(`First available: ${firstAvailable}.`);
|
|
|
}
|
|
|
|
|
|
-function CheckoutBooks(customer: string, ...bookIds: number[]): string[] {
|
|
|
+export function CheckoutBooks(customer: string, ...bookIds: number[]): string[] {
|
|
|
console.log(`Checking out books for ${customer}.`);
|
|
|
|
|
|
let booksCheckedOut: string[] = [];
|
|
@@ -71,7 +69,7 @@ function CheckoutBooks(customer: string, ...bookIds: number[]): string[] {
|
|
|
return booksCheckedOut;
|
|
|
}
|
|
|
|
|
|
-function CreateCustomer(name: string, age?: number, city?: string) {
|
|
|
+export function CreateCustomer(name: string, age?: number, city?: string) {
|
|
|
console.log(`Name: ${name}.`);
|
|
|
if (age) {
|
|
|
console.log(`Age: ${age}.`);
|
|
@@ -81,11 +79,11 @@ function CreateCustomer(name: string, age?: number, city?: string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function CreateCustomerId(chars: string, nums: number): string {
|
|
|
+export function CreateCustomerId(chars: string, nums: number): string {
|
|
|
return chars + nums;
|
|
|
}
|
|
|
|
|
|
-function GetBookTitlesByCategory(categoryFilter: Category = Category.Fiction): Array<string> {
|
|
|
+export function GetBookTitlesByCategory(categoryFilter: Category = Category.Fiction): Array<string> {
|
|
|
console.log(`Getting books in category: ${Category[categoryFilter]}.`);
|
|
|
|
|
|
const allBooks = GetAllBooks();
|
|
@@ -99,22 +97,22 @@ function GetBookTitlesByCategory(categoryFilter: Category = Category.Fiction): A
|
|
|
return filteredTitles;
|
|
|
}
|
|
|
|
|
|
-function GetBookById(id: number): Book {
|
|
|
+export function GetBookById(id: number): Book {
|
|
|
const allBooks = GetAllBooks();
|
|
|
return allBooks.filter(book => book.id === id)[0];
|
|
|
}
|
|
|
|
|
|
-function LogBookTitles(titles: string[]): void {
|
|
|
+export function LogBookTitles(titles: string[]): void {
|
|
|
for (let title of titles) {
|
|
|
console.log(title);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Note: no implementation.
|
|
|
-function GetTitles(author: string): string[];
|
|
|
-function GetTitles(available: boolean): string[];
|
|
|
+export function GetTitles(author: string): string[];
|
|
|
+export function GetTitles(available: boolean): string[];
|
|
|
// Now an implementation:
|
|
|
-function GetTitles(bookProperty: any): string[] {
|
|
|
+export function GetTitles(bookProperty: any): string[] {
|
|
|
const allBooks = GetAllBooks();
|
|
|
|
|
|
const foundTitles: Array<string> = [];
|
|
@@ -141,40 +139,41 @@ function GetTitles(bookProperty: any): string[] {
|
|
|
return foundTitles;
|
|
|
}
|
|
|
|
|
|
-function PrintBook(book: Book): void {
|
|
|
+export function PrintBook(book: Book): void {
|
|
|
console.log(`${book.title} by ${book.author}.`);
|
|
|
}
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
-let myBook: Book = {
|
|
|
- author: 'Jane Austen',
|
|
|
- available: true,
|
|
|
- category: Category.Fiction,
|
|
|
- // copies: 3,
|
|
|
- id: 5,
|
|
|
- pages: 250,
|
|
|
- title: 'Pride and prejudice',
|
|
|
- // year: '1813',
|
|
|
- markDamaged: reason => console.log(`Damaged: ${reason}.`),
|
|
|
-};
|
|
|
-
|
|
|
-// PrintBook(myBook);
|
|
|
-// myBook.markDamaged('Torn back cover');
|
|
|
-
|
|
|
-// let logDamage: DamageLogger = reason => console.log(`Damage reported: ${reason}.`);
|
|
|
-// logDamage('Coffee stains');
|
|
|
-
|
|
|
-// let favoriteLibrarian: Librarian = new UniversityLibrarian();
|
|
|
-// favoriteLibrarian.name = 'Sharon';
|
|
|
-// favoriteLibrarian.assistCustomer('Lynda');
|
|
|
-
|
|
|
-// let ref: ReferenceItem = new ReferenceItem('Facts and Figures', 2016);
|
|
|
-// ref.publisher = 'Random Data publisher';
|
|
|
-// ref.printItem();
|
|
|
-// console.log(ref.publisher);
|
|
|
+function bookDemo() {
|
|
|
+ let myBook: Book = {
|
|
|
+ author: 'Jane Austen',
|
|
|
+ available: true,
|
|
|
+ category: Category.Fiction,
|
|
|
+ // copies: 3,
|
|
|
+ id: 5,
|
|
|
+ pages: 250,
|
|
|
+ title: 'Pride and prejudice',
|
|
|
+ // year: '1813',
|
|
|
+ markDamaged: reason => console.log(`Damaged: ${reason}.`),
|
|
|
+ };
|
|
|
+
|
|
|
+ PrintBook(myBook);
|
|
|
+ myBook.markDamaged!('Torn back cover');
|
|
|
+ let logDamage: DamageLogger = reason => console.log(`Damage reported: ${reason}.`);
|
|
|
+ logDamage('Coffee stains');
|
|
|
+}
|
|
|
|
|
|
function classDemo() {
|
|
|
+ let favoriteLibrarian: Librarian = new UniversityLibrarian();
|
|
|
+ favoriteLibrarian.name = 'Sharon';
|
|
|
+ favoriteLibrarian.assistCustomer('Lynda');
|
|
|
+
|
|
|
+ // let ref: ReferenceItem = new ReferenceItem('Facts and Figures', 2016);
|
|
|
+ // ref.publisher = 'Random Data publisher';
|
|
|
+ // ref.printItem();
|
|
|
+ // console.log(ref.publisher);
|
|
|
+
|
|
|
let Newspaper = class extends ReferenceItem {
|
|
|
printCitation(): void {
|
|
|
console.log(`Newspaper: ${this.title}.`);
|
|
@@ -193,4 +192,5 @@ function classDemo() {
|
|
|
console.log(favoriteNovel);
|
|
|
}
|
|
|
|
|
|
-// classDemo();
|
|
|
+false && bookDemo();
|
|
|
+classDemo();
|