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

    Function getParamsResult

    • Retrieves multiple parameters with type-safe Result handling and defaults.

      Extracts multiple parameters from an object with getParam method (like URI), supporting required params, optional params, and default values. Returns Result.Err if any required parameters are missing.

      Parameters

      • keys: KeysParam

        Array of parameter specifications:

        • string: Required parameter
        • { key: "defaultValue" }: Parameter with default
        • { key: param.OPTIONAL }: Optional parameter
        • Function: Custom error message generator
      • getParam: { getParam: (key: string) => string | undefined }

        Object with getParam method (e.g., URI instance)

      Returns Result<Record<string, string>>

      Result.Ok with all parameters or Result.Err with missing params message

      const uri = URI.from('https://api.com?user=alice&page=1');

      // Required and optional params with defaults
      const result = getParamsResult(
      ['user', { page: '1' }, { limit: param.OPTIONAL }],
      uri
      );

      if (result.isOk()) {
      const { user, page, limit } = result.unwrap();
      // user: 'alice', page: '1', limit: undefined
      }

      // Custom error message
      const result2 = getParamsResult(
      ['apiKey', 'secret', (...missing) => `Auth failed: missing ${missing.join(', ')}`],
      uri
      );