From 81c72edea02c00c58bbb0fa72e0bf316ae258954 Mon Sep 17 00:00:00 2001 From: The Wizard Bear <42446683+TheWizardBear@users.noreply.github.com> Date: Sun, 22 Nov 2020 21:47:01 +0000 Subject: [PATCH] Version 2.1.0 --- README.md | 4 ++-- egg.json | 2 +- mod.ts | 38 +++++++++++++++++++++----------------- version.ts | 2 +- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3f9edc1..07560c9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Currently only PNG and JPG images are supported. To install the CLI tool, run the following from the command line: ```shell -deno install --allow-read --allow-net --unstable --force https://x.nest.land/terminal_images@2.0.0/cli.ts +deno install --allow-read --allow-net --unstable --force https://x.nest.land/terminal_images@2.1.0/cli.ts ``` Then run @@ -52,7 +52,7 @@ _Note that the size might be different, as by default it adapts to the size of y Here is an example of how you can use it: ```ts -import { printImageString } from "https://x.nest.land/terminal_images@2.0.0/mod.ts"; +import { printImageString } from "https://x.nest.land/terminal_images@2.1.0/mod.ts"; printImageString({ diff --git a/egg.json b/egg.json index 8220d74..bf22b75 100644 --- a/egg.json +++ b/egg.json @@ -4,7 +4,7 @@ "entry": "./mod.ts", "description": "A Deno module and CLI tool for displaying images in the terminal", "homepage": "https://github.com/TheWizardBear/terminal_images", - "version": "2.0.0", + "version": "2.1.0", "files": [ "./README.md", "./mod.ts", diff --git a/mod.ts b/mod.ts index 1524973..5518aa3 100644 --- a/mod.ts +++ b/mod.ts @@ -6,7 +6,7 @@ interface imageSettings { /** The raw data of a PNG or JPG image */ rawFile?: Uint8Array; /** The raw data for the image: the rgb(a) array as well as the height and width */ - rawPixels?: {data: Uint8Array, width: number, height: number}; + rawPixels?: { data: Uint8Array; width: number; height: number }; /** The character map to use when outputting the image */ characterMap?: string | string[]; /** The number of characters wide the output image is */ @@ -35,8 +35,7 @@ async function getImageString(settings: imageSettings): Promise { const color = settings.color ?? false; let raw; - if(typeof settings.path !== "undefined"){ - + if (typeof settings.path !== "undefined") { const path = settings.path; //external file on the internet (requires --allow-net) @@ -44,31 +43,31 @@ async function getImageString(settings: imageSettings): Promise { const response = await fetch(path); raw = new Uint8Array(await response.arrayBuffer()); - //local file (requires --allow-read) + //local file (requires --allow-read) } else { raw = await Deno.readFile(path); } - - }else if(typeof settings.rawFile !== "undefined"){ + } else if (typeof settings.rawFile !== "undefined") { raw = settings.rawFile; - }else if(typeof settings.rawPixels !== "undefined"){ + } else if (typeof settings.rawPixels !== "undefined") { raw = settings.rawPixels; - } else{ - throw new Error("No file path or raw data specified.") + } else { + throw new Error("No file path or raw data specified."); } //@ts-ignore - let imageFileType = typeof settings.rawPixels !== "undefined" ? "raw" : getFileType(raw); + let imageFileType = typeof settings.rawPixels !== "undefined" + ? "raw" + : getFileType(raw); if (imageFileType === "unknown") { - if(settings.path){ + if (settings.path) { const fileExtension = settings.path.substr( settings.path.lastIndexOf(".") + 1, ).toLowerCase(); throw new Error(`Image file type not supported. (${fileExtension})`); - }else{ - throw new Error(`Image file type not supported.`) + } else { + throw new Error(`Image file type not supported.`); } - } const decodedImage = decodeImage(raw, imageFileType); @@ -91,7 +90,9 @@ async function getImageString(settings: imageSettings): Promise { let outputString = ""; for ( - let y = resolution; y < imagePixelHeight - resolution; y += resolution * 2 + let y = resolution; + y < imagePixelHeight - resolution; + y += resolution * 2 ) { for ( let x: number = resolution / 2; @@ -290,7 +291,10 @@ async function printImageString(settings: imageSettings): Promise { console.log(await getImageString(settings)); } -function decodeImage(raw: Uint8Array | {data: Uint8Array, width: number, height: number}, format: string) { +function decodeImage( + raw: Uint8Array | { data: Uint8Array; width: number; height: number }, + format: string, +) { let decodedImage; switch (format) { case "jpg": @@ -302,7 +306,7 @@ function decodeImage(raw: Uint8Array | {data: Uint8Array, width: number, height: //@ts-ignore decodedImage = decodePng(raw); break; - + case "raw": decodedImage = raw; break; diff --git a/version.ts b/version.ts index 7be84dc..db7ae38 100644 --- a/version.ts +++ b/version.ts @@ -1 +1 @@ -export default "2.0.0"; +export default "2.1.0";