ng add @angular-eslint/schematics
npm i prettier prettier-eslint eslint-config-prettier eslint-plugin-prettier -D
Filename: .eslintrc.json
| import { AfterViewInit, Directive, ElementRef, Input, Renderer2 } from '@angular/core'; | |
| @Directive({ | |
| selector: '[appReadMore]' | |
| }) | |
| export class ReadMoreDirective implements AfterViewInit { | |
| @Input() limit : number = 50; //to get the custom text limit | |
| @Input() toggle : boolean = false; //true: 'Read Less' button will be present | |
| txtSpan! : HTMLSpanElement; |
| function truncate(str, length) { | |
| return str.length > length | |
| ? `${str.substr(0, length)}...` | |
| : str; | |
| } |
| type ServiceConfigParams = "port" | "basePath" | "enableStripePayments"; | |
| const serviceConfigChecked: Record<ServiceConfigParams, string | number | boolean> = { | |
| port: 3000, | |
| basePath: "http://localhost", | |
| enableStripePayments: false, | |
| }; |
| type Point2d = [x: number, y: number]; | |
| type Point3d = [x: number, y: number, z: number]; | |
| const point: Point2d = [1, 2]; // the IDE will help you showing which is x and y |
| const degToRad = (degree): number => (degree * Math.PI) / 180; |
| function computeFrequency(input: string): Map<string, number> { | |
| const freqTable = new Map(); | |
| for (let ch of input) { | |
| if (!freqTable.has(ch)) { | |
| freqTable.set(ch, 1); | |
| } else { | |
| freqTable.set(ch, freqTable.get(ch) + 1); | |
| } | |
| } |
| interface Identifiable<T> { | |
| id: T; | |
| } | |
| class Product implements Identifiable<string> { | |
| id: string; | |
| constructor(id: string) { | |
| this.id = id; | |
| } | |
| } |
| function counter() { | |
| let count = 0; | |
| function increment() { | |
| return count += 1; | |
| }; | |
| return increment; | |
| } |
| // Check if an element is focused | |
| const hasFocus = (ele) => ele === document.activeElement; | |
| // Get all siblings of an element | |
| const siblings = (ele) => [].slice.call(ele.parentNode.children).filter((child) => child !== ele); | |
| // Get selected text | |
| const getSelectedText = () => window.getSelection().toString(); | |
| // Go back to the previous page |