UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

1 lines 3.12 kB
{"version":3,"sources":["../../src/utils/IfType.ts"],"sourcesContent":["import { isArray, isBoolean, isNumber, isObject, isString } from '../types/Is';\nimport { Optional } from '../types/Types';\nimport { Construct, ofConstruct } from '../types/Constructor';\n\nexport function ifType<Out, T>(o: unknown, predicate: (o: unknown) => o is T, f: Construct<Out, T>, alt: Construct<Out>): Out;\nexport function ifType<Out, T>(o: unknown, predicate: (o: unknown) => o is T, f: Construct<Out, T>, alt?: Construct<Out>): Optional<Out>;\nexport function ifType<Out, T>(o: unknown, predicate: (o: unknown) => o is T, f: Construct<Out, T>, alt?: Construct<Out>): Optional<Out> {\n return predicate(o) ? ofConstruct(f, o) : ofConstruct(alt);\n}\n\nexport function ifString<Out>(o: unknown, f: Construct<Out, string>, alt: Construct<Out>): Out;\nexport function ifString<Out>(o: unknown, f: Construct<Out, string>, alt?: Construct<Out>): Optional<Out>;\nexport function ifString<Out>(o: unknown, f: Construct<Out, string>, alt?: Construct<Out>): Optional<Out> {\n return ifType(o, isString, f, alt);\n}\n\nexport function ifNumber<Out>(o: unknown, f: Construct<Out, number>, alt: Construct<Out>): Out;\nexport function ifNumber<Out>(o: unknown, f: Construct<Out, number>, alt?: Construct<Out>): Optional<Out>;\nexport function ifNumber<Out>(o: unknown, f: Construct<Out, number>, alt?: Construct<Out>): Optional<Out> {\n return ifType(o, isNumber, f, alt);\n}\n\nexport function ifBoolean<Out>(o: unknown, f: Construct<Out, boolean>, alt: Construct<Out>): Out;\nexport function ifBoolean<Out>(o: unknown, f: Construct<Out, boolean>, alt?: Construct<Out>): Optional<Out>;\nexport function ifBoolean<Out>(o: unknown, f: Construct<Out, boolean>, alt?: Construct<Out>): Optional<Out> {\n return ifType(o, isBoolean, f, alt);\n}\n\nexport function ifArray<Out, T = unknown>(o: unknown, f: Construct<Out, T[]>, alt: Construct<Out>): Out;\nexport function ifArray<Out, T = unknown>(o: unknown, f: Construct<Out, T[]>, alt?: Construct<Out>): Optional<Out>;\nexport function ifArray<Out, T = unknown>(o: unknown, f: Construct<Out, T[]>, alt?: Construct<Out>): Optional<Out> {\n return ifType(o, isArray, f, alt);\n}\n\nexport function ifObject<Out>(o: unknown, f: Construct<Out, Record<string, unknown>>, alt: Construct<Out>): Out;\nexport function ifObject<Out>(o: unknown, f: Construct<Out, Record<string, unknown>>, alt?: Construct<Out>): Optional<Out>;\nexport function ifObject<Out>(o: unknown, f: Construct<Out, Record<string, unknown>>, alt?: Construct<Out>): Optional<Out> {\n return ifType(o, isObject, f, alt);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAMO,SAAS,OAAe,GAAY,WAAmC,GAAsB,KAAqC;AACvI,SAAO,UAAU,CAAC,IAAI,YAAY,GAAG,CAAC,IAAI,YAAY,GAAG;AAC3D;AAIO,SAAS,SAAc,GAAY,GAA2B,KAAqC;AACxG,SAAO,OAAO,GAAG,UAAU,GAAG,GAAG;AACnC;AAIO,SAAS,SAAc,GAAY,GAA2B,KAAqC;AACxG,SAAO,OAAO,GAAG,UAAU,GAAG,GAAG;AACnC;AAIO,SAAS,UAAe,GAAY,GAA4B,KAAqC;AAC1G,SAAO,OAAO,GAAG,WAAW,GAAG,GAAG;AACpC;AAIO,SAAS,QAA0B,GAAY,GAAwB,KAAqC;AACjH,SAAO,OAAO,GAAG,SAAS,GAAG,GAAG;AAClC;AAIO,SAAS,SAAc,GAAY,GAA4C,KAAqC;AACzH,SAAO,OAAO,GAAG,UAAU,GAAG,GAAG;AACnC;","names":[]}