@adviser/cement - v0.0.0
    Preparing search index...

    Function stripper

    • Recursively removes properties from objects based on key patterns.

      Strips properties whose keys or paths match the provided string/regex patterns. Supports both shallow key matching and deep path matching (e.g., "user.password"). Handles arrays and nested objects, preventing circular reference issues.

      Type Parameters

      • T

        Input type (object or array)

      • S

        Element type for arrays

      Parameters

      • strip: StripCommand | StripCommand[]

        String, RegExp, or array thereof specifying keys/paths to remove

      • obj: T

        Object or array to strip properties from

      Returns T extends ArrayLike<unknown>
          ? Record<string, unknown>[]
          : Record<string, unknown>

      New object/array with matching properties removed

      const data = {
      name: 'Alice',
      password: 'secret',
      nested: { apiKey: '123', value: 42 }
      };

      // Remove by key name
      const safe1 = stripper('password', data);
      // { name: 'Alice', nested: { apiKey: '123', value: 42 } }

      // Remove by path
      const safe2 = stripper('nested.apiKey', data);
      // { name: 'Alice', password: 'secret', nested: { value: 42 } }

      // Remove multiple with regex
      const safe3 = stripper([/password/, /apiKey/], data);
      // { name: 'Alice', nested: { value: 42 } }