is-chrome-order

1.1.0 • Public • Published

is-chrome-order

Checks if http header order is Chrome

Usage

const express = require("express");
const isChromeOrder = require("is-chrome-order");

const port = 3000;
const app = express();

app.get("/", ({ headers }, res) => {
  const are = isChromeOrder(headers) ? "are" : "are not";

  res.send(`You ${are} chrome!`);
});

app.listen(port);

API

  type Headers = Record<string, string> | string[] | Array<[string, string]>;
  type IsChromeOrderOptions = {
    areRawHeaders: boolean;
  };

  function IsChromeOrder(
    headers: Headers,
    options: IsChromeOrderOptions = { areRawHeaders = false }
  ): boolean;

  export = IsChromeOrder;

headers - one of:

  • array of strings
["accept", "accept-language"];
  • object of structure [key: string]: string
{
  'accept': '...',
  'user-agent': '...'
}
  • array with 2-length array of strings
[
  ["accept-encoding", "gzip"],
  ["accept", "*/*"],
];

options: object that can have areRawHeaders option if it should parse entries array such as:

[
  "user-agent",
  "this is invalid because there can be only one",
  "User-Agent",
  "curl/7.22.0",
  "Host",
  "127.0.0.1:8000",
  "ACCEPT",
  "*",
];

areRawHeaders defaults to false

Test

node test

Related repository

is-firefox-order

Package Sidebar

Install

npm i is-chrome-order

Weekly Downloads

3

Version

1.1.0

License

ISC

Unpacked Size

10.4 kB

Total Files

6

Last publish

Collaborators

  • thepicture