1.0.6 • Published 1 year ago

sakfjs v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

ATTENTION: Jimp's methods are very heavy, so I'm trying to redo them in npm

sakfjs

sakfjs is a lib made by Lucas Christian, this lib was made for be like a swiss army knife, many useful functions, and efficient.

Sumário

Installation

Installation: npm i --save sakfjs

Supported Image Types

  • jpeg;
  • png.

Functions

Files

Fs

Images

Zod

getExtensions

  import { getExtensions } from "sakfjs";

  let extensions = getExtensions("image/jpeg");
  console.log(extensions); // [".jpeg", ".jpg", ".jpe"]

getMIMEType

  import { getMIMEType } from "sakfjs";

  let mimeType = getMIMEType("arquivo.js");
  console.log(mimeType); // "application/javascript"

  mimeType = getMIMEType("C:/Users/User/Pictures/image.jpg");
  console.log(mimeType); // "image/jpeg"

getStat

  import { stat } from "sakfjs";

  let imageStat = await stat("C:/Users/User/Pictures/image.jpg");
  console.log(imageStat); // fs.Stats -> https://nodejs.org/api/fs.html#class-fsstats

changeExtension

  import { changeExtension } from "sakfjs";
  import { writeFile } from "fs";

  const image = await changeExtension("C:/Users/User/Pictures/image.jpg", "png"); 

  // changeExtension returns the Image Buffer!
  console.log(image); // Buffer

  // Combine with writeFile from fs so you can see the change!
  writeFile("C:/Users/User/Pictures/image.png", image);
  // "C:/Users/User/Pictures/image.jpg" -> "C:/Users/User/Pictures/imagem.png"

changeQuality

  import { changeQuality } from "sakfjs";
  import { writeFile } from "fs";

  const image = await changeQuality("C:/Users/User/Pictures/image.jpg", 60); 

  // changeQuality returns the Image Buffer!
  console.log(image); // Buffer

  // Combine with writeFile from fs so you can see the change!
  writeFile("C:/Users/User/Pictures/image.jpg", image);

getSupportedImages

  import { getSupportedImages } from "sakfjs";
  import { readFileSync } from "fs";

  const images = getSupportedImages("C:/Users/User/Pictures");

  console.log(images); 
  /* All supported images will be returned in the array like this
    [
      {          
        name: image.jpg, 
        size: 3000, 
        path: "C:/Users/User/Pictures/image.jpg",
        ext: "jpg",
        mime: "image/jpeg"
      },
      {         
        name: image2.png,
        size: 5000,
        path: "C:/Users/User/Pictures/image2.png",
        ext: "png",
        mime: image/png
      }
    ]
  */

isASupportedImage

  import { isASupportedImage } from "sakfjs";

  let supportedImageByExt = isASupportedImage("jpg"),
  supportedImageByMIME = isASupportedImage("image/jpeg");

  let unsupportedImageByExt = isASupportedImage("gif"),
  unsupportedImageByMIME = isASupportedImage("image/gif");

  console.log(supportedImageByExt); // true
  console.log(supportedImageByMIME); // true

  console.log(unsupportedImageByExt); // false
  console.log(unsupportedImageByMIME); // false

resizeImage

  import { resizeImage } from "sakfjs";
  import { writeFile } from "fs";

  const image = await resizeImage("C:/Users/User/Pictures/image.jpg", {width: 600, height: 400}); // 1200x800 -> 600x400

  // resizeImage returns the Image Buffer!
  console.log(image); // Buffer

  // Combine with writeFile from fs so you can see the change!
  writeFile("C:/Users/User/Pictures/image.jpg", image);

isUndefined

  import { isUndefined } from "sakfjs";

  console.log(isUndefined(undefined); // true
  console.log(isUndefined("hello")); // false

isString

  import { isString } from "sakfjs";

  console.log(isString("hello")); // true
  console.log(isString(321)); // false

isNumber

  import { isNumber } from "sakfjs";

  console.log(isNumber(321)); // true
  console.log(isNumber("hello")); // false

isArray

  import { isArray } from "sakfjs";

  console.log(isArray(["hello", "world"])); // true
  console.log(isArray({hello: "world"})); // false

isBuffer

  import { readFileSync } from "fs";
  import { isBuffer } from "sakfjs";

  let buffer = readFileSync("C:/Users/User/Pictures/image.jpg");

  console.log(isBuffer(buffer); // true
  console.log(isBuffer({hello: "world"})); // false

isObject

  import { isObject } from "sakfjs";

  console.log(isObject({hello: "world"}); // true
  console.log(isObject("hello")); // false

Collaborate

Whenever you think of functions that might be useful, and that would be useful in a lib, make it and send it with a pull request, with tests already implemented in the new function.

Errors in sakfjs

If you have identified an error, just open an issue, and if you have already resolved this error, please make a pull request, so you collaborate with the project!

Authors

1.0.6

1 year ago

1.0.5

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago