From 82e10c4d1d7054e5d123e2fab2b556c0da8a43e7 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 30 Mar 2018 14:53:37 +0200 Subject: [PATCH] chore(formatting): formatted lib --- libs/angular-star-rating/index.ts | 24 +++-- .../src/angular-star-rating.module.ts | 18 ++-- .../components/star-rating.component.spec.ts | 11 ++- .../src/components/star-rating.component.ts | 95 +++++++++---------- .../src/configs/default.config.ts | 54 ++++++----- .../hover-rating-change-event.interface.ts | 2 +- .../star-rating-config.interface.ts | 12 ++- .../services/star-rating-config.service.ts | 38 ++++---- .../src/services/star-rating.ts | 70 ++++++++------ .../src/services/star-rating.utils.ts | 85 +++++++++-------- 10 files changed, 218 insertions(+), 191 deletions(-) diff --git a/libs/angular-star-rating/index.ts b/libs/angular-star-rating/index.ts index 3392bff..7a223ff 100644 --- a/libs/angular-star-rating/index.ts +++ b/libs/angular-star-rating/index.ts @@ -1,13 +1,21 @@ // interfaces -export {ClickEvent} from './src/interfaces/click-event.interface'; -export {HoverRatingChangeEvent} from './src/interfaces/hover-rating-change-event.interface'; -export {RatingChangeEvent} from './src/interfaces/rating-change-event.interface'; -export {StarRatingConfig} from './src/interfaces/star-rating-config.interface'; +export { ClickEvent } from './src/interfaces/click-event.interface'; +export { + HoverRatingChangeEvent +} from './src/interfaces/hover-rating-change-event.interface'; +export { + RatingChangeEvent +} from './src/interfaces/rating-change-event.interface'; +export { + StarRatingConfig +} from './src/interfaces/star-rating-config.interface'; // services -export {StarRatingUtils} from './src/services/star-rating.utils'; -export {StarRating} from './src/services/star-rating'; -export {StarRatingConfigService} from './src/services/star-rating-config.service'; +export { StarRatingUtils } from './src/services/star-rating.utils'; +export { StarRating } from './src/services/star-rating'; +export { + StarRatingConfigService +} from './src/services/star-rating-config.service'; // components -export {StarRatingComponent} from './src/components/star-rating.component'; +export { StarRatingComponent } from './src/components/star-rating.component'; // module export { StarRatingModule } from './src/angular-star-rating.module'; diff --git a/libs/angular-star-rating/src/angular-star-rating.module.ts b/libs/angular-star-rating/src/angular-star-rating.module.ts index 4eb24eb..32b65fb 100644 --- a/libs/angular-star-rating/src/angular-star-rating.module.ts +++ b/libs/angular-star-rating/src/angular-star-rating.module.ts @@ -1,7 +1,7 @@ -import {CommonModule} from '@angular/common'; -import {ModuleWithProviders, NgModule} from '@angular/core'; -import {StarRatingComponent} from './components/star-rating.component'; -import {StarRatingConfigService} from './services/star-rating-config.service'; +import { CommonModule } from '@angular/common'; +import { ModuleWithProviders, NgModule } from '@angular/core'; +import { StarRatingComponent } from './components/star-rating.component'; +import { StarRatingConfigService } from './services/star-rating-config.service'; const DECLARATIONS = [StarRatingComponent]; const EXPORTS = [DECLARATIONS]; @@ -15,16 +15,14 @@ export class StarRatingModule { static forRoot(): ModuleWithProviders { return { ngModule: StarRatingModule, - providers: [ - StarRatingConfigService - ] - } + providers: [StarRatingConfigService] + }; } - static forChild(): ModuleWithProviders { + static forChild(): ModuleWithProviders { return { ngModule: StarRatingModule, providers: [] - } + }; } } diff --git a/libs/angular-star-rating/src/components/star-rating.component.spec.ts b/libs/angular-star-rating/src/components/star-rating.component.spec.ts index 3d72969..60083e7 100644 --- a/libs/angular-star-rating/src/components/star-rating.component.spec.ts +++ b/libs/angular-star-rating/src/components/star-rating.component.spec.ts @@ -9,12 +9,13 @@ describe('StarRatingComponent', () => { let component: StarRatingComponent; let fixture: ComponentFixture; - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ StarRatingComponent ] + beforeEach( + async(() => { + TestBed.configureTestingModule({ + declarations: [StarRatingComponent] + }).compileComponents(); }) - .compileComponents(); - })); + ); beforeEach(() => { fixture = TestBed.createComponent(StarRatingComponent); diff --git a/libs/angular-star-rating/src/components/star-rating.component.ts b/libs/angular-star-rating/src/components/star-rating.component.ts index 3c4e1f9..900a93b 100644 --- a/libs/angular-star-rating/src/components/star-rating.component.ts +++ b/libs/angular-star-rating/src/components/star-rating.component.ts @@ -1,11 +1,11 @@ -import {Component, EventEmitter, forwardRef, Input} from '@angular/core'; -import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; -import {ClickEvent} from '../interfaces/click-event.interface'; -import {HoverRatingChangeEvent} from '../interfaces/hover-rating-change-event.interface'; -import {RatingChangeEvent} from '../interfaces/rating-change-event.interface'; -import {StarRating} from '../services/star-rating'; -import {StarRatingConfigService} from '../services/star-rating-config.service'; -import {StarRatingUtils} from '../services/star-rating.utils'; +import { Component, EventEmitter, forwardRef, Input } from '@angular/core'; +import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; +import { ClickEvent } from '../interfaces/click-event.interface'; +import { HoverRatingChangeEvent } from '../interfaces/hover-rating-change-event.interface'; +import { RatingChangeEvent } from '../interfaces/rating-change-event.interface'; +import { StarRating } from '../services/star-rating'; +import { StarRatingConfigService } from '../services/star-rating-config.service'; +import { StarRatingUtils } from '../services/star-rating.utils'; const STAR_RATING_CONTROL_ACCESSOR = { provide: NG_VALUE_ACCESSOR, @@ -17,36 +17,32 @@ const STAR_RATING_CONTROL_ACCESSOR = { selector: 'star-rating-comp', providers: [STAR_RATING_CONTROL_ACCESSOR], inputs: [ - 'getHalfStarVisible' - , 'getColor' - , 'showHalfStars' - , 'hoverEnabled' - , 'rating' - , 'step' - , 'disabled' - , 'readOnly' - , 'space' - , 'starType' - , 'size' - , 'speed' - , 'numOfStars' - , 'direction' - , 'staticColor' + 'getHalfStarVisible', + 'getColor', + 'showHalfStars', + 'hoverEnabled', + 'rating', + 'step', + 'disabled', + 'readOnly', + 'space', + 'starType', + 'size', + 'speed', + 'numOfStars', + 'direction', + 'staticColor', //, 'labelVisible' - , 'labelPosition' - , 'labelText' - , 'id' - ], - outputs: [ - 'clickEmitter' - , 'ratingChangeEmitter' - , 'hoverRatingChangeEmitter' + 'labelPosition', + 'labelText', + 'id' ], + outputs: ['clickEmitter', 'ratingChangeEmitter', 'hoverRatingChangeEmitter'], styleUrls: [], templateUrl: 'star-rating.component.html' }) -export class StarRatingComponent extends StarRating implements ControlValueAccessor { - +export class StarRatingComponent extends StarRating + implements ControlValueAccessor { //Outputs /////////////////////////////////////////////////////////////////////////////////////////// @@ -58,7 +54,9 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces } } - ratingChangeEmitter: EventEmitter = new EventEmitter(); + ratingChangeEmitter: EventEmitter = new EventEmitter< + RatingChangeEvent + >(); saveOnRatingChange($event: RatingChangeEvent) { if (this.ratingChangeEmitter) { @@ -66,7 +64,9 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces } } - hoverRatingChangeEmitter: EventEmitter = new EventEmitter(); + hoverRatingChangeEmitter: EventEmitter< + HoverRatingChangeEvent + > = new EventEmitter(); saveOnHover($event: HoverRatingChangeEvent) { if (this.hoverRatingChangeEmitter) { @@ -95,7 +95,6 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces //Keyboard events onKeyDown(event: KeyboardEvent) { - if (!this.interactionPossible()) { return; } @@ -118,12 +117,17 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces }; const handleDigits = (eventCode: string): void => { - let dStr = "Digit"; - let digit: number = parseInt(eventCode.substr(dStr.length, eventCode.length - 1)); + let dStr = 'Digit'; + let digit: number = parseInt( + eventCode.substr(dStr.length, eventCode.length - 1) + ); this.rating = digit; }; - if (handlers[event['code']] || StarRatingUtils.isDigitKeyEventCode(event['code'])) { + if ( + handlers[event['code']] || + StarRatingUtils.isDigitKeyEventCode(event['code']) + ) { if (StarRatingUtils.isDigitKeyEventCode(event['code'])) { handleDigits(event['code']); } else { @@ -153,7 +157,6 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces //Hover events onStarHover(rating?: number): void { - if (!this.interactionPossible() || !this.hoverEnabled) { return; } @@ -161,10 +164,8 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces this.hoverRating = rating ? parseInt(rating.toString()) : 0; //fire onHoverRatingChange event - let $event: HoverRatingChangeEvent = {hoverRating: this.hoverRating}; + let $event: HoverRatingChangeEvent = { hoverRating: this.hoverRating }; this.saveOnHover($event); - - } /**Form Control - ControlValueAccessor implementation**/ @@ -194,13 +195,12 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces //if value changed trigger valueAccessor events and outputs if (initValue !== this.rating) { - let $event: RatingChangeEvent = {rating: this.rating}; + let $event: RatingChangeEvent = { rating: this.rating }; this.saveOnRatingChange($event); this.saveOnModelChange(this.rating); } - - }; + } /** * onStarClicked @@ -213,7 +213,6 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces * @param rating */ onStarClicked(rating: number): void { - //fire onClick event if (!this.interactionPossible()) { return; @@ -225,7 +224,5 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces rating: this.rating }; this.saveOnClick(onClickEventObject); - } - } diff --git a/libs/angular-star-rating/src/configs/default.config.ts b/libs/angular-star-rating/src/configs/default.config.ts index f25f3ec..3935a7c 100644 --- a/libs/angular-star-rating/src/configs/default.config.ts +++ b/libs/angular-star-rating/src/configs/default.config.ts @@ -1,10 +1,14 @@ -import {starRatingColor} from '../interfaces/star-rating-config.interface'; -export const getColor = function (rating: number, numOfStars: number, staticColor?: starRatingColor): starRatingColor { +import { starRatingColor } from '../interfaces/star-rating-config.interface'; +export const getColor = function( + rating: number, + numOfStars: number, + staticColor?: starRatingColor +): starRatingColor { rating = rating || 0; // if a fix color is set use this one if (staticColor) { - return staticColor + return staticColor; } // calculate size of smallest fraction @@ -13,38 +17,38 @@ export const getColor = function (rating: number, numOfStars: number, staticColo // apply color by fraction let color: starRatingColor = 'default'; if (rating > 0) { - color = 'negative' + color = 'negative'; } if (rating > fractionSize) { - color = 'ok' + color = 'ok'; } if (rating > fractionSize * 2) { - color = 'positive' + color = 'positive'; } - return color + return color; }; -export const getHalfStarVisible = function (rating: number): boolean { - return Math.abs(rating % 1) > 0 +export const getHalfStarVisible = function(rating: number): boolean { + return Math.abs(rating % 1) > 0; }; export const defaultConfig = { - classEmpty: "default-star-empty-icon", - classHalf: "default-star-half-icon", - classFilled: "default-star-filled-icon", + classEmpty: 'default-star-empty-icon', + classHalf: 'default-star-half-icon', + classFilled: 'default-star-filled-icon', numOfStars: 5, - size: "medium", - speed: "noticeable", - labelPosition: "left", - starType: "svg", - assetsPath: "assets/images/", - svgPath: this.assetsPath + "star-rating.icons.svg", - svgEmptySymbolId: "star-empty", - svgHalfSymbolId: "star-half", - svgFilledSymbolId: "star-filled", - svgPathEmpty: this.svgPath + "#" + this.svgEmptySymbolId, - svgPathHalf: this.svgPath + "#" + this.svgHalfSymbolId, - svgPathFilled: this.svgPath + "#" + this.svgFilledSymbolId, + size: 'medium', + speed: 'noticeable', + labelPosition: 'left', + starType: 'svg', + assetsPath: 'assets/images/', + svgPath: this.assetsPath + 'star-rating.icons.svg', + svgEmptySymbolId: 'star-empty', + svgHalfSymbolId: 'star-half', + svgFilledSymbolId: 'star-filled', + svgPathEmpty: this.svgPath + '#' + this.svgEmptySymbolId, + svgPathHalf: this.svgPath + '#' + this.svgHalfSymbolId, + svgPathFilled: this.svgPath + '#' + this.svgFilledSymbolId, getColor: getColor, - getHalfStarVisible:getHalfStarVisible + getHalfStarVisible: getHalfStarVisible }; diff --git a/libs/angular-star-rating/src/interfaces/hover-rating-change-event.interface.ts b/libs/angular-star-rating/src/interfaces/hover-rating-change-event.interface.ts index e3749d5..0498a7b 100644 --- a/libs/angular-star-rating/src/interfaces/hover-rating-change-event.interface.ts +++ b/libs/angular-star-rating/src/interfaces/hover-rating-change-event.interface.ts @@ -1,3 +1,3 @@ export interface HoverRatingChangeEvent { - hoverRating : number; + hoverRating: number; } diff --git a/libs/angular-star-rating/src/interfaces/star-rating-config.interface.ts b/libs/angular-star-rating/src/interfaces/star-rating-config.interface.ts index de226c1..6e93d40 100644 --- a/libs/angular-star-rating/src/interfaces/star-rating-config.interface.ts +++ b/libs/angular-star-rating/src/interfaces/star-rating-config.interface.ts @@ -3,8 +3,8 @@ export type starRatingColor = 'default' | 'negative' | 'ok' | 'positive'; export type starRatingSpeed = 'immediately' | 'noticeable' | 'slow'; export type starRatingLabelPosition = 'left' | 'right' | 'top' | 'bottom'; export type starRatingStarTypes = 'svg' | 'icon' | 'image'; -export type starRatingStarSpace= 'no' | 'between' | 'around'; -export type starRatingDirection= 'rtl' | 'ltr'; +export type starRatingStarSpace = 'no' | 'between' | 'around'; +export type starRatingDirection = 'rtl' | 'ltr'; export class StarRatingConfig { // binding defaults @@ -14,8 +14,12 @@ export class StarRatingConfig { labelPosition?: starRatingLabelPosition; starType?: starRatingStarTypes; staticColor: starRatingColor; - getColor?: (rating: number, numOfStars: number, staticColor?: starRatingColor)=> starRatingColor; - getHalfStarVisible?:(rating: number) => boolean + getColor?: ( + rating: number, + numOfStars: number, + staticColor?: starRatingColor + ) => starRatingColor; + getHalfStarVisible?: (rating: number) => boolean; // statics classEmpty?: string; classHalf?: string; diff --git a/libs/angular-star-rating/src/services/star-rating-config.service.ts b/libs/angular-star-rating/src/services/star-rating-config.service.ts index 8491ab0..11125ff 100644 --- a/libs/angular-star-rating/src/services/star-rating-config.service.ts +++ b/libs/angular-star-rating/src/services/star-rating-config.service.ts @@ -13,8 +13,7 @@ import { * order to provide default values for all the star ratings used in the application. */ export class StarRatingConfigService implements StarRatingConfig { - - _classEmpty = "default-star-empty-icon"; + _classEmpty = 'default-star-empty-icon'; get classEmpty() { return this._classEmpty; @@ -24,7 +23,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._classEmpty = classEmpty; } - private _classHalf = "default-star-half-icon"; + private _classHalf = 'default-star-half-icon'; get classHalf(): string { return this._classHalf; @@ -34,7 +33,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._classHalf = classHalf; } - private _classFilled = "default-star-filled-icon"; + private _classFilled = 'default-star-filled-icon'; get classFilled(): string { return this._classFilled; @@ -54,7 +53,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._numOfStars = numOfStars; } - private _size: starRatingSizes = "medium"; + private _size: starRatingSizes = 'medium'; get size(): starRatingSizes { return this._size; @@ -74,7 +73,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._staticColor = value; } - private _labelPosition: starRatingLabelPosition = "left"; + private _labelPosition: starRatingLabelPosition = 'left'; get labelPosition(): starRatingLabelPosition { return this._labelPosition; @@ -84,7 +83,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._labelPosition = labelPosition; } - private _speed: starRatingSpeed = "noticeable"; + private _speed: starRatingSpeed = 'noticeable'; get speed(): starRatingSpeed { return this._speed; @@ -94,7 +93,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._speed = speed; } - private _starType: starRatingStarTypes = "svg"; + private _starType: starRatingStarTypes = 'svg'; get starType(): starRatingStarTypes { return this._starType; @@ -104,7 +103,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._starType = starType; } - private _assetsPath = "assets/images/"; + private _assetsPath = 'assets/images/'; get assetsPath(): string { return this._assetsPath; @@ -114,7 +113,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._assetsPath = assetsPath; } - private _svgPath = this.assetsPath + "star-rating.icons.svg"; + private _svgPath = this.assetsPath + 'star-rating.icons.svg'; get svgPath(): string { return this._svgPath; @@ -124,7 +123,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgPath = svgPath; } - private _svgEmptySymbolId = "star-empty"; + private _svgEmptySymbolId = 'star-empty'; get svgEmptySymbolId(): string { return this._svgEmptySymbolId; @@ -134,7 +133,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgEmptySymbolId = svgEmptySymbolId; } - private _svgHalfSymbolId = "star-half"; + private _svgHalfSymbolId = 'star-half'; get svgHalfSymbolId(): string { return this._svgHalfSymbolId; @@ -144,7 +143,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgHalfSymbolId = svgHalfSymbolId; } - private _svgFilledSymbolId = "star-filled"; + private _svgFilledSymbolId = 'star-filled'; get svgFilledSymbolId(): string { return this._svgFilledSymbolId; @@ -154,7 +153,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgFilledSymbolId = svgFilledSymbolId; } - private _svgPathEmpty: string = this.svgPath + "#" + this.svgEmptySymbolId; + private _svgPathEmpty: string = this.svgPath + '#' + this.svgEmptySymbolId; get svgPathEmpty(): string { return this._svgPathEmpty; @@ -164,7 +163,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgPathEmpty = svgPathEmpty; } - private _svgPathHalf: string = this.svgPath + "#" + this.svgHalfSymbolId; + private _svgPathHalf: string = this.svgPath + '#' + this.svgHalfSymbolId; get svgPathHalf(): string { return this._svgPathHalf; @@ -174,7 +173,7 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgPathHalf = svgPathHalf; } - private _svgPathFilled: string = this.svgPath + "#" + this.svgFilledSymbolId; + private _svgPathFilled: string = this.svgPath + '#' + this.svgFilledSymbolId; get svgPathFilled(): string { return this._svgPathFilled; @@ -184,7 +183,11 @@ export class StarRatingConfigService implements StarRatingConfig { this._svgPathFilled = svgPathFilled; } - getColor(rating: number, numOfStars: number, staticColor?: starRatingColor): starRatingColor { + getColor( + rating: number, + numOfStars: number, + staticColor?: starRatingColor + ): starRatingColor { rating = rating || 0; // if a fix color is set use this one @@ -213,5 +216,4 @@ export class StarRatingConfigService implements StarRatingConfig { getHalfStarVisible(rating: number): boolean { return Math.abs(rating % 1) > 0; } - } diff --git a/libs/angular-star-rating/src/services/star-rating.ts b/libs/angular-star-rating/src/services/star-rating.ts index ef482f0..8c76c5d 100644 --- a/libs/angular-star-rating/src/services/star-rating.ts +++ b/libs/angular-star-rating/src/services/star-rating.ts @@ -8,11 +8,10 @@ import { starRatingStarSpace, starRatingStarTypes } from '../interfaces/star-rating-config.interface'; -import {StarRatingConfigService} from './star-rating-config.service'; -import {StarRatingUtils} from './star-rating.utils'; +import { StarRatingConfigService } from './star-rating-config.service'; +import { StarRatingUtils } from './star-rating.utils'; export class StarRating { - protected config: StarRatingConfig; //Inputs @@ -97,7 +96,7 @@ export class StarRating { } set hoverEnabled(value: boolean) { - this._hoverEnabled = (value !== undefined) ? !!value : false; + this._hoverEnabled = value !== undefined ? !!value : false; } ///////////////////////////////////////////// @@ -111,7 +110,7 @@ export class StarRating { } set staticColor(value: starRatingColor) { - this._staticColor = value || this.config.staticColor || undefined; + this._staticColor = value || this.config.staticColor || undefined; //update color. this.setColor(); @@ -133,7 +132,6 @@ export class StarRating { ///////////////////////////////////////////// - /** * numOfStars */ @@ -143,7 +141,7 @@ export class StarRating { } set numOfStars(value: number) { - this._numOfStars = (value > 0) ? value : this.config.numOfStars; + this._numOfStars = value > 0 ? value : this.config.numOfStars; //update stars array this.stars = StarRatingUtils.getStarsArray(this.numOfStars); @@ -163,7 +161,7 @@ export class StarRating { } set hoverRating(value: number) { - this._hoverRating = (value > 0) ? value : 0; + this._hoverRating = value > 0 ? value : 0; } ///////////////////////////////////////////// @@ -201,7 +199,7 @@ export class StarRating { */ protected _starType: starRatingStarTypes; get starType(): starRatingStarTypes { - return this._starType || this.config.starType; + return this._starType || this.config.starType; } set starType(value: starRatingStarTypes) { @@ -258,7 +256,7 @@ export class StarRating { } set step(value: number) { - this._step = (value > 0 ? value : 1); + this._step = value > 0 ? value : 1; } ///////////////////////////////////////////// @@ -279,8 +277,7 @@ export class StarRating { setRating(value: number) { //validate and apply newRating let newRating: number = 0; - if (value >= 0 - && value <= this.numOfStars) { + if (value >= 0 && value <= this.numOfStars) { newRating = value; } @@ -298,7 +295,6 @@ export class StarRating { //update calculated Color this.setColor(); - } set rating(value: number) { @@ -325,7 +321,11 @@ export class StarRating { /** * getColor */ - getColor: (rating: number, numOfStars: number, staticColor?: starRatingColor) => starRatingColor; + getColor: ( + rating: number, + numOfStars: number, + staticColor?: starRatingColor + ) => starRatingColor; ///////////////////////////////////////////// /** @@ -350,7 +350,6 @@ export class StarRating { halfStarVisible: boolean; constructor(config: StarRatingConfigService) { - this.config = config; //set default ctrl props @@ -362,22 +361,27 @@ export class StarRating { this.pathFilled = this.config.svgPathFilled; //set default Component Inputs - if ('getColor' in this.config && typeof this.config.getColor === "function") { + if ( + 'getColor' in this.config && + typeof this.config.getColor === 'function' + ) { this.getColor = this.config.getColor; } - if ('getHalfStarVisible' in this.config && typeof this.config.getHalfStarVisible === "function") { + if ( + 'getHalfStarVisible' in this.config && + typeof this.config.getHalfStarVisible === 'function' + ) { this.getHalfStarVisible = this.config.getHalfStarVisible; } this.numOfStars = this.config.numOfStars; this.rating = 0; this.step = 1; - } svgVisible(): boolean { - return this.starType === "svg"; + return this.starType === 'svg'; } interactionPossible(): boolean { @@ -386,11 +390,18 @@ export class StarRating { setColor(): void { //check if custom function is given - if (typeof this.getColor === "function") { - this.color = this.getColor(this.rating, this.numOfStars, this.staticColor); - } - else { - this.color = StarRatingUtils.getColor(this.rating, this.numOfStars, this.staticColor); + if (typeof this.getColor === 'function') { + this.color = this.getColor( + this.rating, + this.numOfStars, + this.staticColor + ); + } else { + this.color = StarRatingUtils.getColor( + this.rating, + this.numOfStars, + this.staticColor + ); } } @@ -398,14 +409,12 @@ export class StarRating { //update halfStarVisible if (this.showHalfStars) { //check if custom function is given - if (typeof this.getHalfStarVisible === "function") { + if (typeof this.getHalfStarVisible === 'function') { this.halfStarVisible = this.getHalfStarVisible(this.rating); } else { this.halfStarVisible = StarRatingUtils.getHalfStarVisible(this.rating); } - - } - else { + } else { this.halfStarVisible = false; } } @@ -417,7 +426,9 @@ export class StarRating { classNames.push(this.halfStarVisible ? 'half' : ''); classNames.push(this.hoverEnabled ? 'hover' : ''); - let hoverRating = (this.hoverRating ? 'hover-' + this.hoverRating : 'hover-0'); + let hoverRating = this.hoverRating + ? 'hover-' + this.hoverRating + : 'hover-0'; classNames.push(this.hoverEnabled ? hoverRating : ''); classNames.push(this.space ? 'space-' + this.space : ''); @@ -448,5 +459,4 @@ export class StarRating { reset() { this.rating = 0; } - } diff --git a/libs/angular-star-rating/src/services/star-rating.utils.ts b/libs/angular-star-rating/src/services/star-rating.utils.ts index 14030cd..bd1d91f 100644 --- a/libs/angular-star-rating/src/services/star-rating.utils.ts +++ b/libs/angular-star-rating/src/services/star-rating.utils.ts @@ -1,9 +1,9 @@ -import {starRatingColor} from '../interfaces/star-rating-config.interface'; +import { starRatingColor } from '../interfaces/star-rating-config.interface'; export class StarRatingUtils { - //Static methods - /////////////////////////////////////////////////////////////////////////////////////////// + //Static methods + /////////////////////////////////////////////////////////////////////////////////////////// - /* + /* * getStarsArray * * returns an array of increasing numbers starting at 1 @@ -11,15 +11,15 @@ export class StarRatingUtils { * @param numOfStars * @returns {Array} */ - static getStarsArray(numOfStars: number): Array { - let stars: Array = []; - for (let i = 0; i < numOfStars; i++) { - stars.push(i + 1); - } - return stars; + static getStarsArray(numOfStars: number): Array { + let stars: Array = []; + for (let i = 0; i < numOfStars; i++) { + stars.push(i + 1); } + return stars; + } - /* + /* * getHalfStarVisible * * Returns true if there should be a half star visible, and false if not. @@ -27,11 +27,11 @@ export class StarRatingUtils { * @param rating * @returns {boolean} */ - static getHalfStarVisible(rating: number): boolean { - return Math.abs(rating % 1) > 0; - } + static getHalfStarVisible(rating: number): boolean { + return Math.abs(rating % 1) > 0; + } - /* + /* * getColor * * The default function for color calculation @@ -43,40 +43,43 @@ export class StarRatingUtils { * @param staticColor * @returns {starRatingColor} */ - static getColor(rating: number, numOfStars: number, staticColor?: starRatingColor): starRatingColor { - rating = rating || 0; - - //if a fix color is set use this one - if (staticColor) { - return staticColor; - } + static getColor( + rating: number, + numOfStars: number, + staticColor?: starRatingColor + ): starRatingColor { + rating = rating || 0; - //calculate size of smallest fraction - let fractionSize = numOfStars / 3; + //if a fix color is set use this one + if (staticColor) { + return staticColor; + } - //apply color by fraction - let color: starRatingColor = 'default'; - if (rating > 0) { - color = 'negative'; - } - if (rating > fractionSize) { - color = 'ok'; - } - if (rating > fractionSize * 2) { - color = 'positive'; - } + //calculate size of smallest fraction + let fractionSize = numOfStars / 3; - return color; + //apply color by fraction + let color: starRatingColor = 'default'; + if (rating > 0) { + color = 'negative'; + } + if (rating > fractionSize) { + color = 'ok'; } + if (rating > fractionSize * 2) { + color = 'positive'; + } + + return color; + } - /* + /* * isDigitKeyEventCode * detects digit key event sodes * @param eventCode * @returns {boolean} */ - static isDigitKeyEventCode(eventCode: string): boolean { - return eventCode.indexOf('Digit') === 0; - }; - + static isDigitKeyEventCode(eventCode: string): boolean { + return eventCode.indexOf('Digit') === 0; + } }