redis-json
Version:
A wrapper library to store JSON Objects in redis-hashsets and retrieve it back as JSON objects
56 lines (55 loc) • 1.93 kB
TypeScript
import type { IStringifier, IParser } from '../lib/jsonCache.types';
export declare enum TYPE {
OBJECT = "0",
STRING = "1",
NUMBER = "2",
BOOLEAN = "3",
FUNCTION = "4",
UNDEFINED = "5",
SYMBOL = "6"
}
/**
* Returns true if the given value's
* type need to be skipped during storage.
* For ex: Symbol -> Since symbols are private,
* we DO NOT encourage them to be stored, hence
* we are skipping from storing the same.
*
* In case you've forked this library and want to
* add more type, then this is the place for you 🙂
*/
export declare const isSkippedType: (val: any) => boolean;
/**
* Returns a shorter form of the type of the
* value that can be stored in redis.
* This also handles custom Classes by using
* their constructor names directly.
*
* @param val Value whose type needs to be computed
*/
export declare const getTypeOf: (val: any) => (TYPE | string);
/**
* Returns the stringified version of the given value.
* However note that this method needs to take care,
* such that special values like undefined, null, false, true
* etc are also stringified correctly for storage.
*
* In case of a custom class / object, this method would
* call the provided stringifier (if any available), else
* would use `String(val)`
*
* @param val Value to be evaluated
* @param stringifier Custom stringifiers
*
* @returns Stringified value. If null is returned, then such a value must NOT
* be stored
*/
export declare const getValueOf: (val: any, stringifier?: IStringifier) => string;
/**
* Converts the given value to the specified type.
* Also note that, if a custom className type is
* detected, then the provided custom Parser will
* be called (if any available), else will return
* the value as is.
*/
export declare const getTypedVal: (type: TYPE | string, val: string, parser?: IParser) => any;