Skip to content

Commit

Permalink
refactor!: remove deprecated functions without tui-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov authored and splincode committed Aug 8, 2022
1 parent 1b492c4 commit 10d58e0
Show file tree
Hide file tree
Showing 149 changed files with 511 additions and 755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Optional,
} from '@angular/core';
import {TuiLineChartHintContext} from '@taiga-ui/addon-charts/interfaces';
import {draw} from '@taiga-ui/addon-charts/utils';
import {tuiDraw} from '@taiga-ui/addon-charts/utils';
import {
tuiDefaultProp,
TuiIdService,
Expand Down Expand Up @@ -216,7 +216,7 @@ export class TuiLineChartComponent {
private getD(value: readonly TuiPoint[], smoothingFactor: number): string {
return value.reduce(
(d, point, index) =>
index ? `${d} ${draw(value, index, smoothingFactor)}` : `M ${point}`,
index ? `${d} ${tuiDraw(value, index, smoothingFactor)}` : `M ${point}`,
``,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Directive, ElementRef, Inject, Input, NgZone} from '@angular/core';
import {ANIMATION_FRAME, PERFORMANCE} from '@ng-web-apis/common';
import {describeSector} from '@taiga-ui/addon-charts/utils';
import {tuiDescribeSector} from '@taiga-ui/addon-charts/utils';
import {
clamp,
easeInOutQuad,
Expand Down Expand Up @@ -56,7 +56,7 @@ export class TuiPieChartDirective {
takeUntil(destroy$),
)
.subscribe(([start, end]) => {
nativeElement.setAttribute(`d`, describeSector(start, end));
nativeElement.setAttribute(`d`, tuiDescribeSector(start, end));
});
}
}
16 changes: 5 additions & 11 deletions projects/addon-charts/utils/control-point.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {TuiPoint} from '@taiga-ui/core';

import {lineAngle} from './line-angle';
import {lineLength} from './line-length';
import {tuiLineAngle} from './line-angle';
import {tuiLineLength} from './line-length';

/**
* @deprecated: use {@link tuiControlPoint} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function controlPoint(
export function tuiControlPoint(
current: TuiPoint,
previous?: TuiPoint,
next?: TuiPoint,
Expand All @@ -16,12 +12,10 @@ export function controlPoint(
): TuiPoint {
const p = previous || current;
const n = next || current;
const angle = lineAngle(p, n) + (reverse ? Math.PI : 0);
const length = lineLength(p, n) * smoothing;
const angle = tuiLineAngle(p, n) + (reverse ? Math.PI : 0);
const length = tuiLineLength(p, n) * smoothing;
const x = current[0] + Math.cos(angle) * length;
const y = current[1] + Math.sin(angle) * length;

return [x, y];
}

export const tuiControlPoint = controlPoint;
6 changes: 1 addition & 5 deletions projects/addon-charts/utils/describe-sector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {toInt, toRadians} from '@taiga-ui/cdk';
const EMPTY = `M 100 0 A 100 100 0 1 1 100 0 L 0 0`;

/**
* @deprecated: use {@link tuiDescribeSector} instead
* Describes a normalized sector by angles. Normalized meaning it supposed to work with
* SVG with viewBox="-1 -1 2 2" so that 0 coordinates in cartesian and polar match the same spot.
* Everything is multiplied by 100 (including viewBox of SVG to host this) so IE properly
Expand All @@ -12,8 +11,7 @@ const EMPTY = `M 100 0 A 100 100 0 1 1 100 0 L 0 0`;
* @param startAngle starting angle in degrees
* @param endAngle ending angle in degrees
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function describeSector(startAngle: number, endAngle: number): string {
export function tuiDescribeSector(startAngle: number, endAngle: number): string {
const startRad = toRadians(startAngle);
const endRad = toRadians(endAngle);
const startX = Math.cos(startRad) * 100;
Expand All @@ -35,5 +33,3 @@ export function describeSector(startAngle: number, endAngle: number): string {

return isNaN(endX) ? EMPTY : result.join(` `);
}

export const tuiDescribeSector = describeSector;
14 changes: 4 additions & 10 deletions projects/addon-charts/utils/draw-curve.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import {TuiPoint} from '@taiga-ui/core';

import {controlPoint} from './control-point';
import {tuiControlPoint} from './control-point';

/**
* @deprecated: use {@link tuiDrawCurve} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function drawCurve(
export function tuiDrawCurve(
array: readonly TuiPoint[],
index: number,
smoothing: number,
): string {
const [cpsX, cpsY] = controlPoint(
const [cpsX, cpsY] = tuiControlPoint(
array[index - 1],
array[index - 2],
array[index],
false,
smoothing,
);
const [cpeX, cpeY] = controlPoint(
const [cpeX, cpeY] = tuiControlPoint(
array[index],
array[index - 1],
array[index + 1],
Expand All @@ -28,5 +24,3 @@ export function drawCurve(

return `C ${cpsX},${cpsY} ${cpeX},${cpeY} ${array[index][0]},${array[index][1]}`;
}

export const tuiDrawCurve = drawCurve;
8 changes: 1 addition & 7 deletions projects/addon-charts/utils/draw-line.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* @deprecated: use {@link drawLine} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function drawLine(point: [number, number]): string {
export function tuiDrawLine(point: [number, number]): string {
return `L ${point}`;
}

export const tuiDrawLine = drawLine;
16 changes: 5 additions & 11 deletions projects/addon-charts/utils/draw.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import {TuiPoint} from '@taiga-ui/core';

import {drawCurve} from './draw-curve';
import {drawLine} from './draw-line';
import {tuiDrawCurve} from './draw-curve';
import {tuiDrawLine} from './draw-line';

const COEFFICIENT = 500;

/**
* @deprecated: use {@link tuiDraw} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function draw(
export function tuiDraw(
array: readonly TuiPoint[],
index: number,
smoothing: number,
): string {
return smoothing
? drawCurve(array, index, smoothing / COEFFICIENT)
: drawLine([array[index][0], array[index][1]]);
? tuiDrawCurve(array, index, smoothing / COEFFICIENT)
: tuiDrawLine([array[index][0], array[index][1]]);
}

export const tuiDraw = draw;
8 changes: 1 addition & 7 deletions projects/addon-charts/utils/line-angle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import {TuiPoint} from '@taiga-ui/core';

/**
* @deprecated: use {@link tuiLineAngle} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function lineAngle(a: TuiPoint, b: TuiPoint): number {
export function tuiLineAngle(a: TuiPoint, b: TuiPoint): number {
const x = b[0] - a[0];
const y = b[1] - a[1];

return Math.atan2(y, x);
}

export const tuiLineAngle = lineAngle;
8 changes: 1 addition & 7 deletions projects/addon-charts/utils/line-length.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import {TuiPoint} from '@taiga-ui/core';

/**
* @deprecated: use {@link tuiLineLength} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function lineLength(a: TuiPoint, b: TuiPoint): number {
export function tuiLineLength(a: TuiPoint, b: TuiPoint): number {
const x = b[0] - a[0];
const y = b[1] - a[1];

return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}

export const tuiLineLength = lineLength;
4 changes: 2 additions & 2 deletions projects/addon-commerce/pipes/currency/currency.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Pipe, PipeTransform} from '@angular/core';
import {TuiCurrencyVariants} from '@taiga-ui/addon-commerce/types';
import {formatCurrency} from '@taiga-ui/addon-commerce/utils';
import {tuiFormatCurrency} from '@taiga-ui/addon-commerce/utils';

@Pipe({
name: `tuiCurrency`,
})
export class TuiCurrencyPipe implements PipeTransform {
transform(currency: TuiCurrencyVariants): string {
return formatCurrency(currency);
return tuiFormatCurrency(currency);
}
}
8 changes: 1 addition & 7 deletions projects/addon-commerce/utils/format-currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import {tuiIsString} from '@taiga-ui/cdk';

import {tuiGetCurrencySymbol} from './get-currency-symbol';

/**
* @deprecated: use {@link tuiFormatCurrency} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function formatCurrency(currency: TuiCurrencyVariants): string {
export function tuiFormatCurrency(currency: TuiCurrencyVariants): string {
const stringifiedCurrency = stringifyCurrency(currency);

return tuiGetCurrencySymbol(stringifiedCurrency) || stringifiedCurrency;
}

export const tuiFormatCurrency = formatCurrency;

function stringifyCurrency(currency: TuiCurrencyVariants): string {
return currency === null || tuiIsString(currency)
? currency || ``
Expand Down
8 changes: 1 addition & 7 deletions projects/addon-commerce/utils/is-expire-valid.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* @deprecated: use {@link tuiIsExpireValid} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function isExpireValid(expire: string): boolean {
export function tuiIsExpireValid(expire: string): boolean {
const today = new Date();
const currentMonth = today.getMonth();
const currentYear = today.getFullYear() - 2000;
Expand All @@ -11,5 +7,3 @@ export function isExpireValid(expire: string): boolean {

return year > currentYear || (year === currentYear && month >= currentMonth);
}

export const tuiIsExpireValid = isExpireValid;
14 changes: 7 additions & 7 deletions projects/addon-commerce/utils/test/format-currency.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import {formatCurrency} from '../format-currency';
import {tuiFormatCurrency} from '../format-currency';

describe(`formatCurrency`, () => {
describe(`tuiFormatCurrency`, () => {
it(`returns founded currency symbol`, () => {
const usdCode = `USD`;

expect(formatCurrency(usdCode)).toBe(`$`);
expect(tuiFormatCurrency(usdCode)).toBe(`$`);
});

it(`returns custom currency`, () => {
const customCurrency = `CSTM`;

expect(formatCurrency(customCurrency)).toBe(customCurrency);
expect(tuiFormatCurrency(customCurrency)).toBe(customCurrency);
});

it(`returns empty string if there is no value`, () => {
const noCurrency = null;

expect(formatCurrency(noCurrency)).toBe(``);
expect(tuiFormatCurrency(noCurrency)).toBe(``);
});

it(`returns correct currency from number currency code`, () => {
const dollarCode = 840;

expect(formatCurrency(dollarCode)).toBe(`$`);
expect(tuiFormatCurrency(dollarCode)).toBe(`$`);
});

it(`returns correct currency from number currency code with 2 decimal`, () => {
const australianDollar = 36;

expect(formatCurrency(australianDollar)).toBe(`A$`);
expect(tuiFormatCurrency(australianDollar)).toBe(`A$`);
});
});
4 changes: 2 additions & 2 deletions projects/addon-commerce/validators/card-expire.validator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {AbstractControl, ValidationErrors} from '@angular/forms';
import {isExpireValid} from '@taiga-ui/addon-commerce/utils';
import {tuiIsExpireValid} from '@taiga-ui/addon-commerce/utils';
import {TuiValidationError} from '@taiga-ui/cdk';

export function tuiCardExpireValidator({
value,
}: AbstractControl): ValidationErrors | null {
return value?.expire?.length === 5 && !isExpireValid(value?.expire)
return value?.expire?.length === 5 && !tuiIsExpireValid(value?.expire)
? {expire: new TuiValidationError(`Expire date`)}
: null;
}
8 changes: 4 additions & 4 deletions projects/addon-doc/src/components/code/code.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {BehaviorSubject} from 'rxjs';
import {map, switchMap} from 'rxjs/operators';

import {RawLoaderContent} from '../../interfaces/page';
import {rawLoad} from '../../utils/raw-load';
import {tryParseMarkdownCodeBlock} from './parse-code-block';
import {tuiRawLoad} from '../../utils/raw-load';
import {tuiTryParseMarkdownCodeBlock} from './parse-code-block';

@Component({
selector: `tui-doc-code`,
Expand All @@ -18,8 +18,8 @@ export class TuiDocCodeComponent {
filename = ``;

readonly processor$ = this.rawLoader$$.pipe(
switchMap(rawLoad),
map(tryParseMarkdownCodeBlock),
switchMap(tuiRawLoad),
map(tuiTryParseMarkdownCodeBlock),
);

@Input()
Expand Down
8 changes: 1 addition & 7 deletions projects/addon-doc/src/components/code/parse-code-block.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import MarkdownIt from 'markdown-it';
import Token from 'markdown-it/lib/token';

/**
* @deprecated: use {@link tuiTryParseMarkdownCodeBlock} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function tryParseMarkdownCodeBlock(text: string = ``): string[] {
export function tuiTryParseMarkdownCodeBlock(text: string = ``): string[] {
const tokens: Token[] = new MarkdownIt().parse(text, {});
const result = tokens
.filter(({tag, type}) => tag === `code` && type === `fence`)
.map(({content}) => content);

return result.length ? result : [text];
}

export const tuiTryParseMarkdownCodeBlock = tryParseMarkdownCodeBlock;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {ActivatedRoute, Params, UrlSerializer} from '@angular/router';
import {BehaviorSubject, Subject} from 'rxjs';

import {coerceValue} from '../../utils/coerce-value';
import {tuiCoerceValue} from '../../utils/coerce-value';

const SERIALIZED_SUFFIX = `$`;

Expand Down Expand Up @@ -112,7 +112,7 @@ export class TuiDocDocumentationPropertyConnectorDirective<T>
const value =
!!propertyValueWithSuffix && this.documentationPropertyValues
? this.documentationPropertyValues[propertyValueWithSuffix as number]
: coerceValue(propertyValue);
: tuiCoerceValue(propertyValue);

this.onValueChange(value as T);
}
Expand Down
Loading

0 comments on commit 10d58e0

Please sign in to comment.