From a60a56bba8a7cdcc4a6a3ec3dcf9bb19b6930d9e Mon Sep 17 00:00:00 2001 From: John Date: Tue, 4 Oct 2022 09:29:57 +0100 Subject: [PATCH 1/9] feat: convert TypeScript types made more specific --- CHANGES.md | 3 +++ package.json | 2 +- src/tinify/Source.ts | 13 ++++++++++++- test/tinify-typing-test.ts | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6933694..3777809 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +## 1.7.2 +* Refine convert TypeScript types and add type tests + ## 1.7.0 * Added convert and transform functions * Added function to get the file extension diff --git a/package.json b/package.json index c20d311..c67d008 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tinify", - "version": "1.7.1", + "version": "1.7.2", "description": "Node.js client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.", "keywords": [ "tinify", diff --git a/src/tinify/Source.ts b/src/tinify/Source.ts index 5807587..06bb52d 100644 --- a/src/tinify/Source.ts +++ b/src/tinify/Source.ts @@ -5,6 +5,17 @@ import Client from "./Client" import Result from "./Result" import ResultMeta from "./ResultMeta" +export type SupportedImageTypes = "image/webp" + | "image/png" + | "image/jpg"; + +export type WildcardOrSupportedImageTypes = SupportedImageTypes + | "/"; // The wildcard "/" returns the smallest of Tinify's supported image types, currently JPEG, PNG and WebP. + +export type ConvertOptions = { + type: WildcardOrSupportedImageTypes | SupportedImageTypes[]; +} + export default class Source { /** @internal */ private _url: Promise @@ -85,7 +96,7 @@ export default class Source { return this.result().toBuffer(callback!) } - convert(options: object): Source { + convert(options: ConvertOptions): Source { return new tinify.Source( this._url, Object.assign({ convert: options }, this._commands) diff --git a/test/tinify-typing-test.ts b/test/tinify-typing-test.ts index cefda37..b4231e6 100644 --- a/test/tinify-typing-test.ts +++ b/test/tinify-typing-test.ts @@ -11,6 +11,12 @@ async function run() { await tinify.fromBuffer(Buffer.from("foobar")).toBuffer() await tinify.fromUrl("https://tinypng.com/images/panda-happy.png").toBuffer() + await tinify.fromFile("/foo/bar").convert({ type: ["image/webp", "image/png", "image/jpg"] }) + await tinify.fromFile("/foo/bar").convert({ type: "image/webp" }) + await tinify.fromFile("/foo/bar").convert({ type: "image/png" }) + await tinify.fromFile("/foo/bar").convert({ type: "image/jpg" }) + await tinify.fromFile("/foo/bar").convert({ type: "/" }) + await tinify.fromBuffer("foo") .resize({method: "fit", width: 150, height: 100}) .preserve("copyright", "creation") From cd2c12f663c0eba5c9e410df003edb8d3ed7b325 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 4 Oct 2022 15:10:08 +0100 Subject: [PATCH 2/9] feat: / should be */* --- src/tinify/Source.ts | 2 +- test/tinify-typing-test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tinify/Source.ts b/src/tinify/Source.ts index 06bb52d..e86b697 100644 --- a/src/tinify/Source.ts +++ b/src/tinify/Source.ts @@ -10,7 +10,7 @@ export type SupportedImageTypes = "image/webp" | "image/jpg"; export type WildcardOrSupportedImageTypes = SupportedImageTypes - | "/"; // The wildcard "/" returns the smallest of Tinify's supported image types, currently JPEG, PNG and WebP. + | "*/*"; // The wildcard "*/*" returns the smallest of Tinify's supported image types, currently JPEG, PNG and WebP. export type ConvertOptions = { type: WildcardOrSupportedImageTypes | SupportedImageTypes[]; diff --git a/test/tinify-typing-test.ts b/test/tinify-typing-test.ts index b4231e6..bc2311e 100644 --- a/test/tinify-typing-test.ts +++ b/test/tinify-typing-test.ts @@ -15,7 +15,7 @@ async function run() { await tinify.fromFile("/foo/bar").convert({ type: "image/webp" }) await tinify.fromFile("/foo/bar").convert({ type: "image/png" }) await tinify.fromFile("/foo/bar").convert({ type: "image/jpg" }) - await tinify.fromFile("/foo/bar").convert({ type: "/" }) + await tinify.fromFile("/foo/bar").convert({ type: "*/*" }) await tinify.fromBuffer("foo") .resize({method: "fit", width: 150, height: 100}) From 2129308b8df8868a77a312cfea8f4a3d8eb88a67 Mon Sep 17 00:00:00 2001 From: Remco Koopmans Date: Tue, 18 Feb 2025 15:41:52 +0100 Subject: [PATCH 3/9] Update node versions and update tests --- .github/workflows/ci-cd.yaml | 6 +++--- test/tinify-client-test.js | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 852759b..1c47570 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - node: [14, 16, 18] + node: [18, 20, 22, 23] os: [ubuntu-latest, macOS-latest, windows-latest] steps: - uses: actions/checkout@v3 @@ -29,7 +29,7 @@ jobs: strategy: fail-fast: false matrix: - node: [14, 16, 18] + node: [18, 20, 22, 23] os: [ubuntu-latest, macOS-latest, windows-latest] steps: - uses: actions/checkout@v3 @@ -57,7 +57,7 @@ jobs: - name: Set up node uses: actions/setup-node@v3 with: - node-version: "16.x" + node-version: "22.x" registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm install diff --git a/test/tinify-client-test.js b/test/tinify-client-test.js index a0a17a9..1bcbac4 100644 --- a/test/tinify-client-test.js +++ b/test/tinify-client-test.js @@ -233,12 +233,14 @@ describe("Client", function() { }) it("should pass error with message", function() { - if (semver.gte(process.versions.node, "6.0.0")) { + if (semver.gte(process.versions.node, "20.0.0")) { + assert.equal(error.message, "Error while parsing response: Unexpected token '<', \"