Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Improve code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXyfir committed Apr 25, 2019
1 parent 58de466 commit 0cc9320
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,37 @@ Built and maintained by the [Xyfir Network](https://www.xyfir.com).

node-calibre is mostly a simple wrapper around Calibre's CLI using Node's [child_process.exec()](https://nodejs.org/api/child_process.html), without many extra features added. In the future this package will contain more methods unique to each of Calibre's binaries and with both better error checking and improved results provided on success.

# Example
# Examples

```ts
const { Calibre } = require('node-calibre');

(async () => {
try {
const calibre = new Calibre({ library: '/path/to/calibre/library' });

const newFile = await calibre.ebookConvert('/path/to/book.epub', 'pdf', {
smartenPunctuation: null
});
console.log(newFile); // /path/to/book.epub.pdf

let result: string;
result = await calibre.run('calibredb add', ['/path/to/book.epub']);
console.log(result); // Added book ids: ...

result = await calibre.run('ebook-convert', [
'path/to/book.epub',
'path/to/book.txt'
]);
console.log(result); // Output saved to ...

result = await calibre.run('calibredb list', [], { limit: 10 });
console.log(result); // first 10 books

// You can optionally pass `options` as the second parameter
// `forMachine: null` gets converted to `--for-machine`
result = await calibre.run('calibredb list', {
limit: 10,
forMachine: null
});
console.log(Array.isArray(JSON.parse(result))); // true
} catch (err) {
console.error(err);
}
})();
import { Calibre } from 'node-calibre';

// Create Calibre instance
const calibre = new Calibre({ library: '/path/to/calibre/library' });

// Convert ebook from epub to pdf
const newFile = await calibre.ebookConvert('/path/to/book.epub', 'pdf', {
smartenPunctuation: null
});
console.log(newFile); // "/path/to/book.epub.pdf"

let result: string;

// Add book to Calibre library
result = await calibre.run('calibredb add', ['/path/to/book.epub']);
console.log(result); // "Added book ids: ..."

// List books in Calibre Library
result = await calibre.run('calibredb list', [], { limit: 10 });
console.log(result); // first 10 books

// You can optionally pass `options` as the second parameter
// `forMachine: null` gets converted to `--for-machine`
result = await calibre.run('calibredb list', {
limit: 10,
forMachine: null
});
console.log(Array.isArray(JSON.parse(result))); // true
```

# API
Expand Down

0 comments on commit 0cc9320

Please sign in to comment.