Skip to content

Commit

Permalink
Merge pull request #4 from MyUnisoft/version
Browse files Browse the repository at this point in the history
feat: add version method
  • Loading branch information
Dafyh authored Aug 7, 2024
2 parents fd4254c + 3ee6062 commit a4d5523
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,27 @@ The **heif-converter** package facilitates the conversion of HEIF (High Efficien
## 🦴 Installation

```bash
npm install heif-converter
npm install @myunisoft/heif-converter
```

## 🚀 API
<details>
<summary>version</summary>
<br>

The **version** method is used to obtain the version of libheif.

```ts
function version(): string;
```
```js
import lib from "../index.js";

console.log(lib.version());
// 1.17.6
```
</details>
<details>
<summary>toJpeg</summary>
<br>

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare const types: {
toJpeg(input: string | Buffer | Readable, options?: JpegOptions): Promise<Buffer>;
toPng(input: string | Buffer | Readable, options?: PngOptions): Promise<Buffer>;
extract(input: string | Buffer | Readable): Promise<ExtractedImage[]>;
version(): string;
};

export default types;
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ async function getBufferFromInput(input) {
}

module.exports = {
version() {
return lib.version();
},
async toJpeg(input, options = { quality: 75 }) {
const buffer = await getBufferFromInput(input);

Expand Down
Empty file removed platform/darwin-x64/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions src/lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ Napi::Value ExtractIds(const Napi::CallbackInfo& info) {
return result;
}

Napi::String GetVersion(const Napi::CallbackInfo& info) {
return Napi::String::New(info.Env(), heif_get_version());
}

Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "version"), Napi::Function::New(env, GetVersion));
exports.Set(Napi::String::New(env, "toPng"), Napi::Function::New(env, ToPng));
exports.Set(Napi::String::New(env, "toJpeg"), Napi::Function::New(env, ToJpeg));
exports.Set(Napi::String::New(env, "extractIds"), Napi::Function::New(env, ExtractIds));
Expand Down
6 changes: 6 additions & 0 deletions test/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import lib from "../index.js";
// CONSTANTS
const kDirname = path.dirname(fileURLToPath(import.meta.url));

describe("version", () => {
it("Should get libheif version", () => {
assert.strictEqual(/\d{1}\.\d{1,2}\.\d{1,2}/.test(lib.version()), true);
});
});

describe("toJpeg", () => {
it("Should convert .heic to .jpeg", async() => {
const heifFilePath = path.join(kDirname, "image.heic");
Expand Down

0 comments on commit a4d5523

Please sign in to comment.