-
Notifications
You must be signed in to change notification settings - Fork 0
API: Preprocessors
API › "@mkacct/cdif/preprocessors"
"@mkacct/cdif/preprocessors" contains included serializer preprocessors to make advanced configuration of the serializer more convenient. Note that the exported functions are not preprocessor functions themselves; rather, they return preprocessor functions. (See the documentation on preprocessors for more information.)
function filterObjectProperties(
names: ReadonlyArray<string>
): CDIFSerializerPreprocessorFunctionReturns a preprocessor that omits all properties in an object (and any nested objects) other than those specified by names. It only omits string-keyed properties, so arrays are unaffected.
Parameters:
-
names:ReadonlyArray<string>– object properties to include
Returns:
-
CDIFSerializerPreprocessorFunction– the preprocessor function
function useIntegers(): CDIFSerializerPreprocessorFunctionReturns a preprocessor that makes integer numbers (those that are evenly divisible by 1) be serialized as cDIF integers. (They won't have trailing decimal points in the resulting cDIF text.) Not recommended if input will contain numbers that may not be integers.
Returns:
-
CDIFSerializerPreprocessorFunction– the preprocessor function
function assignType(
type: string,
condition: (data: {
key: null | string | number;
value: object;
}) => boolean
): CDIFSerializerPreprocessorFunctionReturns a preprocessor that assigns the given type (type) to an object if the given condition (condition) is met. (If the condition is not met, it returns void, continuing to the next preprocessor as usual.)
The actual object value is unchanged. If you need to modify the value, write your own preprocessor instead of using assignType().
Parameters:
-
type:string– the type identifier to assign -
condition:(data: {...}) => boolean– a function that takes{key, value}and returnstrueif and only ifvalueshould be assigned typetype
Returns:
-
CDIFSerializerPreprocessorFunction– the preprocessor function
function usePreprocessMethods(): CDIFSerializerPreprocessorFunctionReturns a preprocessor that delegates to the [CDIF.Symbol.preprocess] method of an object if it exists. (If not, it returns void, continuing to the next preprocessor as usual.) This allows preprocessors to be defined on objects themselves for better cohesion.
This preprocessor takes effect when the value being preprocessed is an object with a symbol-keyed property [CDIF.Symbol.preprocess] (see the documentation on CDIF.Symbol for details on symbols such as this one). The value of this property must be a valid preprocessor function (not a function that returns one; see the documentation on preprocessors for details on CDIFSerializerPreprocessorFunction). If so, the value of [CDIF.Symbol.preprocess] will be called as a preprocessor at this time.
Returns:
-
CDIFSerializerPreprocessorFunction– the preprocessor function