How to use the @tsed/core.isEmpty function in @tsed/core

To help you get started, we’ve selected a few @tsed/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / packages / common / src / converters / services / ConverterService.ts View on Github external
deserialize(obj: any, targetType: any, baseType?: any, options: IConverterOptions = {}): any {
    const {ignoreCallback, checkRequiredValue = true} = options;

    try {
      if (ignoreCallback && ignoreCallback(obj, targetType, baseType)) {
        return obj;
      }

      if (targetType !== Boolean && (isEmpty(obj) || isEmpty(targetType) || targetType === Object)) {
        return obj;
      }

      const converter = this.getConverter(targetType);
      const deserializer: IDeserializer = (o: any, targetType: any, baseType: any) => this.deserialize(o, targetType, baseType, options);

      if (converter) {
        // deserialize from a custom JsonConverter
        return converter!.deserialize!(obj, targetType, baseType, deserializer);
      }

      /* istanbul ignore next */
      if (isArrayOrArrayClass(obj)) {
        const converter = this.getConverter(Array);

        return converter!.deserialize!(obj, Array, baseType, deserializer);
github TypedProject / ts-express-decorators / packages / common / src / converters / services / ConverterService.ts View on Github external
serialize(obj: any, options: IConverterOptions = {}): any {
    try {
      if (isEmpty(obj)) {
        return obj;
      }

      const converter = this.getConverter(obj);
      const serializer: ISerializer = (o: any, opt?: any) => this.serialize(o, Object.assign({}, options, opt));

      if (converter && converter.serialize) {
        // deserialize from a custom JsonConverter
        return converter.serialize(obj, serializer);
      }

      if (typeof obj.serialize === "function") {
        // deserialize from serialize method
        return obj.serialize(options, this);
      }
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return false when {} is given", () => {
      expect(isEmpty({})).to.eq(false);
    });
    it("should return false when [] is given", () => {
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return true when null is given", () => {
      expect(isEmpty(null)).to.eq(true);
    });
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return false when false is given", () => {
      expect(isEmpty(false)).to.eq(false);
    });
  });
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return true when empty string is given", () => {
      expect(isEmpty("")).to.eq(true);
    });
    it("should return true when null is given", () => {
github TypedProject / ts-express-decorators / test / units / core / utils / ObjectUtils.spec.ts View on Github external
it("should return true when empty string is given", () => {
      expect(isEmpty(undefined)).to.eq(true);
    });
    it("should return false when {} is given", () => {