{"size": 567, "ext": "js", "max_stars_repo_path": "src/app/bookmarks/form/fields/description.directive.js", "max_stars_repo_name": "tekerson/ng-bookmarks", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/app/bookmarks/form/fields/description.directive.js", "max_issues_repo_name": "tekerson/ng-bookmarks", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app/bookmarks/form/fields/description.directive.js", "max_forks_repo_name": "tekerson/ng-bookmarks", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.35, "max_line_length": 77, "alphanum_fraction": 0.6014109347}
import * as Description from '../../bookmark/description';

export default function fieldDescriptionDirective() {
  return {
    restrict: 'A',
    require: '?ngModel',
    link: (scope, element, attrs, ctrl) => {
      if (ctrl === undefined) { return; }

      ctrl.$parsers.push((v) => v === '' ? null : Description.fromString(v));

      ctrl.$validators.length = value =>
        (value === null) || !(value instanceof Description.TooShortError);

      ctrl.$formatters.push(value =>
        Description.isInstance(value) ? value.toString() : '');
    }
  };
}
