<commit_before>import { Component, Input, Output, EventEmitter, OnInit, OnChanges } from '@angular/core';
import * as zxcvbn from 'zxcvbn';
import './complexity-meter.scss';

@Component({
  selector: 'swui-complexity-meter',
  template: `
    <meter
      max="4"
      [value]="score"
      [class]="cssClass">
      <div
        class="meter-text"
        [hidden]="!showMessage"
        [innerHTML]="message">
      </div>
    </meter>
  `,
  host: {
    class: 'swui-complexity-meter'
  }
})
export class ComplexityMeterComponent implements OnInit, OnChanges {

  @Input() value: string = '';
  @Input() showMessage: boolean = true;
  @Input() showAscent: boolean = true;

  @Output() onChange = new EventEmitter();

  private results: any;

  get score() {
    if(!this.results) return 0;
    return this.results.score;
  }

  get message() {
    if(!this.results || !this.value.length)
      return 'Strong passwords are required';

    let msg;
    if(this.score === 0 || this.score === 1) {
      msg = 'Weak Password';
    } else if(this.score === 2 || this.score === 3) {
      msg = 'Average Password';
    } else if(this.score === 4) {
      msg = 'Strong Password';
    }

    msg = `<strong>${msg}</strong>`;

    if(this.results.feedback.warning) {
      msg = `${msg} | ${this.results.feedback.warning}`;
    }

    return msg;
  }

  get cssClass() {
    let clz = 'meter-bar';

    clz += ` score-${this.score}`;

    if(this.value.length) {
      clz += ' has-value';
    }

    if(this.showAscent) {
      clz += ' ascented';
    }

    return clz;
  }

  ngOnInit() {<commit_msg>(component): Add null check for password value before calling length on it<commit_after>import { Component, Input, Output, EventEmitter, OnInit, OnChanges } from '@angular/core';
import * as zxcvbn from 'zxcvbn';
import './complexity-meter.scss';

@Component({
  selector: 'swui-complexity-meter',
  template: `
    <meter
      max="4"
      [value]="score"
      [class]="cssClass">
      <div
        class="meter-text"
        [hidden]="!showMessage"
        [innerHTML]="message">
      </div>
    </meter>
  `,
  host: {
    class: 'swui-complexity-meter'
  }
})
export class ComplexityMeterComponent implements OnInit, OnChanges {

  @Input() value: string = '';
  @Input() showMessage: boolean = true;
  @Input() showAscent: boolean = true;

  @Output() onChange = new EventEmitter();

  private results: any;

  get score() {
    if(!this.results) return 0;
    return this.results.score;
  }

  get message() {
    if(!this.results || !this.value || !this.value.length)
      return 'Strong passwords are required';

    let msg;
    if(this.score === 0 || this.score === 1) {
      msg = 'Weak Password';
    } else if(this.score === 2 || this.score === 3) {
      msg = 'Average Password';
    } else if(this.score === 4) {
      msg = 'Strong Password';
    }

    msg = `<strong>${msg}</strong>`;

    if(this.results.feedback.warning) {
      msg = `${msg} | ${this.results.feedback.warning}`;
    }

    return msg;
  }

  get cssClass() {
    let clz = 'meter-bar';

    clz += ` score-${this.score}`;

    if(this.value && this.value.length) {
      clz += ' has-value';
    }

    if(this.showAscent) {
      clz += ' ascented';
    }

    return clz;
  }

  ngOnInit() {
{'fraction_non_alphanumeric': 0.1696048632218845, 'fraction_numerical': 0.00425531914893617, 'mean_word_length': 2.6324503311258276, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6201143', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1097, 'n_words': 253}