lodash#isObjectLike TypeScript Examples

The following examples show how to use lodash#isObjectLike. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: logger-console.service.ts    From nr-apm-stack with Apache License 2.0 6 votes vote down vote up
debug(_message?: any, ..._optionalParams: any[]): void {
    if (process.env.LOG_LEVEL === 'debug') {
      let __message = _message;
      const ___optionalParams: any[] = [];
      if (isObjectLike(_message)) {
        __message=JSON.stringify(_message);
      }
      if (_optionalParams && _optionalParams.length > 0) {
        for (const optionalParam of _optionalParams) {
          if (isObjectLike(optionalParam)) {
            ___optionalParams.push(JSON.stringify(optionalParam));
          } else {
            ___optionalParams.push(optionalParam);
          }
        }
      }
      console.log(__message, ...___optionalParams);
    }
  }
Example #2
Source File: custom-validators.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
export function IsPluginConfig(validationOptions?: ValidationOptions) {
    return (object: any, propertyName: string) => {
        registerDecorator({
            name: 'isPluginConfig',
            target: object.constructor,
            propertyName: propertyName,
            options: validationOptions,
            validator: {
                validate(value: any, _args: ValidationArguments) {
                    if (isObjectLike(value)) {
                        return Object.entries(value).every(([_, v]) => {
                            if (isArray(v)) {
                                // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                                // @ts-ignore
                                return Array.from(v).every(isString);
                            }

                            return isString(v) || isBoolean(v);
                        });
                    }

                    return false;
                },
                defaultMessage(args?: ValidationArguments) {
                    const expectedMsg = 'Expected "{ [key: string]: string | string[] | boolean }"';

                    if (!args) {
                        return expectedMsg;
                    }

                    const strValue = JSON.stringify(args.value);
                    return `${expectedMsg} on "${args.property}" but found "${strValue}" instead`;
                },
            },
        });
    };
}