thesmo-calc-fields-objectdeprecated

Collection of calculating fields for manipulating with objects

Usage no npm install needed!

<script type="module">
  import thesmoCalcFieldsObject from 'https://cdn.skypack.dev/thesmo-calc-fields-object';
</script>

README

npm GitHub GitHub last commit npm GitHub top language code style: prettier

Summary

This package contains calculating fields for object source values.

Functions

getNode

Generates UnsafeCF for obtaining node from source object by its' path

type Args = {
    nodePath: string;
};

type Signature = ({ nodePath }: Args) => UnsafeCF<unknown>

getObjectGuarantor

Generates guarantor for object unsafe calculating fields

type Args = {
    convertArrayToArrayLikeObject?: boolean;
    convertNullToEmptyObject?: boolean;
    convertUndefinedToEmptyObject?: boolean;
};

type Signature = ({
    convertArrayToArrayLikeObject = false,
    convertNullToEmptyObject = false,
    convertUndefinedToEmptyObject = false
}: Args) => Guarantor<object>

getRequiredFieldNames

Generates UnsafeCF for obtaining names of fields which satisfy custom check based on their names and values

type Args = {
    check: ({ fieldName, fieldValue }: CheckArgs) => boolean;
};

type Signature = ({ check }: Args) => UnsafeCF<string[]>

merge

Generates UnsafeCF for objects merging

type Args<T> = {
    partToBeMergedWith: T;
};

type Signature = <
    Source extends object,
    MergingPart extends object = Partial<Source>
>({
    partToBeMergedWith
}: Args<MergingPart>) => UnsafeCF<Source & MergingPart>

updateInClone

Generates UnsafeCF for updating source object without changing it (modified copy will be returned)

type Args<Source, Result> = {
    nodePath: string;
    calcField: SafeCF<Source, Result>;
};

type Signature = <Source, Result>({
    nodePath,
    calcField
}: Args<Source, Result>): UnsafeCF<object>

updateWithPattern

Generates UnsafeCF for updating source with given pattern (pattern makes possible to change required source fields via calculating fields)

type UpdatingPattern<T extends object> = Partial<
    {
        [K in keyof T]: SafeCF<T[K]>;
    }
>;

type Args<T extends object> = {
    pattern: UpdatingPattern<T>;
};

type Signature = <T extends object>({
    pattern
}: Args<T>): UnsafeCF<T>