json-fetchfy
Version:
A lightweight Node.js module to fetch, validate, and manipulate JSON data from various sources seamlessly.
69 lines (60 loc) • 1.6 kB
TypeScript
// json-fetchfy.d.ts
declare module "json-fetchfy.d.ts" {
// Define constants
export const CONTENT_TYPES: {
NUMBERS: "Numbers";
STRINGS: "Strings";
OBJECTS: "Objects";
SINGLE: "Single";
UNKNOWN: "Unknown";
INVALID: "Invalid JSON";
};
export const DEFAULT_OPTIONS: {
cache: boolean;
deep: boolean;
caseSensitive: boolean;
limit: number;
single: boolean;
};
// Define types for options
export interface Options {
cache?: boolean;
deep?: boolean;
caseSensitive?: boolean;
limit?: number;
single?: boolean;
update?: Record<string, unknown>;
save?: boolean;
id?: string | "auto";
alphabetical?: boolean;
unique?: boolean;
uniqueKeys?: string | string[];
validate?: boolean;
}
// Define types for detectJsonContentType
export function detectJsonContentType(
jsonInput: string | object
): keyof typeof CONTENT_TYPES;
// Define options function
export function options(options?: object | "get"): object | null;
// Define get function
export function get(
data: any,
query: any,
key?: string | null,
options?: Options
): any;
// Define update function
export function update(
data: any,
query: any,
key?: string | null,
options?: Options
): boolean | object;
// Define add function
export function add(
data: any,
items: any,
options?: Options
): { success: boolean; data: any };
}