1.0.1 â€ĸ Published 17 days ago

@hugoalh/http-header-link v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

HTTP Header Link (ES)

⚖ī¸ MIT

GitHub: hugoalh-studio/http-header-link-es JSR: @hugoalh/http-header-link NPM: @hugoalh/http-header-link

An ES (JavaScript & TypeScript) module to handle HTTP header Link according to RFC 8288 standard.

đŸŽ¯ Target

  • Bun ^ v1.0.0
  • Cloudflare Workers
  • Deno >= v1.34.0 / >= v1.41.1 (For JSR Only)

    🛡ī¸ Require Permission

    N/A

  • NodeJS >= v16.13.0

🔰 Usage

Via JSR With node_modules

đŸŽ¯ Supported Target

  • Bun
  • Cloudflare Workers
  • NodeJS
  1. Install via:
    • Bun
      bunx jsr add @hugoalh/http-header-link[@${Tag}]
    • NPM
      npx jsr add @hugoalh/http-header-link[@${Tag}]
    • PNPM
      pnpm dlx jsr add @hugoalh/http-header-link[@${Tag}]
    • Yarn
      yarn dlx jsr add @hugoalh/http-header-link[@${Tag}]
  2. Import at the script:
    import ... from "@hugoalh/http-header-link";

ℹī¸ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via JSR With Specifier

đŸŽ¯ Supported Target

  • Deno
  1. Import at the script:
    import ... from "jsr:@hugoalh/http-header-link[@${Tag}]";

ℹī¸ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via NPM With node_modules

đŸŽ¯ Supported Target

  • Cloudflare Workers
  • NodeJS
  1. Install via:
    • NPM
      npm install @hugoalh/http-header-link[@${Tag}]
    • PNPM
      pnpm add @hugoalh/http-header-link[@${Tag}]
    • Yarn
      yarn add @hugoalh/http-header-link[@${Tag}]
  2. Import at the script:
    import ... from "@hugoalh/http-header-link";

ℹī¸ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via NPM With Specifier

đŸŽ¯ Supported Target

  • Bun
  • Deno
  1. Import at the script:
    import ... from "npm:@hugoalh/http-header-link[@${Tag}]";

ℹī¸ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via Remote Import

đŸŽ¯ Supported Target

  • Deno
  1. Import at the script:
    /* Via GitHub Raw (Require Tag) */
    import ... from "https://raw.githubusercontent.com/hugoalh-studio/http-header-link-es/${Tag}/mod.ts";

ℹī¸ Note

  • Although it is recommended to import the entire module with the main path mod.ts, it is also able to import part of the module with sub path if available, but do not import if:

    • it's file path has an underscore prefix (e.g.: _foo.ts, _util/bar.ts), or
    • it is a benchmark or test file (e.g.: foo.bench.ts, foo.test.ts), or
    • it's symbol has an underscore prefix (e.g.: export function _baz() {}).

    These elements are not considered part of the public API, thus no stability is guaranteed for them.

  • Although there have 3rd party services which provide enhanced, equal, or similar methods/ways to remote import the module, beware these services maybe inject unrelated elements and thus affect the security.

🧩 API

  • class HTTPHeaderLink {
      constructor(value?: string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response): HTTPHeaderLink;
      add(value: string | Headers | HTTPHeaderLink | HTTPHeaderLinkEntry[] | Response): this;
      entries(): HTTPHeaderLinkEntry[];
      getByParameter(key: string, value: string): HTTPHeaderLinkEntry[];
      getByRel(value: string): HTTPHeaderLinkEntry[];
      hasParameter(key: string, value: string): boolean;
      toString(): string;
      static parse(value: string | Headers | HTTPHeaderLink | Response): HTTPHeaderLink;
      static stringify(value: HTTPHeaderLinkEntry[]): string;
    }
  • type HTTPHeaderLinkEntry = [
      uri: string,
      parameters: { [key: string]: string; }
    ];

ℹī¸ Note

For the prettier documentation, can visit via:

✍ī¸ Example

  • new HTTPHeaderLink(`<https://example.com>; rel="preconnect"`);
    /*=>
    HTTPHeaderLink [
      ["https://example.com", { rel: "preconnect" }]
    ]
    */
  • new HTTPHeaderLink(`<https://example.com/%E8%8B%97%E6%9D%A1>; rel="preconnect"`);
    /*=>
    HTTPHeaderLink [
      ["https://example.com/č‹—æĄ", { rel: "preconnect" }]
    ]
    */
1.0.1

17 days ago

1.0.0

17 days ago