Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "compact"

Index

Functions

Functions

compact

  • compact<T>(array: T[]): T[]
  • compact<T>(object: T): Partial<T>
  • Filters falsy values of the given array Removes null and undefined values and their keys from an object


    Example usage:

    import { compact } from "@thalesrc/js-utils";
    
    const arr = [undefined, "", false, 0, 1, "1"];
    const compacted = compact(arr); // [1, "1"];
    
    const object = {
     x: null,
     y: undefined,
     z: 20
    };
    
    const compacted = compact(object); // {z: 20}

    Type parameters

    • T

    Parameters

    • array: T[]

    Returns T[]

  • Filters falsy values of the given array Removes null and undefined values and their keys from an object


    Example usage:

    import { compact } from "@thalesrc/js-utils";
    
    const arr = [undefined, "", false, 0, 1, "1"];
    const compacted = compact(arr); // [1, "1"];
    
    const object = {
     x: null,
     y: undefined,
     z: 20
    };
    
    const compacted = compact(object); // {z: 20}

    Type parameters

    • T: Object

    Parameters

    • object: T

    Returns Partial<T>

Generated using TypeDoc