Skip to content
On this page

Home > entanclature > entanclature

entanclature variable

This is the main function of this project!

Signature:

typescript
entanclature: typeof router & {
    fromURL: typeof fromURL;
    fromFile: typeof fromFile;
}

Remarks

This is a wrapper around the functions , fromURL() and fromFile().

You can pass in a string of file paths or URLs. We will process them as appropriate and return information about all files that pass through Entanglement Nomenclature.

If the string of a file path is passed, meta, baseURL and fileDir will be a must.

Example 1

You can import and use it in your project like this:

typescript
import { entanclature } from "entanclature";

const url = "https://example.com/images/OTk0QTc5OVA4MEErVy04.png";
const result = await entanclature(url);

console.log(result);

Example 2

We also support the local file path as a parameter (Node.js only), but you need to manually define the meta information for processing images, and specify the baseURL and fileDir of the URL:

typescript
import { entanclature } from "entanclature";

import type { Meta, Opts } from "entanclature";

const filePath = "./path/for/an/image.png";
const meta = [
  { type: "image/png", quality: 80 },
  { type: "image/avif", quality: "+" },
  { type: "image/webp", quality: "-" },
];
const opts: Opts = {
  baseURL: "https://example.com",
  fileDir: "/images/",
};
const result = await entanclature(filePath, meta, opts);

console.log(result);

Example 3

If you don't like await, you can also use entanclature.form URL to handle URLs:

typescript
import { entanclature } from "entanclature";

const url = "https://example.com/images/OTk0QTc5OVA4MEErVy04.png";
const result = entanclature.fromURL(url);

console.log(result);

However, await is required for the file path, because we need to calculate the SHA-1 of the file:

typescript
import { entanclature } from "entanclature";

// Omit defining `filePath`, `meta` and `opts` here.

const result = await entanclature.fromURL(filePath, meta, opts);

console.log(result);

Released under the CC-BY-SA-4.0 License.