ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...
    • Omit properties from an object.

      Type Parameters

      • T extends object
      • K extends string | number | symbol

      Parameters

      • data: T

        The object to omit properties from.

      • path: MaybeArray<K>

        The property or properties to omit.

      Returns Omit<T, K>

      The object with the specified properties omitted.

      const data = {
      name: "John",
      age: 30,
      city: "New York",
      };
      omit(data, "age"); // { name: "John", city: "New York" }
      omit(data, ["age", "city"]); // { name: "John" }
      export function omit<T extends object, K extends keyof T>(
      data: T,
      path: MaybeArray<K>,
      ): Omit<T, K> {
      if (!path) {
      return data;
      }
      if (typeof path === "string") {
      path = [path];
      } else if (!Array.isArray(path)) {
      throw new Error("path must be a string or an array of strings");
      }

      return Object.fromEntries(
      Object.entries(data).filter(([key]) => !path.includes(key as K)),
      ) as Omit<T, K>;
      }