2023-11-30 13:01:29 -05:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assertNever ensures a branch of code can never be reached,
|
|
|
|
* resulting in a Typescript error if it can.
|
|
|
|
*/
|
|
|
|
export function assertNever(a: never): never {
|
|
|
|
return a
|
|
|
|
}
|
2023-12-04 15:20:38 -05:00
|
|
|
|
2023-12-05 10:09:33 -05:00
|
|
|
/**
|
|
|
|
* noop is an empty function for use as a default value.
|
|
|
|
*/
|
|
|
|
export function noop() {}
|
|
|
|
|
2023-12-08 18:55:57 -05:00
|
|
|
/**
|
|
|
|
* isObject checks if a value is an object.
|
|
|
|
*/
|
|
|
|
export function isObject(val: unknown): val is object {
|
|
|
|
return Boolean(val && typeof val === "object" && val.constructor === Object)
|
|
|
|
}
|
|
|
|
|
2023-12-04 15:20:38 -05:00
|
|
|
/**
|
|
|
|
* pluralize is a very simple function that returns either
|
|
|
|
* the singular or plural form of a string based on the given
|
|
|
|
* quantity.
|
|
|
|
*
|
|
|
|
* TODO: Ideally this would use a localized pluralization.
|
|
|
|
*/
|
|
|
|
export function pluralize(signular: string, plural: string, qty: number) {
|
|
|
|
return qty === 1 ? signular : plural
|
|
|
|
}
|
2023-12-05 10:09:33 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isTailscaleIPv6 returns true when the ip matches
|
|
|
|
* Tailnet's IPv6 format.
|
|
|
|
*/
|
|
|
|
export function isTailscaleIPv6(ip: string): boolean {
|
|
|
|
return ip.startsWith("fd7a:115c:a1e0")
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* isPromise returns whether the current value is a promise.
|
|
|
|
*/
|
|
|
|
export function isPromise<T = unknown>(val: unknown): val is Promise<T> {
|
|
|
|
if (!val) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return typeof val === "object" && "then" in val
|
|
|
|
}
|
2024-02-22 14:24:34 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isHTTPS reports whether the current page is loaded over HTTPS.
|
|
|
|
*/
|
|
|
|
export function isHTTPS() {
|
|
|
|
return window.location.protocol === "https:"
|
|
|
|
}
|