react-user-agent-client-hints
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -63,3 +63,12 @@ "use strict"; | ||
}); | ||
const { result } = (0, react_1.renderHook)(() => (0, useUserAgentClientHints_1.useUserAgentClientHints)({ entropy: "high", hints: [] })); | ||
const { result } = (0, react_1.renderHook)(() => (0, useUserAgentClientHints_1.useUserAgentClientHints)({ | ||
entropy: "high", | ||
hints: [ | ||
"architecture", | ||
"bitness", | ||
"fullVersionList", | ||
"model", | ||
"platformVersion" | ||
] | ||
})); | ||
yield (0, react_1.waitFor)(() => { | ||
@@ -79,3 +88,12 @@ expect(result.current).toEqual(highEntropyUserAgentData); | ||
}); | ||
const { result } = (0, react_1.renderHook)(() => (0, useUserAgentClientHints_1.useUserAgentClientHints)({ entropy: "high", hints: [] })); | ||
const { result } = (0, react_1.renderHook)(() => (0, useUserAgentClientHints_1.useUserAgentClientHints)({ | ||
entropy: "high", | ||
hints: [ | ||
"architecture", | ||
"bitness", | ||
"fullVersionList", | ||
"model", | ||
"platformVersion" | ||
] | ||
})); | ||
yield (0, react_1.waitFor)(() => { | ||
@@ -90,3 +108,12 @@ expect(result.current).toEqual(new Error("Could not retrieve high-entropy user-agent data.")); | ||
}); | ||
const { result } = (0, react_1.renderHook)(() => (0, useUserAgentClientHints_1.useUserAgentClientHints)({ entropy: "high", hints: [] })); | ||
const { result } = (0, react_1.renderHook)(() => (0, useUserAgentClientHints_1.useUserAgentClientHints)({ | ||
entropy: "high", | ||
hints: [ | ||
"architecture", | ||
"bitness", | ||
"fullVersionList", | ||
"model", | ||
"platformVersion" | ||
] | ||
})); | ||
yield (0, react_1.waitFor)(() => { | ||
@@ -93,0 +120,0 @@ expect(result.current).toEqual(new Error(useUserAgentClientHints_1.errors.userAgentApiUndefined)); |
@@ -1,5 +0,2 @@ | ||
import { UADataValues, UALowEntropyJSON } from "../types"; | ||
declare type Hint = "architecture" | "model" | "bitness" | "platformVersion" | "fullVersionList"; | ||
declare type HighEntropy = "high"; | ||
declare type LowEntropy = "low"; | ||
import { HighEntropy, Hint, LowEntropy, UADataValues, UALowEntropyJSON } from "../types"; | ||
declare const notAllowedErrorName = "NotAllowedError"; | ||
@@ -6,0 +3,0 @@ declare const errors: { |
@@ -45,2 +45,3 @@ "use strict"; | ||
if ((0, types_1.isUADataValues)(data)) { | ||
console.log(data); | ||
dispatch({ type: HIGH_ENTROPY, payload: data }); | ||
@@ -47,0 +48,0 @@ } |
export { useUserAgentClientHints } from "./hooks/useUserAgentClientHints"; | ||
export { UADataValues, UALowEntropyJSON } from "./types"; | ||
export { UADataValues, UALowEntropyJSON, Hint } from "./types"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -20,4 +20,7 @@ export interface NavigatorUABrandVersion { | ||
} | ||
export declare function isUADataValues(params: unknown): params is UADataValues; | ||
export declare function isUALowEntropyJSON(params: unknown): params is UALowEntropyJSON; | ||
export declare type Hint = "architecture" | "model" | "bitness" | "platformVersion" | "fullVersionList" | "uaFullVersion"; | ||
export declare type HighEntropy = "high"; | ||
export declare type LowEntropy = "low"; | ||
export declare function isUADataValues(params: any): params is UADataValues; | ||
export declare function isUALowEntropyJSON(params: any): params is UALowEntropyJSON; | ||
//# sourceMappingURL=types.d.ts.map |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isUALowEntropyJSON = exports.isUADataValues = void 0; | ||
function hasKey(k, o) { | ||
return k in o; | ||
// function hasKey<K extends string, T extends object>( | ||
// k: K, | ||
// o: T | ||
// ): o is T & Record<K, unknown> { | ||
// return k in o | ||
// } | ||
function isDefined(params) { | ||
return params !== undefined; | ||
} | ||
function isUADataValues(params) { | ||
return (typeof params === "object" && | ||
params !== null && | ||
hasKey("architecture", params) && | ||
typeof params.architecture === "string" && | ||
hasKey("mobile", params) && | ||
typeof params.mobile === "boolean" && | ||
hasKey("platform", params) && | ||
typeof params.platform === "string" && | ||
hasKey("bitness", params) && | ||
typeof params.bitness === "string" && | ||
hasKey("brands", params) && | ||
Array.isArray(params.brands) && | ||
params.brands.every((brand) => brand.brand && brand.version) && | ||
hasKey("model", params) && | ||
typeof params.model === "string" && | ||
hasKey("platformVersion", params) && | ||
typeof params.platformVersion === "string"); | ||
return (params !== null && | ||
typeof params === "object" && | ||
(!isDefined(params.brands) || Array.isArray(params.brands)) && | ||
(!isDefined(params.mobile) || typeof params.mobile === "boolean") && | ||
(!isDefined(params.platform) || typeof params.platform === "string") && | ||
(!isDefined(params.architecture) || | ||
typeof params.architecture === "string") && | ||
(!isDefined(params.bitness) || typeof params.bitness === "string") && | ||
(!isDefined(params.uaFullVersion) || | ||
typeof params.uaFullVersion === "string") && | ||
(!isDefined(params.model) || typeof params.model === "string") && | ||
(!isDefined(params.platformVersion) || | ||
typeof params.platformVersion === "string") && | ||
(!isDefined(params.fullVersionList) || | ||
Array.isArray(params.fullVersionList))); | ||
} | ||
exports.isUADataValues = isUADataValues; | ||
function isUALowEntropyJSON(params) { | ||
return (typeof params === "object" && | ||
params !== null && | ||
hasKey("brands", params) && | ||
Array.isArray(params.brands) && | ||
params.brands.every((brand) => brand.brand && brand.version) && | ||
hasKey("mobile", params) && | ||
typeof params.mobile === "boolean" && | ||
hasKey("platform", params) && | ||
typeof params.platform === "string"); | ||
return (params !== null && | ||
typeof params === "object" && | ||
(!isDefined(params.brands) || Array.isArray(params.brands)) && | ||
(!isDefined(params.mobile) || typeof params.mobile === "boolean") && | ||
(!isDefined(params.platform) || typeof params.platform === "string")); | ||
} | ||
exports.isUALowEntropyJSON = isUALowEntropyJSON; |
{ | ||
"name": "react-user-agent-client-hints", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29782
514