@tempots/std
Version:
Std library for TypeScript. Natural complement to the Tempo libraries.
58 lines (57 loc) • 1.65 kB
TypeScript
import { Nothing } from './domain';
import { Result } from './result';
/**
* Represents a JSON primitive value.
* It can be a string, boolean, number, or Nothing (null or undefined).
* @public
*/
export type JSONPrimitive = string | boolean | number | Nothing;
/**
* Represents a JSON object.
* @public
*/
export interface JSONObject {
[k: string]: JSONValue;
}
/**
* Represents an array of JSON values.
* @public
*/
export type JSONArray = JSONValue[];
/**
* Represents a JSON value, which can be a primitive, an object, or an array.
* @public
*/
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
/**
* Checks if the value is a JSON object.
*
* @param value - The value to check.
* @returns `true` if the value is a JSON object; otherwise, `false`.
* @public
*/
export declare const isJSONObject: (value: JSONValue) => value is JSONObject;
/**
* Checks if the value is a JSON array.
*
* @param value - The value to check.
* @returns `true` if the value is a JSON array; otherwise, `false`.
* @public
*/
export declare const isJSONArray: (value: JSONValue) => value is JSONArray;
/**
* Checks if the value is a JSON primitive.
*
* @param value - The value to check.
* @returns `true` if the value is a JSON primitive; otherwise, `false`.
* @public
*/
export declare const isJSONPrimitive: (value: JSONValue) => value is JSONPrimitive;
/**
* Parses a JSON string into a JSON value.
*
* @param value - The JSON string to parse.
* @returns A result containing the parsed JSON value or an error if parsing fails.
* @public
*/
export declare const parseJSON: (value: string) => Result<JSONValue, Error>;