Interface PropsMethods

Interface that defines all available props methods.

Example

props.getProp(user, 'profile.age');
props.setProp(user, 'profile.email', 'flavio@ever.com');
props.hasProp(user, 'profile.bio');
props.removeProp(user, 'profile.email');
interface PropsMethods {
    getConfig(): PropsConfig<any>;
    getProp<T, P>(obj, path, defaultValue?): any;
    hasProp<T, P>(obj, path): boolean;
    removeProp<T, P>(obj, path): T;
    setProp<T, P>(obj, path, value): T;
    use<T>(config): void;
}

Methods

  • Gets the value of a property using a dot-notation path. Applies any configured transformers and returns the fallback if the property does not exist.

    Type Parameters

    • T extends NestedObject

      The object type.

    • P extends string

      The property path type.

    Parameters

    • obj: T

      The source object.

    • path: P

      The property path (e.g., "user.name").

    • Optional defaultValue: any

      Optional default value if the property does not exist.

    Returns any

    The property value, the default value, or the global fallback.

    Throws

    If input validation fails.

    Example

    const user = { name: 'Flavio Ever', profile: { age: 30 } };
    props.getProp(user, 'profile.age'); // 30
    props.getProp(user, 'profile.email', 'no-email'); // 'no-email'
  • Checks if a property exists using a dot-notation path. Applies any configured transformers.

    Type Parameters

    • T extends NestedObject

      The object type.

    • P extends string

      The property path type.

    Parameters

    • obj: T

      The object to check.

    • path: P

      The property path (e.g., "user.name").

    Returns boolean

    True if the property exists, false otherwise.

    Throws

    If input validation fails.

    Example

    const user = { name: 'Flavio Ever', profile: { age: 30 } };
    props.hasProp(user, 'profile.bio'); // false
  • Removes a property using a dot-notation path. Applies any configured transformers.

    Type Parameters

    • T extends NestedObject

      The object type.

    • P extends string

      The property path type.

    Parameters

    • obj: T

      The source object.

    • path: P

      The property path (e.g., "user.name").

    Returns T

    The modified object.

    Throws

    If input validation fails.

    Example

    const user = { name: 'Flavio Ever', profile: { age: 30, email: 'flavio@ever.com' } };
    props.removeProp(user, 'profile.email');
  • Sets the value of a property using a dot-notation path. Applies any configured transformers.

    Type Parameters

    • T extends NestedObject

      The object type.

    • P extends string

      The property path type.

    Parameters

    • obj: T

      The target object.

    • path: P

      The property path (e.g., "user.name").

    • value: any

      The value to set.

    Returns T

    The modified object.

    Throws

    If input validation fails.

    Example

    const user = { name: 'Flavio Ever', profile: { age: 30 } };
    props.setProp(user, 'profile.email', 'flavio@ever.com');
  • Configures the global props behavior.

    Type Parameters

    • T = any

      The object type for property path autocomplete.

    Parameters

    Returns void

    Example

    props.use<User>({
    fallback: 'N/A',
    transformers: { getProp: { name: value => value.trim() } }
    });