UNPKG

@snap/camera-kit

Version:
68 lines 3.09 kB
type UnknownRecord<T = unknown> = Record<string | number | symbol, T>; export type Guard<T> = (value: unknown) => value is T; export declare function isString(value: unknown): value is string; /** * Ensures given value is a safe string. * * Safe strings allow to prevent CRLF attacks. We use encoding approach inspired by: * https://community.veracode.com/s/question/0D53n00007hJJV5CAO/is-cwe-id-117-intended-for-consolelog */ export declare function isSafeString(value: unknown): value is string; export declare function isNumber(value: unknown): value is number; export declare function isValidNumber(value: unknown): value is number; export declare function isValidNumberOrUndefined(value: unknown): value is number | undefined; export declare function isArrayOfType<T>(elementTypeGuard: Guard<T>, value: unknown): value is T[]; export declare function isSafeStringArray(value: unknown): value is string[]; export declare function isStringOrUndefined(value: unknown): value is string | undefined; /** * Guards given value is instance of ArrayBuffer. */ export declare function isArrayBuffer(value: unknown): value is ArrayBuffer; /** * Guards given value is a typed array. */ export declare function isTypedArray<T>(value: unknown): value is T; /** * Guards given object is not undefined. */ export declare function isUndefined<T>(value: unknown): value is T; /** * Narrow an unknown type to a Record (i.e. a non-null JS object). This holds true for class instances, not just * plain objects. */ export declare function isRecord(value: unknown): value is UnknownRecord; /** * Check if the value is an arbitrary function */ export declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown; /** * Type guard function to check if a value is an instance of Date. * @param value - The value to check. * @returns True if the value is a Date, false otherwise. */ export declare function isDate(value: unknown): value is Date; export declare function isDateOrUndefined(value: unknown): value is Date | undefined; /** * Type guard function to check if a value is an instance of Date and represents a valid date. * @param value - The value to check. * @returns True if the value is a valid Date, false otherwise. */ export declare function isValidDate(value: unknown): value is Date; /** * Apply a given type predicate asserting values are of type T to each value in a Record. * * @param predicate Any unary type predicate * @returns A type predicate which takes an UnknownRecord and tests that all its values are of type T */ export declare function predicateRecordValues<T>(predicate: (value: unknown) => value is T): (value: UnknownRecord) => value is UnknownRecord<T>; /** * Checks whether given value is undefined or a safe URL string. * * The function checks whether given string is a valid URL with https: protocol. * * @param urlString URL string to check. * @returns True if URL is valid. */ export declare function isEmptyOrSafeUrl(urlString: string | undefined): boolean; export {}; //# sourceMappingURL=typeguards.d.ts.map