Skip to content

Latest commit

 

History

History
315 lines (190 loc) · 15 KB

CHANGELOG.md

File metadata and controls

315 lines (190 loc) · 15 KB

@httpx/assert

0.12.4

Patch Changes

0.12.3

Patch Changes

0.12.2

Patch Changes

0.12.1

Patch Changes

0.12.0

Minor Changes

  • #1231 fd2ecd3 Thanks @belgattitude! - Improve PlainObject convenience typings when passing a generic.

    import { isPlainObject, assertPlainObject } from "@httpx/assert";
    
    type TValue = {
      key: string;
      deep: {
        connected: boolean;
      };
    };
    const value = {
      key: "hello",
      deep: {
        connected: true,
      },
    } as unknown;
    
    // Without generic
    
    assertPlainObject(value);
    // value is Record<string, unknown>
    // -> no typing
    
    value.key; // unknown, no runtime error
    value.anything; // unknown, no runtime error
    // value.deep.connected // not possible without explicit typing
    
    // With generic
    
    assertPlainObject<TValue>(value);
    
    value.key; // unknown, no runtime error
    value.anything; // unknown, no runtime error
    value.deep?.connected; // connected is 'unknown', typescript suggest the type

0.11.0

Minor Changes

0.10.3

Patch Changes

  • #1214 226a4b1 Thanks @belgattitude! - isPlainObject allows Object.create(null) and disallow stringTagName and iterators symbols

0.10.2

Patch Changes

0.10.1

Patch Changes

0.10.0

Minor Changes

  • #1171 7fdbf08 Thanks @belgattitude! - Add generic convenience typing in isPlainObject

    You can now pass a generic type in isPlainObject and assertPlainObject.

    It allows to get typescript autocompletion after running isPlainObject(v). But notice all keys becomes optional and values are set to unknown in this case to reflect that no runtime check was done.

    isPlainObject

    Name Type Comment
    isPlainObject<T?> PlainObject<T extends Record<string, unknown> = Record<string, unknown>
    assertPlainObject<T?> PlainObject<T extends Record<string, unknown> = Record<string, unknown>
    import { isPlainObject, assertPlainObject } from "@httpx/assert";
    
    // Simple case: without generic value
    isPlainObject({ cwol: true }); // 👈 true
    isPlainObject(new Promise()); // 👈 false
    assertPlainObject({});
    
    // With generic value (unchecked at runtime!)
    type CustomType = {
      name: string;
      deep: {
        yes: boolean | null;
      };
    };
    const value = {
      name: "hello",
      deep: {
        yes: true,
      },
    } as unknown;
    
    if (isPlainObject<CustomType>(value)) {
      // Notice it's a deep partial to allow autocompletion
      const test = value?.deep?.yes; // 👈  yes will be unknown (no runtime check)
    }

0.9.1

Patch Changes

0.9.0

Minor Changes

Patch Changes

0.8.1

Patch Changes

0.8.0

Minor Changes

0.7.0

Minor Changes

Patch Changes

0.6.7

Patch Changes

0.6.6

Patch Changes

0.6.5

Patch Changes

0.6.4

Patch Changes

0.6.3

Patch Changes

0.6.2

Patch Changes

0.6.1

Patch Changes

0.6.0

Minor Changes

0.5.2

Patch Changes

0.5.1

Patch Changes

  • #832 321957a Thanks @belgattitude! - esbuild updated to 0.19.11 to fix a potential typeScript-specific class transform edge case

0.5.0

Minor Changes

0.4.0

Minor Changes

0.3.0

Minor Changes

  • #826 a2f8352 Thanks @belgattitude! - Improve assertion error messages (now typed as TypeError)

    Assertions errors includes information about received value. They're now typed as native TypeError.

    expect(() => assertUuid("123")).toThrow(
      new TypeError("Value is expected to be an uuid, got: string(3)")
    );
    expect(() => assertUuid(false, undefined, { version: 1 })).toThrow(
      new TypeError("Value is expected to be an uuid v1, got: boolean(false)")
    );
    expect(() => assertUuidV1(Number.NaN)).toThrow(
      new TypeError("Value is expected to be an uuid v1, got: NaN")
    );
    expect(() => assertUuidV3(new Error())).toThrow(
      new TypeError("Value is expected to be an uuid v3, got: Error")
    );
    expect(() => assertUuidV4(new Date())).toThrow(
      new TypeError("Value is expected to be an uuid v4, got: Date")
    );
    expect(() => assertUuidV5(() => {})).toThrow(
      new TypeError("Value is expected to be an uuid v5, got: function")
    );

0.2.0

Minor Changes

0.1.0

Minor Changes